1 /* if.h 2 * Interface definitions for beos 3 */ 4 5 #ifndef _NET_IF_H 6 #define _NET_IF_H 7 8 #include <Drivers.h> 9 #include <sys/socketvar.h> 10 #include <net/if_types.h> 11 #include <netinet/in.h> 12 #include <net/route.h> 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 enum { 19 IF_GETADDR = B_DEVICE_OP_CODES_END, 20 IF_INIT, 21 IF_NONBLOCK, 22 IF_ADDMULTI, 23 IF_REMMULTI, 24 IF_SETPROMISC, 25 IF_GETFRAMESIZE 26 }; 27 28 /* Media types are now listed in net/if_types.h */ 29 30 /* Interface flags */ 31 enum { 32 IFF_UP = 0x0001, 33 IFF_DOWN = 0x0002, 34 IFF_PROMISC = 0x0004, 35 IFF_RUNNING = 0x0008, 36 IFF_MULTICAST = 0x0010, 37 IFF_BROADCAST = 0x0020, 38 IFF_POINTOPOINT = 0x0040, 39 IFF_NOARP = 0x0080, 40 IFF_LOOPBACK = 0x0100, 41 IFF_DEBUG = 0x0200, 42 IFF_LINK0 = 0x0400, 43 IFF_LINK1 = 0x0800, 44 IFF_LINK2 = 0x1000, 45 IFF_SIMPLEX = 0x2000 46 }; 47 48 struct ifq { 49 struct mbuf *head; 50 struct mbuf *tail; 51 int maxlen; 52 int len; 53 sem_id lock; 54 sem_id pop; 55 }; 56 57 #define IFQ_FULL(ifq) (ifq->len >= ifq->maxlen) 58 59 #define IFQ_ENQUEUE(ifq, m) { \ 60 acquire_sem((ifq)->lock); \ 61 (m)->m_nextpkt = 0; \ 62 if ((ifq)->tail == 0) \ 63 (ifq)->head = m; \ 64 else \ 65 (ifq)->tail->m_nextpkt = m; \ 66 (ifq)->tail = m; \ 67 (ifq)->len++; \ 68 release_sem((ifq)->lock); \ 69 release_sem((ifq)->pop); \ 70 } 71 72 #define IFQ_DEQUEUE(ifq, m) { \ 73 acquire_sem((ifq)->lock); \ 74 (m) = (ifq)->head; \ 75 if (m) { \ 76 if (((ifq)->head = (m)->m_nextpkt) == 0) \ 77 (ifq)->tail = 0; \ 78 (m)->m_nextpkt = 0; \ 79 (ifq)->len--; \ 80 } \ 81 release_sem((ifq)->lock); \ 82 } 83 84 struct ifaddr { 85 struct ifaddr *ifa_next; /* the next address for the interface */ 86 struct ifnet *ifa_ifp; /* pointer to the interface structure */ 87 88 struct sockaddr *ifa_addr; /* the address - cast to be a suitable type, so we 89 * use this structure to store any type of address that 90 * we have a struct sockaddr_? for. e.g. 91 * link level address via sockaddr_dl and 92 * ipv4 via sockeddr_in 93 * same for next 2 pointers as well 94 */ 95 struct sockaddr *ifa_dstaddr; /* if we're on a point-to-point link this 96 * is the other end */ 97 struct sockaddr *ifa_netmask; /* The netmask we're using */ 98 99 /* check or clean routes... */ 100 void (*ifa_rtrequest)(int, struct rtentry *, struct sockaddr *); 101 uint8 ifa_flags; /* flags (mainly routing */ 102 uint16 ifa_refcnt; /* how many references are there to 103 * this structure? */ 104 int ifa_metric; /* the metirc for this interface/address */ 105 }; 106 #define ifa_broadaddr ifa_dstaddr 107 108 struct if_data { 109 uint8 ifi_type; /* type of media */ 110 uint8 ifi_addrlen; /* length of media address length */ 111 uint8 ifi_hdrlen; /* size of media header */ 112 uint32 ifi_mtu; /* mtu */ 113 uint32 ifi_metric; /* routing metric */ 114 uint32 ifi_baudrate; /* baudrate of line */ 115 /* statistics!! */ 116 int32 ifi_ipackets; /* packets received on interface */ 117 int32 ifi_ierrors; /* input errors on interface */ 118 int32 ifi_opackets; /* packets sent on interface */ 119 int32 ifi_oerrors; /* output errors on interface */ 120 int32 ifi_collisions; /* collisions on csma interfaces */ 121 int32 ifi_ibytes; /* total number of octets received */ 122 int32 ifi_obytes; /* total number of octets sent */ 123 int32 ifi_imcasts; /* packets received via multicast */ 124 int32 ifi_omcasts; /* packets sent via multicast */ 125 int32 ifi_iqdrops; /* dropped on input, this interface */ 126 int32 ifi_noproto; /* destined for unsupported protocol */ 127 }; 128 129 struct ifnet { 130 struct ifnet *if_next; /* next device */ 131 struct ifaddr *if_addrlist; /* linked list of addresses */ 132 int devid; /* our device id if we have one... */ 133 int id; /* id within the stack's device list */ 134 char *name; /* name of driver e.g. tulip */ 135 int if_unit; /* number of unit e.g 0 */ 136 char *if_name; /* full name, e.g. tulip0 */ 137 struct if_data ifd; /* if_data structure, shortcuts below */ 138 int if_flags; /* if flags */ 139 int if_index; /* our index in ifnet_addrs and interfaces */ 140 141 struct ifq *rxq; 142 thread_id rx_thread; 143 struct ifq *txq; 144 thread_id tx_thread; 145 struct ifq *devq; 146 147 int (*start) (struct ifnet *); 148 int (*stop) (struct ifnet *); 149 void (*input) (struct mbuf*); 150 int (*output)(struct ifnet *, struct mbuf*, 151 struct sockaddr*, struct rtentry *); 152 int (*ioctl) (struct ifnet *, ulong, caddr_t); 153 }; 154 #define if_mtu ifd.ifi_mtu 155 #define if_type ifd.ifi_type 156 #define if_addrlen ifd.ifi_addrlen 157 #define if_hdrlen ifd.ifi_hdrlen 158 #define if_metric ifd.ifi_metric 159 #define if_baudrate ifd.ifi_baudrate 160 #define if_ipackets ifd.ifi_ipackets 161 #define if_ierrors ifd.ifi_ierrors 162 #define if_opackets ifd.ifi_opackets 163 #define if_oerrors ifd.ifi_oerrors 164 #define if_collisions ifd.ifi_collisions 165 #define if_ibytes ifd.ifi_ibytes 166 #define if_obytes ifd.ifi_obytes 167 #define if_imcasts ifd.ifi_imcasts 168 #define if_omcasts ifd.ifi_omcasts 169 #define if_iqdrops ifd.ifi_iqdrops 170 #define if_noproto ifd.ifi_noproto 171 172 #define IFNAMSIZ 16 173 174 /* This structure is used for passing interface requests via ioctl */ 175 struct ifreq { 176 char ifr_name[IFNAMSIZ]; /* name of interface */ 177 union { 178 struct sockaddr ifru_addr; 179 struct sockaddr ifru_dstaddr; 180 struct sockaddr ifru_broadaddr; 181 uint16 ifru_flags; 182 int ifru_metric; 183 char * ifru_data; 184 } ifr_ifru; 185 }; 186 #define ifr_addr ifr_ifru.ifru_addr 187 #define ifr_dstaddr ifr_ifru.ifru_dstaddr 188 #define ifr_broadaddr ifr_ifru.ifru_broadaddr 189 #define ifr_flags ifr_ifru.ifru_flags 190 #define ifr_metric ifr_ifru.ifru_metric 191 #define ifr_mtu ifr_ifru.ifru_metric /* sneaky overload :) */ 192 #define ifr_data ifr_ifru.ifru_data 193 194 struct ifconf { 195 int ifc_len; /* length of associated buffer */ 196 union { 197 char * ifcu_buf; 198 struct ifreq *ifcu_req; 199 } ifc_ifcu; 200 }; 201 #define ifc_buf ifc_ifcu.ifcu_buf 202 #define ifc_req ifc_ifcu.ifcu_req 203 204 205 #define IFAFREE(ifa) \ 206 do { \ 207 if ((ifa)->ifa_refcnt <= 0) \ 208 ifafree(ifa); \ 209 else \ 210 (ifa)->ifa_refcnt--; \ 211 } while (0) 212 213 /* used to pass in additional information, such as aliases */ 214 struct ifaliasreq { 215 char ifa_name[IFNAMSIZ]; 216 struct sockaddr ifra_addr; 217 struct sockaddr ifra_broadaddr; 218 #define ifra_dstaddr ifra_broadaddr 219 struct sockaddr ifra_mask; 220 }; 221 222 #define IFA_ROUTE RTF_UP 223 224 /* 225 * Message format for use in obtaining information about interfaces 226 * from sysctl and the routing socket. 227 */ 228 struct if_msghdr { 229 u_short ifm_msglen; /* to skip over non-understood messages */ 230 u_char ifm_version; /* future binary compatability */ 231 u_char ifm_type; /* message type */ 232 int ifm_addrs; /* like rtm_addrs */ 233 int ifm_flags; /* value of if_flags */ 234 u_short ifm_index; /* index for associated ifp */ 235 struct if_data ifm_data;/* statistics and other data about if */ 236 }; 237 238 /* 239 * Message format for use in obtaining information about interface addresses 240 * from sysctl and the routing socket. 241 */ 242 struct ifa_msghdr { 243 u_short ifam_msglen; /* to skip over non-understood messages */ 244 u_char ifam_version; /* future binary compatability */ 245 u_char ifam_type; /* message type */ 246 int ifam_addrs; /* like rtm_addrs */ 247 int ifam_flags; /* value of ifa_flags */ 248 u_short ifam_index; /* index for associated ifp */ 249 int ifam_metric; /* value of ifa_metric */ 250 }; 251 252 /* function declaration */ 253 struct ifq *start_ifq(void); 254 void stop_ifq(struct ifq *); 255 struct ifnet *get_interfaces(void); 256 struct ifnet *ifunit(char *name); 257 struct ifaddr *ifa_ifwithaddr(struct sockaddr *); 258 struct ifaddr *ifa_ifwithaf(int); 259 struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *); 260 struct ifaddr *ifa_ifwithnet(struct sockaddr *); 261 struct ifaddr *ifa_ifwithroute(int, struct sockaddr *, 262 struct sockaddr *); 263 struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *); 264 void ifafree(struct ifaddr *); 265 266 void if_attach(struct ifnet *ifp); 267 void if_detach(struct ifnet *ifp); 268 269 int ifioctl(struct socket *so, ulong cmd, caddr_t data); 270 int ifconf(int cmd, char *data); 271 void if_init(void); 272 273 #ifdef __cplusplus 274 } 275 #endif 276 277 #endif /* _NET_IF_H */ 278 279