diff options
Diffstat (limited to 'sys/net/if.h')
-rw-r--r-- | sys/net/if.h | 139 |
1 files changed, 131 insertions, 8 deletions
diff --git a/sys/net/if.h b/sys/net/if.h index 0bf2b61588f..e486c42adc5 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if.h,v 1.28 2001/06/23 22:52:51 fgsch Exp $ */ +/* $OpenBSD: if.h,v 1.29 2001/06/27 05:50:06 kjc Exp $ */ /* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */ /* @@ -42,6 +42,14 @@ #include <sys/queue.h> /* + * Always include ALTQ glue here -- we use the ALTQ interface queue + * structure even when ALTQ is not configured into the kernel so that + * the size of struct ifnet does not changed based on the option. The + * ALTQ queue structure is API-compatible with the legacy ifqueue. + */ +#include <altq/if_altq.h> + +/* * Structures defining a network interface, providing a packet * transport mechanism (ala level 0 of the PUP protocols). * @@ -105,6 +113,17 @@ struct if_data { }; /* + * Structure defining a queue for a network interface. + */ +struct ifqueue { + struct mbuf *ifq_head; + struct mbuf *ifq_tail; + int ifq_len; + int ifq_maxlen; + int ifq_drops; +}; + +/* * Values for if_link_state. */ #define LINK_STATE_UNKNOWN 0 /* link invalid/unknown */ @@ -151,13 +170,7 @@ struct ifnet { /* and the entries */ __P((struct ifnet *)); void (*if_watchdog) /* timer routine */ __P((struct ifnet *)); - struct ifqueue { - struct mbuf *ifq_head; - struct mbuf *ifq_tail; - int ifq_len; - int ifq_maxlen; - int ifq_drops; - } if_snd; /* output queue */ + struct ifaltq if_snd; /* output queue (includes altq) */ struct ifprefix *if_prefixlist; /* linked list of prefixes per if */ }; #define if_mtu if_data.ifi_mtu @@ -250,6 +263,20 @@ struct ifnet { /* and the entries */ (ifq)->ifq_len--; \ } \ } +#define IF_POLL(ifq, m) ((m) = (ifq)->ifq_head) +#define IF_PURGE(ifq) \ +do { \ + struct mbuf *__m0; \ + \ + for (;;) { \ + IF_DEQUEUE((ifq), __m0); \ + if (__m0 == NULL) \ + break; \ + else \ + m_freem(__m0); \ + } \ +} while (0) +#define IF_IS_EMPTY(ifq) ((ifq)->ifq_len == 0) #define IFQ_MAXLEN 50 #define IFNET_SLOWHZ 1 /* granularity is 1 second */ @@ -415,6 +442,102 @@ do { \ (ifa)->ifa_refcnt--; \ } while (0) +#ifdef ALTQ +#define ALTQ_DECL(x) x + +#define IFQ_ENQUEUE(ifq, m, pattr, err) \ +do { \ + if (ALTQ_IS_ENABLED((ifq))) \ + ALTQ_ENQUEUE((ifq), (m), (pattr), (err)); \ + else { \ + if (IF_QFULL((ifq))) { \ + m_freem((m)); \ + (err) = ENOBUFS; \ + } else { \ + IF_ENQUEUE((ifq), (m)); \ + (err) = 0; \ + } \ + } \ + if ((err)) \ + (ifq)->ifq_drops++; \ +} while (0) + +#define IFQ_DEQUEUE(ifq, m) \ +do { \ + if (TBR_IS_ENABLED((ifq))) \ + (m) = tbr_dequeue((ifq), ALTDQ_REMOVE); \ + else if (ALTQ_IS_ENABLED((ifq))) \ + ALTQ_DEQUEUE((ifq), (m)); \ + else \ + IF_DEQUEUE((ifq), (m)); \ +} while (0) + +#define IFQ_POLL(ifq, m) \ +do { \ + if (TBR_IS_ENABLED((ifq))) \ + (m) = tbr_dequeue((ifq), ALTDQ_POLL); \ + else if (ALTQ_IS_ENABLED((ifq))) \ + ALTQ_POLL((ifq), (m)); \ + else \ + IF_POLL((ifq), (m)); \ +} while (0) + +#define IFQ_PURGE(ifq) \ +do { \ + if (ALTQ_IS_ENABLED((ifq))) \ + ALTQ_PURGE((ifq)); \ + else \ + IF_PURGE((ifq)); \ +} while (0) + +#define IFQ_SET_READY(ifq) \ + do { ((ifq)->altq_flags |= ALTQF_READY); } while (0) + +#define IFQ_CLASSIFY(ifq, m, af, pa) \ +do { \ + if (ALTQ_IS_ENABLED((ifq))) { \ + if (ALTQ_NEEDS_CLASSIFY((ifq))) \ + (pa)->pattr_class = (*(ifq)->altq_classify) \ + ((ifq)->altq_clfier, (m), (af)); \ + (pa)->pattr_af = (af); \ + (pa)->pattr_hdr = mtod((m), caddr_t); \ + } \ +} while (0) + +#else /* !ALTQ */ +#define ALTQ_DECL(x) /* nothing */ + +#define IFQ_ENQUEUE(ifq, m, pattr, err) \ +do { \ + if (IF_QFULL((ifq))) { \ + m_freem((m)); \ + (err) = ENOBUFS; \ + } else { \ + IF_ENQUEUE((ifq), (m)); \ + (err) = 0; \ + } \ + if ((err)) \ + (ifq)->ifq_drops++; \ +} while (0) + +#define IFQ_DEQUEUE(ifq, m) IF_DEQUEUE((ifq), (m)) + +#define IFQ_POLL(ifq, m) IF_POLL((ifq), (m)) + +#define IFQ_PURGE(ifq) IF_PURGE((ifq)) + +#define IFQ_SET_READY(ifq) /* nothing */ + +#define IFQ_CLASSIFY(ifq, m, af, pa) /* nothing */ + +#endif /* ALTQ */ + +#define IFQ_IS_EMPTY(ifq) ((ifq)->ifq_len == 0) +#define IFQ_INC_LEN(ifq) ((ifq)->ifq_len++) +#define IFQ_DEC_LEN(ifq) (--(ifq)->ifq_len) +#define IFQ_INC_DROPS(ifq) ((ifq)->ifq_drops++) +#define IFQ_SET_MAXLEN(ifq, len) ((ifq)->ifq_maxlen = (len)) + struct ifnet_head ifnet; struct ifnet **ifindex2ifnet; struct ifnet *lo0ifp; |