Skip to content

sizeof(struct sockaddr_xia) compromise

Michel Machado edited this page Feb 19, 2015 · 10 revisions

The largest XIP address is max_nodes*row_size=127*28=3556 bytes, and an XIP packet has two XIP addresses; one for source, and another for destination. With an MTU of 1500B, a packet can't even hold its header! Therefore, a compromise on the maximum size of an XIP address must be made.

When a socket system call (e.g. bind(2)) passes an struct sockaddr to Linux's kernel, the kernel copies the content of the user's struct sockaddr into a kernel buffer whose size is sizeof(struct sockaddr_storage). Thus, every struct sockaddr must be smaller or equal to this size. The file net/socket.c contains the socket system calls, whereas include/linux/socket.h defines struct sockaddr_storage, and it has size 128 bytes.

With 128 bytes, one can fit 128/28=4 nodes in an XIP address. Although four nodes should be enough to most cases, it's is rather small in general. Whereas 256 bytes can fit 256/28=9 nodes, an odd number, but a reasonable one. Moreover, a header with two maximum-size addresses of 9 nodes would take 8+2*9*28=512 bytes; it's a nice number 512=2^9! It still is a big header when compared to a 20-byte, without-options IP header, but it's "okay" given all the flexibility that is built in it, and the fact that it fits an MTU of 1500B.

This discussion implies that constant include/linux/socket.h:_K_SS_MAXSIZE must be redefined to 256, and struct sockaddr_xia must limit the number of nodes to 9.