(name string)
| 509 | ) |
| 510 | |
| 511 | func (tun *NativeTun) initFromFlags(name string) error { |
| 512 | sc, err := tun.tunFile.SyscallConn() |
| 513 | if err != nil { |
| 514 | return err |
| 515 | } |
| 516 | if e := sc.Control(func(fd uintptr) { |
| 517 | var ( |
| 518 | ifr *unix.Ifreq |
| 519 | ) |
| 520 | ifr, err = unix.NewIfreq(name) |
| 521 | if err != nil { |
| 522 | return |
| 523 | } |
| 524 | err = unix.IoctlIfreq(int(fd), unix.TUNGETIFF, ifr) |
| 525 | if err != nil { |
| 526 | return |
| 527 | } |
| 528 | got := ifr.Uint16() |
| 529 | if got&unix.IFF_VNET_HDR != 0 { |
| 530 | // tunTCPOffloads were added in Linux v2.6. We require their support |
| 531 | // if IFF_VNET_HDR is set. |
| 532 | err = unix.IoctlSetInt(int(fd), unix.TUNSETOFFLOAD, tunTCPOffloads) |
| 533 | if err != nil { |
| 534 | return |
| 535 | } |
| 536 | tun.vnetHdr = true |
| 537 | tun.batchSize = conn.IdealBatchSize |
| 538 | // tunUDPOffloads were added in Linux v6.2. We do not return an |
| 539 | // error if they are unsupported at runtime. |
| 540 | tun.udpGSO = unix.IoctlSetInt(int(fd), unix.TUNSETOFFLOAD, tunTCPOffloads|tunUDPOffloads) == nil |
| 541 | } else { |
| 542 | tun.batchSize = 1 |
| 543 | } |
| 544 | }); e != nil { |
| 545 | return e |
| 546 | } |
| 547 | return err |
| 548 | } |
| 549 | |
| 550 | // CreateTUN creates a Device with the provided name and MTU. |
| 551 | func CreateTUN(name string, mtu int) (Device, error) { |
no outgoing calls
no test coverage detected