34 enum { NETIF_IFNAME_TYPE, NETIF_NETDEV_NAME_TYPE };
36 enum { PRIMARY_IPADDR = 0, DEFAULT_FORWARDING_STATE = 1, NUM_IP_ADDRS = 8 };
71 struct in_addr netmask;
72 struct in_addr broadcast;
83 char ifname[IF_NAMESIZE + 1];
84 char netdev_name[IF_NAMESIZE + 1];
85 struct drv_entry *drv;
86 struct rt4_entry *rt_cached;
87 struct inet4_addr ip4_addrs[NUM_IP_ADDRS];
89 } __cne_cache_aligned;
91 #define _IFF_UP 0x00000001
92 #define _IFF_BROADCAST 0x00000002
93 #define _IFF_DEBUG 0x00000004
94 #define _IFF_LOOPBACK 0x00000008
95 #define _IFF_POINTOPOINT 0x00000010
96 #define _IFF_SMART 0x00000020
97 #define _IFF_RUNNING 0x00000040
98 #define _IFF_NOARP 0x00000080
99 #define _IFF_PROMISC 0x00000100
100 #define _IFF_ALLMULTI 0x00000200
101 #define _IFF_OACTIVE 0x00000400
102 #define _IFF_SIMPLEX 0x00000800
103 #define _IFF_LINK0 0x00001000
104 #define _IFF_LINK1 0x00002000
105 #define _IFF_LINK2 0x00004000
106 #define _IFF_MULTICAST 0x00008000
107 #define _IFF_NOTRAILERS 0x00020000
108 #define _IFF_INET_UP 0x00040000
109 #define _IFF_INET6_UP 0x00080000
110 #define _IFF_RARP 0x00100000
111 #define _IFF_DONT_FORWARD 0x00200000
113 #define _ipv4_broadcast_compare(_i) \
115 if (netif->ip4_addrs[_i].ip.s_addr) { \
116 if (ip->s_addr == netif->ip4_addrs[_i].broadcast.s_addr) \
127 if (NUM_IP_ADDRS == 4) {
128 _ipv4_broadcast_compare(0);
129 _ipv4_broadcast_compare(1);
130 _ipv4_broadcast_compare(2);
131 _ipv4_broadcast_compare(3);
134 for (
int i = 0; i < NUM_IP_ADDRS; i++)
135 _ipv4_broadcast_compare(i);
139 #define _ipv4_compare(_i) \
141 struct in_addr *ip2, *mask; \
142 ip2 = &netif->ip4_addrs[_i].ip; \
143 mask = &netif->ip4_addrs[_i].netmask; \
144 if (inet_addr_mask_cmp(&addr, ip2, mask)) \
149 cnet_ipv4_compare(
struct netif *netif,
struct in_addr *ip)
153 addr.s_addr = ntohl(ip->s_addr);
154 if (NUM_IP_ADDRS == 4) {
161 for (
int i = 0; i < NUM_IP_ADDRS; i++)
170 static inline struct netif *
173 return vec_at_index(this_cnet->netifs, idx);
179 static inline struct netif *
182 struct netif **netif;
184 vec_foreach (netif, this_cnet->netifs) {
185 if (cnet_ipv4_compare(*netif, ipaddr) != -1)
198 if (netif->netif_idx >= 0 && netif->netif_idx < CNE_MAX_ETHPORTS)
199 vec_at_index(this_cnet->netifs, netif->netif_idx) = NULL;
207 static inline struct netif *
210 struct netif *netif = NULL;
212 netif = calloc(1,
sizeof(
struct netif));
216 netif->netif_idx = -1;
219 netif->ip_ident = (uint16_t)(
cne_rdtsc() & 0xFFFF);
230 if (!flags || !netif)
233 *flags = netif->ifflags;
static uint64_t cne_rdtsc(void)
CNDP_API int cnet_netif_register(uint16_t lpid, char *ifname, char *netdev)
Register lport, ifname and netdev to create a netif structure.
CNDP_API int cnet_netif_set_flags(struct netif *netif, uint32_t flags)
Add flags or set the flags to a netif structure.
static int cnet_ipv4_broadcast(struct netif *netif, struct in_addr *ip)
CNDP_API struct netif * cnet_netif_find_by_name(char *ifname)
Find the netif structure for the given interface name.
CNDP_API struct netif * cnet_netif_find_by_lport(int lport)
Find the netif structure by the lport id.
CNDP_API int cnet_netif_set_mtu(struct netif *netif, uint16_t mtu)
Set the MTU for a given netif structure.
CNDP_API int cnet_ipv4_ipaddr_delete(struct netif *netif, struct in_addr *ip)
Delete the given IPv4 address from the given netif structure.
CNDP_API int cnet_netif_attach_ports(struct cnet *cnet)
Attach ports to CNET and the netif structures.
CNDP_API struct netif * cnet_netif_from_name(const char *name, int typ)
Locate the netif for the given interface name.
static void cnet_netif_free(struct netif *netif)
CNDP_API int cnet_ipv4_ipaddr_add(struct netif *netif, struct inet4_addr *ip)
Add a new IPv4 address to the given netif structure.
CNDP_API struct netif * cnet_netif_find_by_netdev(char *netdev_name)
Find the netif structure by the netdev name.
CNDP_API int cnet_is_netdev_valid(char *netdev_name)
Is the netdev name a valid netdev.
CNDP_API struct netif * cnet_netif_find_by_ifindex(int ifindex)
Locate the netif structure by the ifindex value.
static int cnet_netif_get_flags(struct netif *netif, uint32_t *flags)
static struct netif * cnet_netif_match_subnet(struct in_addr *ipaddr)
#define _IFF_DONT_FORWARD
CNDP_API int cnet_is_ifindex_valid(int ifindex)
Is the ifindex valid interface index.
static struct netif * cnet_netif_alloc(uint16_t lpid)
CNDP_API struct inet4_addr * cnet_ipv4_ipaddr_find(struct netif *netif, struct in_addr *ip)
Find the given IPv4 address in a given netif structure.
CNDP_API int cnet_is_ifname_valid(char *ifname)
Is the ifname a valid interface name.
CNDP_API int cnet_netif_foreach(int(*func)(struct netif *netif, void *arg), void *arg)
look over all netif structures calling the specified function
static struct netif * cnet_netif_from_index(uint8_t idx)