1 #ifndef MINIX_NET_LWIP_IFDEV_H
2 #define MINIX_NET_LWIP_IFDEV_H
5 #include <net/if_types.h>
6 #include <netinet6/in6_var.h>
7 #include <netinet6/nd6.h>
10 * NetBSD makes setting a hardware address through ifconfig(8) a whole lot
11 * harder than it needs to be, namely by keeping a list of possible hardware
12 * addresses and marking one of them as active. For us, that level of extra
13 * flexibility is completely useless. In order to shield individual interface
14 * modules from having to deal with the rather extended interface for the list
15 * management, we maintain the list in ifdev and simply use a iop_set_hwaddr()
16 * call to the modules when the active address changes. This setting is the
17 * maximum number of hardware addresses in the list maintained by ifdev. It
18 * should be at least 2, or changing hardware addresses will not be possible.
20 #define IFDEV_NUM_HWADDRS 3
26 /* Interface operations table. */
28 err_t (* iop_init
)(struct ifdev
* ifdev
, struct netif
* netif
);
29 err_t (* iop_input
)(struct pbuf
* pbuf
, struct netif
* netif
);
30 err_t (* iop_output
)(struct ifdev
* ifdev
, struct pbuf
* pbuf
,
31 struct netif
* netif
);
32 err_t (* iop_output_v4
)(struct netif
* netif
, struct pbuf
* pbuf
,
33 const ip4_addr_t
* ipaddr
);
34 err_t (* iop_output_v6
)(struct netif
* netif
, struct pbuf
* pbuf
,
35 const ip6_addr_t
* ipaddr
);
36 void (* iop_hdrcmplt
)(struct ifdev
* ifdev
, struct pbuf
* pbuf
);
37 void (* iop_poll
)(struct ifdev
* ifdev
);
38 int (* iop_set_ifflags
)(struct ifdev
* ifdev
, unsigned int ifflags
);
39 void (* iop_get_ifcap
)(struct ifdev
* ifdev
, uint64_t * ifcap
,
41 int (* iop_set_ifcap
)(struct ifdev
* ifdev
, uint64_t ifcap
);
42 void (* iop_get_ifmedia
)(struct ifdev
* ifdev
, int * ifcurrent
,
44 int (* iop_set_ifmedia
)(struct ifdev
* ifdev
, int ifmedia
);
45 void (* iop_set_promisc
)(struct ifdev
* ifdev
, int promisc
);
46 int (* iop_set_hwaddr
)(struct ifdev
* ifdev
, const uint8_t * hwaddr
);
47 int (* iop_set_mtu
)(struct ifdev
* ifdev
, unsigned int mtu
);
48 int (* iop_destroy
)(struct ifdev
* ifdev
);
51 /* Hardware address list entry. The first entry, if any, is the active one. */
53 uint8_t ifhwa_addr
[NETIF_MAX_HWADDR_LEN
];
56 #define IFHWAF_VALID 0x01 /* entry contains an address */
57 #define IFHWAF_FACTORY 0x02 /* factory (device-given) address */
59 /* Interface structure. */
61 TAILQ_ENTRY(ifdev
) ifdev_next
; /* list of active interfaces */
62 char ifdev_name
[IFNAMSIZ
]; /* interface name, null terminated */
63 unsigned int ifdev_ifflags
; /* NetBSD-style interface flags */
64 unsigned int ifdev_dlt
; /* data link type (DLT_) */
65 unsigned int ifdev_promisc
; /* number of promiscuity requestors */
66 struct netif ifdev_netif
; /* lwIP interface structure */
67 struct if_data ifdev_data
; /* NetBSD-style interface data */
68 char ifdev_v4set
; /* interface has an IPv4 address? */
69 uint8_t ifdev_v6prefix
[LWIP_IPV6_NUM_ADDRESSES
]; /* IPv6 prefixes */
70 uint8_t ifdev_v6flags
[LWIP_IPV6_NUM_ADDRESSES
]; /* v6 address flags */
71 uint8_t ifdev_v6state
[LWIP_IPV6_NUM_ADDRESSES
]; /* v6 shadow states */
72 uint8_t ifdev_v6scope
[LWIP_IPV6_NUM_ADDRESSES
]; /* cached v6 scopes */
73 struct ifdev_hwaddr ifdev_hwlist
[IFDEV_NUM_HWADDRS
]; /* HW addr's */
74 uint32_t ifdev_nd6flags
; /* ND6-related flags (ND6_IFF_) */
75 const struct ifdev_ops
*ifdev_ops
; /* interface operations table */
76 TAILQ_HEAD(, bpfdev_link
) ifdev_bpf
; /* list of attached BPF devices */
79 #define ifdev_get_name(ifdev) ((ifdev)->ifdev_name)
80 #define ifdev_get_ifflags(ifdev) ((ifdev)->ifdev_ifflags)
81 #define ifdev_get_dlt(ifdev) ((ifdev)->ifdev_dlt)
82 #define ifdev_is_promisc(ifdev) ((ifdev)->ifdev_promisc != 0)
83 #define ifdev_get_netif(ifdev) (&(ifdev)->ifdev_netif)
84 #define ifdev_get_nd6flags(ifdev) ((ifdev)->ifdev_nd6flags)
85 #define ifdev_get_iftype(ifdev) ((ifdev)->ifdev_data.ifi_type)
86 #define ifdev_get_hwlen(ifdev) ((ifdev)->ifdev_data.ifi_addrlen)
87 #define ifdev_get_hdrlen(ifdev) ((ifdev)->ifdev_data.ifi_hdrlen)
88 #define ifdev_get_link(ifdev) ((ifdev)->ifdev_data.ifi_link_state)
89 #define ifdev_get_mtu(ifdev) ((ifdev)->ifdev_data.ifi_mtu)
90 #define ifdev_get_metric(ifdev) ((ifdev)->ifdev_data.ifi_metric)
91 #define ifdev_get_ifdata(ifdev) (&(ifdev)->ifdev_data)
92 #define ifdev_is_loopback(ifdev) ((ifdev)->ifdev_ifflags & IFF_LOOPBACK)
93 #define ifdev_is_up(ifdev) ((ifdev)->ifdev_ifflags & IFF_UP)
94 #define ifdev_is_link_up(ifdev) (netif_is_link_up(&(ifdev)->ifdev_netif))
95 #define ifdev_set_metric(ifdev, metric) \
96 ((void)((ifdev)->ifdev_data.ifi_metric = (metric)))
97 #define ifdev_get_index(ifdev) \
98 ((uint32_t)(netif_get_index(ifdev_get_netif(ifdev))))
100 #define ifdev_output_drop(ifdev) ((ifdev)->ifdev_data.ifi_oerrors++)
102 #define netif_get_ifdev(netif) ((struct ifdev *)(netif)->state)
104 void ifdev_init(void);
105 void ifdev_poll(void);
107 void ifdev_register(const char * name
, int (* create
)(const char *));
109 void ifdev_input(struct ifdev
* ifdev
, struct pbuf
* pbuf
,
110 struct netif
* netif
, int to_bpf
);
111 err_t
ifdev_output(struct ifdev
* ifdev
, struct pbuf
* pbuf
,
112 struct netif
* netif
, int to_bpf
, int hdrcmplt
);
114 void ifdev_attach_bpf(struct ifdev
* ifdev
, struct bpfdev_link
* bpfl
);
115 void ifdev_detach_bpf(struct ifdev
* ifdev
, struct bpfdev_link
* bpfl
);
117 struct ifdev
*ifdev_get_by_index(uint32_t ifindex
);
118 struct ifdev
*ifdev_find_by_name(const char * name
);
119 struct ifdev
*ifdev_enum(struct ifdev
* last
);
121 int ifdev_check_name(const char * name
, unsigned int * vtype_slot
);
123 int ifdev_set_promisc(struct ifdev
* ifdev
);
124 void ifdev_clear_promisc(struct ifdev
* ifdev
);
126 int ifdev_set_ifflags(struct ifdev
* ifdev
, unsigned int ifflags
);
127 void ifdev_update_ifflags(struct ifdev
* ifdev
, unsigned int ifflags
);
129 void ifdev_get_ifcap(struct ifdev
* ifdev
, uint64_t * ifcap
,
131 int ifdev_set_ifcap(struct ifdev
* ifdev
, uint64_t ifena
);
133 int ifdev_get_ifmedia(struct ifdev
* ifdev
, int * ifcurrent
, int * ifactive
);
134 int ifdev_set_ifmedia(struct ifdev
* ifdev
, int ifmedia
);
136 int ifdev_set_mtu(struct ifdev
* ifdev
, unsigned int mtu
);
138 int ifdev_set_nd6flags(struct ifdev
* ifdev
, uint32_t nd6flags
);
140 void ifdev_add(struct ifdev
* ifdev
, const char * name
, unsigned int ifflags
,
141 unsigned int iftype
, size_t hdrlen
, size_t addrlen
, unsigned int dlt
,
142 unsigned int mtu
, uint32_t nd6flags
, const struct ifdev_ops
* iop
);
143 int ifdev_remove(struct ifdev
* ifdev
);
145 struct ifdev
*ifdev_get_loopback(void);
147 void ifdev_update_link(struct ifdev
* ifdev
, int link
);
148 void ifdev_update_hwaddr(struct ifdev
* ifdev
, const uint8_t * hwaddr
,
151 int ifdev_create(const char * name
);
152 int ifdev_destroy(struct ifdev
* ifdev
);
153 const char *ifdev_enum_vtypes(unsigned int num
);
155 #endif /* !MINIX_NET_LWIP_IFDEV_H */