if_var.h (67334) | if_var.h (69152) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * From: @(#)if.h 8.1 (Berkeley) 6/10/93 | 1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * From: @(#)if.h 8.1 (Berkeley) 6/10/93 |
34 * $FreeBSD: head/sys/net/if_var.h 67334 2000-10-19 23:15:54Z joe $ | 34 * $FreeBSD: head/sys/net/if_var.h 69152 2000-11-25 07:35:38Z jlemon $ |
35 */ 36 37#ifndef _NET_IF_VAR_H_ 38#define _NET_IF_VAR_H_ 39 40/* 41 * Structures defining a network interface, providing a packet 42 * transport mechanism (ala level 0 of the PUP protocols). --- 27 unchanged lines hidden (view full) --- 70struct proc; 71struct rtentry; 72struct socket; 73struct ether_header; 74#endif 75 76#include <sys/queue.h> /* get TAILQ macros */ 77 | 35 */ 36 37#ifndef _NET_IF_VAR_H_ 38#define _NET_IF_VAR_H_ 39 40/* 41 * Structures defining a network interface, providing a packet 42 * transport mechanism (ala level 0 of the PUP protocols). --- 27 unchanged lines hidden (view full) --- 70struct proc; 71struct rtentry; 72struct socket; 73struct ether_header; 74#endif 75 76#include <sys/queue.h> /* get TAILQ macros */ 77 |
78#include <sys/mbuf.h> 79#include <machine/mutex.h> 80 |
|
78TAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */ 79TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */ 80TAILQ_HEAD(ifprefixhead, ifprefix); 81LIST_HEAD(ifmultihead, ifmultiaddr); 82 83/* 84 * Structure defining a queue for a network interface. 85 */ 86struct ifqueue { 87 struct mbuf *ifq_head; 88 struct mbuf *ifq_tail; 89 int ifq_len; 90 int ifq_maxlen; 91 int ifq_drops; | 81TAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */ 82TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */ 83TAILQ_HEAD(ifprefixhead, ifprefix); 84LIST_HEAD(ifmultihead, ifmultiaddr); 85 86/* 87 * Structure defining a queue for a network interface. 88 */ 89struct ifqueue { 90 struct mbuf *ifq_head; 91 struct mbuf *ifq_tail; 92 int ifq_len; 93 int ifq_maxlen; 94 int ifq_drops; |
95 struct mtx ifq_mtx; |
|
92}; 93 94/* 95 * Structure defining a network interface. 96 * 97 * (Would like to call this struct ``if'', but C isn't PL/1.) 98 */ 99struct ifnet { 100 void *if_softc; /* pointer to driver state */ 101 char *if_name; /* name, e.g. ``en'' or ``lo'' */ 102 TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ 103 struct ifaddrhead if_addrhead; /* linked list of addresses per if */ 104 int if_pcount; /* number of promiscuous listeners */ 105 struct bpf_if *if_bpf; /* packet filter structure */ 106 u_short if_index; /* numeric abbreviation for this if */ 107 short if_unit; /* sub-unit for lower level driver */ 108 short if_timer; /* time 'til if_watchdog called */ 109 short if_flags; /* up/down, broadcast, etc. */ | 96}; 97 98/* 99 * Structure defining a network interface. 100 * 101 * (Would like to call this struct ``if'', but C isn't PL/1.) 102 */ 103struct ifnet { 104 void *if_softc; /* pointer to driver state */ 105 char *if_name; /* name, e.g. ``en'' or ``lo'' */ 106 TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ 107 struct ifaddrhead if_addrhead; /* linked list of addresses per if */ 108 int if_pcount; /* number of promiscuous listeners */ 109 struct bpf_if *if_bpf; /* packet filter structure */ 110 u_short if_index; /* numeric abbreviation for this if */ 111 short if_unit; /* sub-unit for lower level driver */ 112 short if_timer; /* time 'til if_watchdog called */ 113 short if_flags; /* up/down, broadcast, etc. */ |
114 int if_mpsafe; /* XXX TEMPORARY */ |
|
110 int if_ipending; /* interrupts pending */ 111 void *if_linkmib; /* link-type-specific MIB data */ 112 size_t if_linkmiblen; /* length of above data */ 113 struct if_data if_data; 114 struct ifmultihead if_multiaddrs; /* multicast addresses configured */ 115 int if_amcount; /* number of all-multicast requests */ 116/* procedure handles */ 117 int (*if_output) /* output routine (enqueue) */ --- 18 unchanged lines hidden (view full) --- 136 void (*if_init) /* Init routine */ 137 __P((void *)); 138 int (*if_resolvemulti) /* validate/resolve multicast */ 139 __P((struct ifnet *, struct sockaddr **, struct sockaddr *)); 140 struct ifqueue if_snd; /* output queue */ 141 struct ifqueue *if_poll_slowq; /* input queue for slow devices */ 142 struct ifprefixhead if_prefixhead; /* list of prefixes per if */ 143}; | 115 int if_ipending; /* interrupts pending */ 116 void *if_linkmib; /* link-type-specific MIB data */ 117 size_t if_linkmiblen; /* length of above data */ 118 struct if_data if_data; 119 struct ifmultihead if_multiaddrs; /* multicast addresses configured */ 120 int if_amcount; /* number of all-multicast requests */ 121/* procedure handles */ 122 int (*if_output) /* output routine (enqueue) */ --- 18 unchanged lines hidden (view full) --- 141 void (*if_init) /* Init routine */ 142 __P((void *)); 143 int (*if_resolvemulti) /* validate/resolve multicast */ 144 __P((struct ifnet *, struct sockaddr **, struct sockaddr *)); 145 struct ifqueue if_snd; /* output queue */ 146 struct ifqueue *if_poll_slowq; /* input queue for slow devices */ 147 struct ifprefixhead if_prefixhead; /* list of prefixes per if */ 148}; |
149 |
|
144typedef void if_init_f_t __P((void *)); 145 146#define if_mtu if_data.ifi_mtu 147#define if_type if_data.ifi_type 148#define if_physical if_data.ifi_physical 149#define if_addrlen if_data.ifi_addrlen 150#define if_hdrlen if_data.ifi_hdrlen 151#define if_metric if_data.ifi_metric --- 26 unchanged lines hidden (view full) --- 178#define IFI_XMIT 2 /* I want to transmit */ 179 180/* 181 * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq) 182 * are queues of messages stored on ifqueue structures 183 * (defined above). Entries are added to and deleted from these structures 184 * by these macros, which should be called with ipl raised to splimp(). 185 */ | 150typedef void if_init_f_t __P((void *)); 151 152#define if_mtu if_data.ifi_mtu 153#define if_type if_data.ifi_type 154#define if_physical if_data.ifi_physical 155#define if_addrlen if_data.ifi_addrlen 156#define if_hdrlen if_data.ifi_hdrlen 157#define if_metric if_data.ifi_metric --- 26 unchanged lines hidden (view full) --- 184#define IFI_XMIT 2 /* I want to transmit */ 185 186/* 187 * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq) 188 * are queues of messages stored on ifqueue structures 189 * (defined above). Entries are added to and deleted from these structures 190 * by these macros, which should be called with ipl raised to splimp(). 191 */ |
186#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 187#define IF_DROP(ifq) ((ifq)->ifq_drops++) 188#define IF_ENQUEUE(ifq, m) { \ 189 (m)->m_nextpkt = 0; \ 190 if ((ifq)->ifq_tail == 0) \ 191 (ifq)->ifq_head = m; \ 192 else \ 193 (ifq)->ifq_tail->m_nextpkt = m; \ 194 (ifq)->ifq_tail = m; \ 195 (ifq)->ifq_len++; \ 196} 197#define IF_PREPEND(ifq, m) { \ 198 (m)->m_nextpkt = (ifq)->ifq_head; \ 199 if ((ifq)->ifq_tail == 0) \ 200 (ifq)->ifq_tail = (m); \ 201 (ifq)->ifq_head = (m); \ 202 (ifq)->ifq_len++; \ 203} 204#define IF_DEQUEUE(ifq, m) { \ 205 (m) = (ifq)->ifq_head; \ 206 if (m) { \ 207 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \ 208 (ifq)->ifq_tail = 0; \ 209 (m)->m_nextpkt = 0; \ 210 (ifq)->ifq_len--; \ 211 } \ 212} | 192#define IF_LOCK(ifq) mtx_enter(&(ifq)->ifq_mtx, MTX_DEF) 193#define IF_UNLOCK(ifq) mtx_exit(&(ifq)->ifq_mtx, MTX_DEF) 194#define _IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 195#define _IF_DROP(ifq) ((ifq)->ifq_drops++) 196#define _IF_QLEN(ifq) ((ifq)->ifq_len) |
213 | 197 |
198#define _IF_ENQUEUE(ifq, m) do { \ 199 (m)->m_nextpkt = NULL; \ 200 if ((ifq)->ifq_tail == NULL) \ 201 (ifq)->ifq_head = m; \ 202 else \ 203 (ifq)->ifq_tail->m_nextpkt = m; \ 204 (ifq)->ifq_tail = m; \ 205 (ifq)->ifq_len++; \ 206} while (0) 207 208#define IF_ENQUEUE(ifq, m) do { \ 209 IF_LOCK(ifq); \ 210 _IF_ENQUEUE(ifq, m); \ 211 IF_UNLOCK(ifq); \ 212} while (0) 213 214#define _IF_PREPEND(ifq, m) do { \ 215 (m)->m_nextpkt = (ifq)->ifq_head; \ 216 if ((ifq)->ifq_tail == NULL) \ 217 (ifq)->ifq_tail = (m); \ 218 (ifq)->ifq_head = (m); \ 219 (ifq)->ifq_len++; \ 220} while (0) 221 222#define IF_PREPEND(ifq, m) do { \ 223 IF_LOCK(ifq); \ 224 _IF_PREPEND(ifq, m); \ 225 IF_UNLOCK(ifq); \ 226} while (0) 227 228#define _IF_DEQUEUE(ifq, m) do { \ 229 (m) = (ifq)->ifq_head; \ 230 if (m) { \ 231 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \ 232 (ifq)->ifq_tail = NULL; \ 233 (m)->m_nextpkt = NULL; \ 234 (ifq)->ifq_len--; \ 235 } \ 236} while (0) 237 238#define IF_DEQUEUE(ifq, m) do { \ 239 IF_LOCK(ifq); \ 240 _IF_DEQUEUE(ifq, m); \ 241 IF_UNLOCK(ifq); \ 242} while (0) 243 244#define IF_DRAIN(ifq) do { \ 245 struct mbuf *m; \ 246 IF_LOCK(ifq); \ 247 for (;;) { \ 248 _IF_DEQUEUE(ifq, m); \ 249 if (m == NULL) \ 250 break; \ 251 m_freem(m); \ 252 } \ 253 IF_UNLOCK(ifq); \ 254} while (0) 255 |
|
214#ifdef _KERNEL | 256#ifdef _KERNEL |
215#define IF_ENQ_DROP(ifq, m) if_enq_drop(ifq, m) | 257#define IF_HANDOFF(ifq, m, ifp) if_handoff(ifq, m, ifp, 0) 258#define IF_HANDOFF_ADJ(ifq, m, ifp, adj) if_handoff(ifq, m, ifp, adj) |
216 | 259 |
217#if defined(__GNUC__) && defined(MT_HEADER) | |
218static __inline int | 260static __inline int |
219if_queue_drop(struct ifqueue *ifq, struct mbuf *m) | 261if_handoff(struct ifqueue *ifq, struct mbuf *m, struct ifnet *ifp, int adjust) |
220{ | 262{ |
221 IF_DROP(ifq); 222 return 0; 223} | 263 int active = 0; |
224 | 264 |
225static __inline int 226if_enq_drop(struct ifqueue *ifq, struct mbuf *m) 227{ 228 if (IF_QFULL(ifq) && 229 !if_queue_drop(ifq, m)) 230 return 0; 231 IF_ENQUEUE(ifq, m); 232 return 1; | 265 IF_LOCK(ifq); 266 if (_IF_QFULL(ifq)) { 267 _IF_DROP(ifq); 268 IF_UNLOCK(ifq); 269 m_freem(m); 270 return (0); 271 } 272 if (ifp != NULL) { 273 ifp->if_obytes += m->m_pkthdr.len + adjust; 274 if (m->m_flags & M_MCAST) 275 ifp->if_omcasts++; 276 active = ifp->if_flags & IFF_OACTIVE; 277 } 278 _IF_ENQUEUE(ifq, m); 279 IF_UNLOCK(ifq); 280 if (ifp != NULL && !active) { 281 if (ifp->if_mpsafe) { 282 DROP_GIANT_NOSWITCH(); 283 (*ifp->if_start)(ifp); 284 PICKUP_GIANT(); 285 } else { 286 (*ifp->if_start)(ifp); 287 } 288 } 289 return (1); |
233} | 290} |
234#else | |
235 | 291 |
236#ifdef MT_HEADER 237int if_enq_drop __P((struct ifqueue *, struct mbuf *)); 238#endif 239 240#endif 241 | |
242/* 243 * 72 was chosen below because it is the size of a TCP/IP 244 * header (40) + the minimum mss (32). 245 */ 246#define IF_MINMTU 72 247#define IF_MAXMTU 65535 248 249#endif /* _KERNEL */ --- 116 unchanged lines hidden (view full) --- 366void ifafree __P((struct ifaddr *)); 367 368struct ifmultiaddr *ifmaof_ifpforaddr __P((struct sockaddr *, 369 struct ifnet *)); 370int if_simloop __P((struct ifnet *ifp, struct mbuf *m, int af, int hlen)); 371 372#endif /* _KERNEL */ 373 | 292/* 293 * 72 was chosen below because it is the size of a TCP/IP 294 * header (40) + the minimum mss (32). 295 */ 296#define IF_MINMTU 72 297#define IF_MAXMTU 65535 298 299#endif /* _KERNEL */ --- 116 unchanged lines hidden (view full) --- 416void ifafree __P((struct ifaddr *)); 417 418struct ifmultiaddr *ifmaof_ifpforaddr __P((struct sockaddr *, 419 struct ifnet *)); 420int if_simloop __P((struct ifnet *ifp, struct mbuf *m, int af, int hlen)); 421 422#endif /* _KERNEL */ 423 |
374 | |
375#endif /* !_NET_IF_VAR_H_ */ | 424#endif /* !_NET_IF_VAR_H_ */ |