linuxkit / virtsock

Go bindings for virtio and Hyper-V sockets
Other
87 stars 29 forks source link

hvsock: Fix issue with 4.16.x and newer kernels #63

Closed themiron closed 3 years ago

themiron commented 4 years ago

Kernel 4.16 introduces SMC IPv6 protocol, defines SMCPROTO_SMC6 as 1. So, socket(43 /* AF_HYPERV */, SOCK_STREAM, 1 /* HV_PROTOCOL_RAW */) does no longer fail, gives false-positive presense of Hyper-V socket support.

Fix this by getting and checking exact socket name size, it should be different for AF_SMC/SMCPROTO_SMC6 and AF_HYPERV/HV_PROTOCOL_RAW.

Also, non-standard Linux extension accept4() required _GNU_SOURCE to be defined. If not, following warnings are expected: hvsock_linux.go: In function ‘accept_hv’: hvsock_linux.go:33:12: warning: implicit declaration of function ‘accept4’

If flags is 0 then accept4() is the same as accept(), so in this case let's use accept() and get rid of warnings.

themiron commented 3 years ago

@justincormack @rn hello, can you take a look?

themiron commented 3 years ago

thank you