@@ -285,16 +285,12 @@ func New(opts *Options) (stack.LinkEndpoint, error) {
285285 return nil , fmt .Errorf ("unix.SetNonblock(%v) failed: %v" , fd , err )
286286 }
287287
288- isSocket , err := isSocketFD (fd )
289- if err != nil {
290- return nil , err
291- }
292- e .fds = append (e .fds , fdInfo {fd : fd , isSocket : isSocket })
288+ e .fds = append (e .fds , fdInfo {fd : fd , isSocket : true })
293289 if opts .ProcessorsPerChannel == 0 {
294290 opts .ProcessorsPerChannel = common .Max (1 , runtime .GOMAXPROCS (0 )/ len (opts .FDs ))
295291 }
296292
297- inboundDispatcher , err := createInboundDispatcher ( e , fd , isSocket , opts )
293+ inboundDispatcher , err := newRecvMMsgDispatcher ( fd , e , opts )
298294 if err != nil {
299295 return nil , fmt .Errorf ("createInboundDispatcher(...) = %v" , err )
300296 }
@@ -304,40 +300,6 @@ func New(opts *Options) (stack.LinkEndpoint, error) {
304300 return e , nil
305301}
306302
307- func createInboundDispatcher (e * endpoint , fd int , isSocket bool , opts * Options ) (linkDispatcher , error ) {
308- // By default use the readv() dispatcher as it works with all kinds of
309- // FDs (tap/tun/unix domain sockets and af_packet).
310- inboundDispatcher , err := newReadVDispatcher (fd , e , opts )
311- if err != nil {
312- return nil , fmt .Errorf ("newReadVDispatcher(%d, %+v) = %v" , fd , e , err )
313- }
314-
315- if isSocket {
316- switch e .packetDispatchMode {
317- case RecvMMsg :
318- // If the provided FD is a socket then we optimize
319- // packet reads by using recvmmsg() instead of read() to
320- // read packets in a batch.
321- inboundDispatcher , err = newRecvMMsgDispatcher (fd , e , opts )
322- if err != nil {
323- return nil , fmt .Errorf ("newRecvMMsgDispatcher(%d, %+v) = %v" , fd , e , err )
324- }
325- case Readv :
326- default :
327- return nil , fmt .Errorf ("unknown dispatch mode %d" , e .packetDispatchMode )
328- }
329- }
330- return inboundDispatcher , nil
331- }
332-
333- func isSocketFD (fd int ) (bool , error ) {
334- var stat unix.Stat_t
335- if err := unix .Fstat (fd , & stat ); err != nil {
336- return false , fmt .Errorf ("unix.Fstat(%v,...) failed: %v" , fd , err )
337- }
338- return (stat .Mode & unix .S_IFSOCK ) == unix .S_IFSOCK , nil
339- }
340-
341303// Attach launches the goroutine that reads packets from the file descriptor and
342304// dispatches them via the provided dispatcher. If one is already attached,
343305// then nothing happens.
0 commit comments