Write into the route socket fails for unclear reason

From: Yuri <yuri_at_FreeBSD.org>
Date: Wed, 18 Oct 2023 21:11:43 UTC
Hi,


I am troubleshooting the problem that the write call into the routing 
socket fails with EINVAL.


The file descriptor is created like this:

fd = socket(PF_ROUTE, SOCK_RAW, 0);


Then the write is performed for this socket, that fails with errno=EINVAL:

write(fd, buf, 168);

buf has these bytes:

0:   a8 00 05 04 00 00 00 00 00 04 00 00 01 00 00 00
16:  00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00
32:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
48:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
64:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
80:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
96:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
112: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
128: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
144: 00 00 00 00 00 00 00 00|10 02 00 00 c0 a8 05 01
160: 00 00 00 00 00 00 00 00

Based on the code, the first 152 bytes represent 'struct rt_msghdr'.

It is followed with 16 bytes of 'struct sockaddr_in' representing the IP 
address 192.168.5.1.


The file descriptor is valid at the moment of the write call. The 
structures above looks fine.


Why does the write call fail then?


Can anybody figure this out without the need to rebuild the kernel?



Thanks,

Yuri