...

Source file src/edge-infra.dev/pkg/lib/kernel/netlink/ip/ip.go

Documentation: edge-infra.dev/pkg/lib/kernel/netlink/ip

     1  package ip
     2  
     3  import (
     4  	"math/big"
     5  	"net"
     6  )
     7  
     8  type IPv4HeaderBitOffset uint32
     9  
    10  const (
    11  	// see IPv4 Header (RFC 791) - https://wiki.sans.blue/Tools/tcpip/ip.html
    12  	SrcAddressBitOffset IPv4HeaderBitOffset = 12
    13  	DstAddressBitOffset IPv4HeaderBitOffset = 16
    14  	OptionsBitOffset    IPv4HeaderBitOffset = 20
    15  )
    16  
    17  var (
    18  	DstPortMask uint32 = 0x0000ffff
    19  	SrcPortMask uint32 = 0xffff0000
    20  )
    21  
    22  var (
    23  	IPIPHeaderSize = 20 // IPIP header 20 bytes length
    24  )
    25  
    26  // converts ipv4 address to unsigned, 32 bit integer
    27  func IPv4ToUInt32(ip net.IP) uint32 {
    28  	ipv4 := ip.To4()
    29  	ipInt := big.NewInt(0)
    30  	ipInt.SetBytes(ipv4)
    31  	return uint32(ipInt.Uint64()) /* #nosec G115 */
    32  }
    33  

View as plain text