2 /* $KAME: altq_subr.c,v 1.21 2003/11/06 06:32:53 kjc Exp $ */
5 * Copyright (C) 1997-2003
6 * Sony Computer Science Laboratories Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #if defined(__FreeBSD__) || defined(__NetBSD__)
32 #if (__FreeBSD__ != 2)
35 #include "opt_inet6.h"
38 #endif /* __FreeBSD__ || __NetBSD__ */
40 #include <sys/param.h>
41 #include <sys/malloc.h>
43 #include <sys/systm.h>
45 #include <sys/socket.h>
46 #include <sys/socketvar.h>
47 #include <sys/kernel.h>
48 #include <sys/errno.h>
49 #include <sys/syslog.h>
50 #include <sys/sysctl.h>
51 #include <sys/queue.h>
54 #include <net/if_dl.h>
55 #include <net/if_types.h>
57 #include <netinet/in.h>
58 #include <netinet/in_systm.h>
59 #include <netinet/ip.h>
61 #include <netinet/ip6.h>
63 #include <netinet/tcp.h>
64 #include <netinet/udp.h>
66 #include <net/pfvar.h>
67 #include <altq/altq.h>
69 #include <altq/altq_conf.h>
72 /* machine dependent clock related includes */
75 #include "opt_cpu.h" /* for FreeBSD-2.2.8 to get i586_ctr_freq */
79 #include <sys/eventhandler.h>
80 #include <machine/clock.h>
83 #include <machine/cpufunc.h> /* for pentium tsc */
84 #include <machine/specialreg.h> /* for CPUID_TSC */
86 #include <machine/md_var.h> /* for cpu_feature */
87 #elif defined(__NetBSD__) || defined(__OpenBSD__)
88 #include <machine/cpu.h> /* for cpu_feature */
93 * internal function prototypes
95 static void tbr_timeout(void *);
96 int (*altq_input)(struct mbuf *, int) = NULL;
97 static struct mbuf *tbr_dequeue(struct ifaltq *, int);
98 static int tbr_timer = 0; /* token bucket regulator timer */
99 #if !defined(__FreeBSD__) || (__FreeBSD_version < 600000)
100 static struct callout tbr_callout = CALLOUT_INITIALIZER;
102 static struct callout tbr_callout;
105 #ifdef ALTQ3_CLFIER_COMPAT
106 static int extract_ports4(struct mbuf *, struct ip *, struct flowinfo_in *);
108 static int extract_ports6(struct mbuf *, struct ip6_hdr *,
109 struct flowinfo_in6 *);
111 static int apply_filter4(u_int32_t, struct flow_filter *,
112 struct flowinfo_in *);
113 static int apply_ppfilter4(u_int32_t, struct flow_filter *,
114 struct flowinfo_in *);
116 static int apply_filter6(u_int32_t, struct flow_filter6 *,
117 struct flowinfo_in6 *);
119 static int apply_tosfilter4(u_int32_t, struct flow_filter *,
120 struct flowinfo_in *);
121 static u_long get_filt_handle(struct acc_classifier *, int);
122 static struct acc_filter *filth_to_filtp(struct acc_classifier *, u_long);
123 static u_int32_t filt2fibmask(struct flow_filter *);
125 static void ip4f_cache(struct ip *, struct flowinfo_in *);
126 static int ip4f_lookup(struct ip *, struct flowinfo_in *);
127 static int ip4f_init(void);
128 static struct ip4_frag *ip4f_alloc(void);
129 static void ip4f_free(struct ip4_frag *);
130 #endif /* ALTQ3_CLFIER_COMPAT */
133 * alternate queueing support routines
136 /* look up the queue state by the interface name and the queueing type. */
138 altq_lookup(name, type)
144 if ((ifp = ifunit(name)) != NULL) {
145 /* read if_snd unlocked */
146 if (type != ALTQT_NONE && ifp->if_snd.altq_type == type)
147 return (ifp->if_snd.altq_disc);
154 altq_attach(ifq, type, discipline, enqueue, dequeue, request, clfier, classify)
158 int (*enqueue)(struct ifaltq *, struct mbuf *, struct altq_pktattr *);
159 struct mbuf *(*dequeue)(struct ifaltq *, int);
160 int (*request)(struct ifaltq *, int, void *);
162 void *(*classify)(void *, struct mbuf *, int);
165 if (!ALTQ_IS_READY(ifq)) {
172 * pfaltq can override the existing discipline, but altq3 cannot.
173 * check these if clfier is not NULL (which implies altq3).
175 if (clfier != NULL) {
176 if (ALTQ_IS_ENABLED(ifq)) {
180 if (ALTQ_IS_ATTACHED(ifq)) {
186 ifq->altq_type = type;
187 ifq->altq_disc = discipline;
188 ifq->altq_enqueue = enqueue;
189 ifq->altq_dequeue = dequeue;
190 ifq->altq_request = request;
191 ifq->altq_clfier = clfier;
192 ifq->altq_classify = classify;
193 ifq->altq_flags &= (ALTQF_CANTCHANGE|ALTQF_ENABLED);
196 altq_module_incref(type);
209 if (!ALTQ_IS_READY(ifq)) {
213 if (ALTQ_IS_ENABLED(ifq)) {
217 if (!ALTQ_IS_ATTACHED(ifq)) {
223 altq_module_declref(ifq->altq_type);
227 ifq->altq_type = ALTQT_NONE;
228 ifq->altq_disc = NULL;
229 ifq->altq_enqueue = NULL;
230 ifq->altq_dequeue = NULL;
231 ifq->altq_request = NULL;
232 ifq->altq_clfier = NULL;
233 ifq->altq_classify = NULL;
234 ifq->altq_flags &= ALTQF_CANTCHANGE;
248 if (!ALTQ_IS_READY(ifq)) {
252 if (ALTQ_IS_ENABLED(ifq)) {
262 IFQ_PURGE_NOLOCK(ifq);
263 ASSERT(ifq->ifq_len == 0);
264 ifq->ifq_drv_maxlen = 0; /* disable bulk dequeue */
265 ifq->altq_flags |= ALTQF_ENABLED;
266 if (ifq->altq_clfier != NULL)
267 ifq->altq_flags |= ALTQF_CLASSIFY;
281 if (!ALTQ_IS_ENABLED(ifq)) {
291 IFQ_PURGE_NOLOCK(ifq);
292 ASSERT(ifq->ifq_len == 0);
293 ifq->altq_flags &= ~(ALTQF_ENABLED|ALTQF_CLASSIFY);
302 altq_assert(file, line, failedexpr)
303 const char *file, *failedexpr;
306 (void)printf("altq assertion \"%s\" failed: file \"%s\", line %d\n",
307 failedexpr, file, line);
308 panic("altq assertion");
314 * internal representation of token bucket parameters
315 * rate: byte_per_unittime << 32
316 * (((bits_per_sec) / 8) << 32) / machclk_freq
321 #define TBR_SCALE(x) ((int64_t)(x) << TBR_SHIFT)
322 #define TBR_UNSCALE(x) ((x) >> TBR_SHIFT)
329 struct tb_regulator *tbr;
334 IFQ_LOCK_ASSERT(ifq);
336 if (op == ALTDQ_REMOVE && tbr->tbr_lastop == ALTDQ_POLL) {
337 /* if this is a remove after poll, bypass tbr check */
339 /* update token only when it is negative */
340 if (tbr->tbr_token <= 0) {
341 now = read_machclk();
342 interval = now - tbr->tbr_last;
343 if (interval >= tbr->tbr_filluptime)
344 tbr->tbr_token = tbr->tbr_depth;
346 tbr->tbr_token += interval * tbr->tbr_rate;
347 if (tbr->tbr_token > tbr->tbr_depth)
348 tbr->tbr_token = tbr->tbr_depth;
352 /* if token is still negative, don't allow dequeue */
353 if (tbr->tbr_token <= 0)
357 if (ALTQ_IS_ENABLED(ifq))
358 m = (*ifq->altq_dequeue)(ifq, op);
360 if (op == ALTDQ_POLL)
366 if (m != NULL && op == ALTDQ_REMOVE)
367 tbr->tbr_token -= TBR_SCALE(m_pktlen(m));
368 tbr->tbr_lastop = op;
373 * set a token bucket regulator.
374 * if the specified rate is zero, the token bucket regulator is deleted.
377 tbr_set(ifq, profile)
379 struct tb_profile *profile;
381 struct tb_regulator *tbr, *otbr;
383 if (tbr_dequeue_ptr == NULL)
384 tbr_dequeue_ptr = tbr_dequeue;
386 if (machclk_freq == 0)
388 if (machclk_freq == 0) {
389 printf("tbr_set: no cpu clock available!\n");
394 if (profile->rate == 0) {
395 /* delete this tbr */
396 if ((tbr = ifq->altq_tbr) == NULL) {
400 ifq->altq_tbr = NULL;
407 MALLOC(tbr, struct tb_regulator *, sizeof(struct tb_regulator),
409 if (tbr == NULL) { /* can not happen */
413 bzero(tbr, sizeof(struct tb_regulator));
415 tbr->tbr_rate = TBR_SCALE(profile->rate / 8) / machclk_freq;
416 tbr->tbr_depth = TBR_SCALE(profile->depth);
417 if (tbr->tbr_rate > 0)
418 tbr->tbr_filluptime = tbr->tbr_depth / tbr->tbr_rate;
420 tbr->tbr_filluptime = 0xffffffffffffffffLL;
421 tbr->tbr_token = tbr->tbr_depth;
422 tbr->tbr_last = read_machclk();
423 tbr->tbr_lastop = ALTDQ_REMOVE;
426 otbr = ifq->altq_tbr;
427 ifq->altq_tbr = tbr; /* set the new tbr */
430 FREE(otbr, M_DEVBUF);
432 if (tbr_timer == 0) {
433 CALLOUT_RESET(&tbr_callout, 1, tbr_timeout, (void *)0);
442 * tbr_timeout goes through the interface list, and kicks the drivers
460 #if defined(__FreeBSD__) && (__FreeBSD_version >= 500000)
463 for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_list)) {
464 /* read from if_snd unlocked */
465 if (!TBR_IS_ENABLED(&ifp->if_snd))
468 if (!IFQ_IS_EMPTY(&ifp->if_snd) && ifp->if_start != NULL)
469 (*ifp->if_start)(ifp);
471 #if defined(__FreeBSD__) && (__FreeBSD_version >= 500000)
476 CALLOUT_RESET(&tbr_callout, 1, tbr_timeout, (void *)0);
478 tbr_timer = 0; /* don't need tbr_timer anymore */
479 #if defined(__alpha__) && !defined(ALTQ_NOPCC)
482 * XXX read out the machine dependent clock once a second
483 * to detect counter wrap-around.
488 (void)read_machclk();
492 #endif /* __alpha__ && !ALTQ_NOPCC */
496 * get token bucket regulator profile
499 tbr_get(ifq, profile)
501 struct tb_profile *profile;
503 struct tb_regulator *tbr;
506 if ((tbr = ifq->altq_tbr) == NULL) {
511 (u_int)TBR_UNSCALE(tbr->tbr_rate * 8 * machclk_freq);
512 profile->depth = (u_int)TBR_UNSCALE(tbr->tbr_depth);
519 * attach a discipline to the interface. if one already exists, it is
521 * Locking is done in the discipline specific attach functions. Basically
522 * they call back to altq_attach which takes care of the attach and locking.
525 altq_pfattach(struct pf_altq *a)
529 switch (a->scheduler) {
534 error = cbq_pfattach(a);
539 error = priq_pfattach(a);
544 error = hfsc_pfattach(a);
555 * detach a discipline from the interface.
556 * it is possible that the discipline was already overridden by another
560 altq_pfdetach(struct pf_altq *a)
565 if ((ifp = ifunit(a->ifname)) == NULL)
568 /* if this discipline is no longer referenced, just return */
569 /* read unlocked from if_snd */
570 if (a->altq_disc == NULL || a->altq_disc != ifp->if_snd.altq_disc)
578 /* read unlocked from if_snd, _disable and _detach take care */
579 if (ALTQ_IS_ENABLED(&ifp->if_snd))
580 error = altq_disable(&ifp->if_snd);
582 error = altq_detach(&ifp->if_snd);
589 * add a discipline or a queue
590 * Locking is done in the discipline specific functions with regards to
591 * malloc with WAITOK, also it is not yet clear which lock to use.
594 altq_add(struct pf_altq *a)
598 if (a->qname[0] != 0)
599 return (altq_add_queue(a));
601 if (machclk_freq == 0)
603 if (machclk_freq == 0)
604 panic("altq_add: no cpu clock");
606 switch (a->scheduler) {
609 error = cbq_add_altq(a);
614 error = priq_add_altq(a);
619 error = hfsc_add_altq(a);
630 * remove a discipline or a queue
631 * It is yet unclear what lock to use to protect this operation, the
632 * discipline specific functions will determine and grab it
635 altq_remove(struct pf_altq *a)
639 if (a->qname[0] != 0)
640 return (altq_remove_queue(a));
642 switch (a->scheduler) {
645 error = cbq_remove_altq(a);
650 error = priq_remove_altq(a);
655 error = hfsc_remove_altq(a);
666 * add a queue to the discipline
667 * It is yet unclear what lock to use to protect this operation, the
668 * discipline specific functions will determine and grab it
671 altq_add_queue(struct pf_altq *a)
675 switch (a->scheduler) {
678 error = cbq_add_queue(a);
683 error = priq_add_queue(a);
688 error = hfsc_add_queue(a);
699 * remove a queue from the discipline
700 * It is yet unclear what lock to use to protect this operation, the
701 * discipline specific functions will determine and grab it
704 altq_remove_queue(struct pf_altq *a)
708 switch (a->scheduler) {
711 error = cbq_remove_queue(a);
716 error = priq_remove_queue(a);
721 error = hfsc_remove_queue(a);
732 * get queue statistics
733 * Locking is done in the discipline specific functions with regards to
734 * copyout operations, also it is not yet clear which lock to use.
737 altq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes)
741 switch (a->scheduler) {
744 error = cbq_getqstats(a, ubuf, nbytes);
749 error = priq_getqstats(a, ubuf, nbytes);
754 error = hfsc_getqstats(a, ubuf, nbytes);
765 * read and write diffserv field in IPv4 or IPv6 header
768 read_dsfield(m, pktattr)
770 struct altq_pktattr *pktattr;
773 u_int8_t ds_field = 0;
775 if (pktattr == NULL ||
776 (pktattr->pattr_af != AF_INET && pktattr->pattr_af != AF_INET6))
777 return ((u_int8_t)0);
779 /* verify that pattr_hdr is within the mbuf data */
780 for (m0 = m; m0 != NULL; m0 = m0->m_next)
781 if ((pktattr->pattr_hdr >= m0->m_data) &&
782 (pktattr->pattr_hdr < m0->m_data + m0->m_len))
785 /* ick, pattr_hdr is stale */
786 pktattr->pattr_af = AF_UNSPEC;
788 printf("read_dsfield: can't locate header!\n");
790 return ((u_int8_t)0);
793 if (pktattr->pattr_af == AF_INET) {
794 struct ip *ip = (struct ip *)pktattr->pattr_hdr;
797 return ((u_int8_t)0); /* version mismatch! */
798 ds_field = ip->ip_tos;
801 else if (pktattr->pattr_af == AF_INET6) {
802 struct ip6_hdr *ip6 = (struct ip6_hdr *)pktattr->pattr_hdr;
805 flowlabel = ntohl(ip6->ip6_flow);
806 if ((flowlabel >> 28) != 6)
807 return ((u_int8_t)0); /* version mismatch! */
808 ds_field = (flowlabel >> 20) & 0xff;
815 write_dsfield(struct mbuf *m, struct altq_pktattr *pktattr, u_int8_t dsfield)
819 if (pktattr == NULL ||
820 (pktattr->pattr_af != AF_INET && pktattr->pattr_af != AF_INET6))
823 /* verify that pattr_hdr is within the mbuf data */
824 for (m0 = m; m0 != NULL; m0 = m0->m_next)
825 if ((pktattr->pattr_hdr >= m0->m_data) &&
826 (pktattr->pattr_hdr < m0->m_data + m0->m_len))
829 /* ick, pattr_hdr is stale */
830 pktattr->pattr_af = AF_UNSPEC;
832 printf("write_dsfield: can't locate header!\n");
837 if (pktattr->pattr_af == AF_INET) {
838 struct ip *ip = (struct ip *)pktattr->pattr_hdr;
843 return; /* version mismatch! */
845 dsfield |= old & 3; /* leave CU bits */
848 ip->ip_tos = dsfield;
850 * update checksum (from RFC1624)
851 * HC' = ~(~HC + ~m + m')
853 sum = ~ntohs(ip->ip_sum) & 0xffff;
854 sum += 0xff00 + (~old & 0xff) + dsfield;
855 sum = (sum >> 16) + (sum & 0xffff);
856 sum += (sum >> 16); /* add carry */
858 ip->ip_sum = htons(~sum & 0xffff);
861 else if (pktattr->pattr_af == AF_INET6) {
862 struct ip6_hdr *ip6 = (struct ip6_hdr *)pktattr->pattr_hdr;
865 flowlabel = ntohl(ip6->ip6_flow);
866 if ((flowlabel >> 28) != 6)
867 return; /* version mismatch! */
868 flowlabel = (flowlabel & 0xf03fffff) | (dsfield << 20);
869 ip6->ip6_flow = htonl(flowlabel);
877 * high resolution clock support taking advantage of a machine dependent
878 * high resolution time counter (e.g., timestamp counter of intel pentium).
880 * - 64-bit-long monotonically-increasing counter
881 * - frequency range is 100M-4GHz (CPU speed)
883 /* if pcc is not available or disabled, emulate 256MHz using microtime() */
884 #define MACHCLK_SHIFT 8
887 u_int32_t machclk_freq;
888 u_int32_t machclk_per_tick;
892 extern u_int32_t cycles_per_sec; /* alpha cpu clock frequency */
893 #elif defined(__NetBSD__) || defined(__OpenBSD__)
894 extern u_int64_t cycles_per_usec; /* alpha cpu clock frequency */
896 #endif /* __alpha__ */
897 #if defined(__i386__) && defined(__NetBSD__)
898 extern u_int64_t cpu_tsc_freq;
899 #endif /* __alpha__ */
901 #if (__FreeBSD_version >= 700035)
902 /* Update TSC freq with the value indicated by the caller. */
904 tsc_freq_changed(void *arg, const struct cf_level *level, int status)
906 /* If there was an error during the transition, don't do anything. */
910 #if (__FreeBSD_version >= 701102) && (defined(__amd64__) || defined(__i386__))
911 /* If TSC is P-state invariant, don't do anything. */
912 if (tsc_is_invariant)
916 /* Total setting for this level gives the new frequency in MHz. */
919 EVENTHANDLER_DEFINE(cpufreq_post_change, tsc_freq_changed, NULL,
920 EVENTHANDLER_PRI_LAST);
921 #endif /* __FreeBSD_version >= 700035 */
924 init_machclk_setup(void)
926 #if (__FreeBSD_version >= 600000)
927 callout_init(&tbr_callout, 0);
932 #if (!defined(__i386__) && !defined(__alpha__)) || defined(ALTQ_NOPCC)
935 #if defined(__FreeBSD__) && defined(SMP)
938 #if defined(__NetBSD__) && defined(MULTIPROCESSOR)
942 /* check if TSC is available */
943 if (machclk_usepcc == 1 && ((cpu_feature & CPUID_TSC) == 0 ||
954 /* Call one-time initialization function. */
956 init_machclk_setup();
960 if (machclk_usepcc == 0) {
961 /* emulate 256MHz using microtime() */
962 machclk_freq = 1000000 << MACHCLK_SHIFT;
963 machclk_per_tick = machclk_freq / hz;
965 printf("altq: emulate %uHz cpu clock\n", machclk_freq);
971 * if the clock frequency (of Pentium TSC or Alpha PCC) is
972 * accessible, just use it.
976 #if (__FreeBSD_version > 300000)
977 machclk_freq = tsc_freq;
979 machclk_freq = i586_ctr_freq;
981 #elif defined(__NetBSD__)
982 machclk_freq = (u_int32_t)cpu_tsc_freq;
983 #elif defined(__OpenBSD__) && (defined(I586_CPU) || defined(I686_CPU))
984 machclk_freq = pentium_mhz * 1000000;
986 #elif defined(__alpha__)
988 machclk_freq = cycles_per_sec;
989 #elif defined(__NetBSD__) || defined(__OpenBSD__)
990 machclk_freq = (u_int32_t)(cycles_per_usec * 1000000);
992 #endif /* __alpha__ */
995 * if we don't know the clock frequency, measure it.
997 if (machclk_freq == 0) {
999 struct timeval tv_start, tv_end;
1000 u_int64_t start, end, diff;
1003 microtime(&tv_start);
1004 start = read_machclk();
1005 timo = hz; /* 1 sec */
1006 (void)tsleep(&wait, PWAIT | PCATCH, "init_machclk", timo);
1008 end = read_machclk();
1009 diff = (u_int64_t)(tv_end.tv_sec - tv_start.tv_sec) * 1000000
1010 + tv_end.tv_usec - tv_start.tv_usec;
1012 machclk_freq = (u_int)((end - start) * 1000000 / diff);
1015 machclk_per_tick = machclk_freq / hz;
1018 printf("altq: CPU clock: %uHz\n", machclk_freq);
1022 #if defined(__OpenBSD__) && defined(__i386__)
1023 static __inline u_int64_t
1027 __asm __volatile(".byte 0x0f, 0x31" : "=A" (rv));
1030 #endif /* __OpenBSD__ && __i386__ */
1037 if (machclk_usepcc) {
1038 #if defined(__i386__)
1040 #elif defined(__alpha__)
1041 static u_int32_t last_pcc, upper;
1045 * for alpha, make a 64bit counter value out of the 32bit
1046 * alpha processor cycle counter.
1047 * read_machclk must be called within a half of its
1048 * wrap-around cycle (about 5 sec for 400MHz cpu) to properly
1049 * detect a counter wrap-around.
1050 * tbr_timeout calls read_machclk once a second.
1052 pcc = (u_int32_t)alpha_rpcc();
1053 if (pcc <= last_pcc)
1056 val = ((u_int64_t)upper << 32) + pcc;
1058 panic("read_machclk");
1064 val = (((u_int64_t)(tv.tv_sec - boottime.tv_sec) * 1000000
1065 + tv.tv_usec) << MACHCLK_SHIFT);
1070 #ifdef ALTQ3_CLFIER_COMPAT
1073 #define IPPROTO_ESP 50 /* encapsulating security payload */
1076 #define IPPROTO_AH 51 /* authentication header */
1080 * extract flow information from a given packet.
1081 * filt_mask shows flowinfo fields required.
1082 * we assume the ip header is in one mbuf, and addresses and ports are
1083 * in network byte order.
1086 altq_extractflow(m, af, flow, filt_bmask)
1089 struct flowinfo *flow;
1090 u_int32_t filt_bmask;
1095 struct flowinfo_in *fin;
1098 ip = mtod(m, struct ip *);
1103 fin = (struct flowinfo_in *)flow;
1104 fin->fi_len = sizeof(struct flowinfo_in);
1105 fin->fi_family = AF_INET;
1107 fin->fi_proto = ip->ip_p;
1108 fin->fi_tos = ip->ip_tos;
1110 fin->fi_src.s_addr = ip->ip_src.s_addr;
1111 fin->fi_dst.s_addr = ip->ip_dst.s_addr;
1113 if (filt_bmask & FIMB4_PORTS)
1114 /* if port info is required, extract port numbers */
1115 extract_ports4(m, ip, fin);
1126 struct flowinfo_in6 *fin6;
1127 struct ip6_hdr *ip6;
1129 ip6 = mtod(m, struct ip6_hdr *);
1130 /* should we check the ip version? */
1132 fin6 = (struct flowinfo_in6 *)flow;
1133 fin6->fi6_len = sizeof(struct flowinfo_in6);
1134 fin6->fi6_family = AF_INET6;
1136 fin6->fi6_proto = ip6->ip6_nxt;
1137 fin6->fi6_tclass = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
1139 fin6->fi6_flowlabel = ip6->ip6_flow & htonl(0x000fffff);
1140 fin6->fi6_src = ip6->ip6_src;
1141 fin6->fi6_dst = ip6->ip6_dst;
1143 if ((filt_bmask & FIMB6_PORTS) ||
1144 ((filt_bmask & FIMB6_PROTO)
1145 && ip6->ip6_nxt > IPPROTO_IPV6))
1147 * if port info is required, or proto is required
1148 * but there are option headers, extract port
1149 * and protocol numbers.
1151 extract_ports6(m, ip6, fin6);
1153 fin6->fi6_sport = 0;
1154 fin6->fi6_dport = 0;
1166 flow->fi_len = sizeof(struct flowinfo);
1167 flow->fi_family = AF_UNSPEC;
1172 * helper routine to extract port numbers
1174 /* structure for ipsec and ipv6 option header template */
1176 u_int8_t opt6_nxt; /* next header */
1177 u_int8_t opt6_hlen; /* header extension length */
1179 u_int32_t ah_spi; /* security parameter index
1180 for authentication header */
1184 * extract port numbers from a ipv4 packet.
1187 extract_ports4(m, ip, fin)
1190 struct flowinfo_in *fin;
1201 ip_off = ntohs(ip->ip_off);
1202 /* if it is a fragment, try cached fragment info */
1203 if (ip_off & IP_OFFMASK) {
1204 ip4f_lookup(ip, fin);
1208 /* locate the mbuf containing the protocol header */
1209 for (m0 = m; m0 != NULL; m0 = m0->m_next)
1210 if (((caddr_t)ip >= m0->m_data) &&
1211 ((caddr_t)ip < m0->m_data + m0->m_len))
1215 printf("extract_ports4: can't locate header! ip=%p\n", ip);
1219 off = ((caddr_t)ip - m0->m_data) + (ip->ip_hl << 2);
1225 while (off >= m0->m_len) {
1229 return (0); /* bogus ip_hl! */
1231 if (m0->m_len < off + 4)
1239 udp = (struct udphdr *)(mtod(m0, caddr_t) + off);
1240 fin->fi_sport = udp->uh_sport;
1241 fin->fi_dport = udp->uh_dport;
1242 fin->fi_proto = proto;
1248 if (fin->fi_gpi == 0){
1251 gpi = (u_int32_t *)(mtod(m0, caddr_t) + off);
1254 fin->fi_proto = proto;
1258 /* get next header and header length */
1261 opt6 = (struct _opt6 *)(mtod(m0, caddr_t) + off);
1262 proto = opt6->opt6_nxt;
1263 off += 8 + (opt6->opt6_hlen * 4);
1264 if (fin->fi_gpi == 0 && m0->m_len >= off + 8)
1265 fin->fi_gpi = opt6->ah_spi;
1267 /* goto the next header */
1269 #endif /* ALTQ_IPSEC */
1272 fin->fi_proto = proto;
1276 /* if this is a first fragment, cache it. */
1278 ip4f_cache(ip, fin);
1285 extract_ports6(m, ip6, fin6)
1287 struct ip6_hdr *ip6;
1288 struct flowinfo_in6 *fin6;
1295 fin6->fi6_sport = 0;
1296 fin6->fi6_dport = 0;
1298 /* locate the mbuf containing the protocol header */
1299 for (m0 = m; m0 != NULL; m0 = m0->m_next)
1300 if (((caddr_t)ip6 >= m0->m_data) &&
1301 ((caddr_t)ip6 < m0->m_data + m0->m_len))
1305 printf("extract_ports6: can't locate header! ip6=%p\n", ip6);
1309 off = ((caddr_t)ip6 - m0->m_data) + sizeof(struct ip6_hdr);
1311 proto = ip6->ip6_nxt;
1313 while (off >= m0->m_len) {
1319 if (m0->m_len < off + 4)
1327 udp = (struct udphdr *)(mtod(m0, caddr_t) + off);
1328 fin6->fi6_sport = udp->uh_sport;
1329 fin6->fi6_dport = udp->uh_dport;
1330 fin6->fi6_proto = proto;
1335 if (fin6->fi6_gpi == 0) {
1338 gpi = (u_int32_t *)(mtod(m0, caddr_t) + off);
1339 fin6->fi6_gpi = *gpi;
1341 fin6->fi6_proto = proto;
1345 /* get next header and header length */
1348 opt6 = (struct _opt6 *)(mtod(m0, caddr_t) + off);
1349 if (fin6->fi6_gpi == 0 && m0->m_len >= off + 8)
1350 fin6->fi6_gpi = opt6->ah_spi;
1351 proto = opt6->opt6_nxt;
1352 off += 8 + (opt6->opt6_hlen * 4);
1353 /* goto the next header */
1357 case IPPROTO_HOPOPTS:
1358 case IPPROTO_ROUTING:
1359 case IPPROTO_DSTOPTS: {
1360 /* get next header and header length */
1363 opt6 = (struct _opt6 *)(mtod(m0, caddr_t) + off);
1364 proto = opt6->opt6_nxt;
1365 off += (opt6->opt6_hlen + 1) * 8;
1366 /* goto the next header */
1370 case IPPROTO_FRAGMENT:
1371 /* ipv6 fragmentations are not supported yet */
1373 fin6->fi6_proto = proto;
1382 * altq common classifier
1385 acc_add_filter(classifier, filter, class, phandle)
1386 struct acc_classifier *classifier;
1387 struct flow_filter *filter;
1391 struct acc_filter *afp, *prev, *tmp;
1395 if (filter->ff_flow.fi_family != AF_INET &&
1396 filter->ff_flow.fi_family != AF_INET6)
1399 if (filter->ff_flow.fi_family != AF_INET)
1403 MALLOC(afp, struct acc_filter *, sizeof(struct acc_filter),
1404 M_DEVBUF, M_WAITOK);
1407 bzero(afp, sizeof(struct acc_filter));
1409 afp->f_filter = *filter;
1410 afp->f_class = class;
1412 i = ACC_WILDCARD_INDEX;
1413 if (filter->ff_flow.fi_family == AF_INET) {
1414 struct flow_filter *filter4 = &afp->f_filter;
1417 * if address is 0, it's a wildcard. if address mask
1418 * isn't set, use full mask.
1420 if (filter4->ff_flow.fi_dst.s_addr == 0)
1421 filter4->ff_mask.mask_dst.s_addr = 0;
1422 else if (filter4->ff_mask.mask_dst.s_addr == 0)
1423 filter4->ff_mask.mask_dst.s_addr = 0xffffffff;
1424 if (filter4->ff_flow.fi_src.s_addr == 0)
1425 filter4->ff_mask.mask_src.s_addr = 0;
1426 else if (filter4->ff_mask.mask_src.s_addr == 0)
1427 filter4->ff_mask.mask_src.s_addr = 0xffffffff;
1429 /* clear extra bits in addresses */
1430 filter4->ff_flow.fi_dst.s_addr &=
1431 filter4->ff_mask.mask_dst.s_addr;
1432 filter4->ff_flow.fi_src.s_addr &=
1433 filter4->ff_mask.mask_src.s_addr;
1436 * if dst address is a wildcard, use hash-entry
1437 * ACC_WILDCARD_INDEX.
1439 if (filter4->ff_mask.mask_dst.s_addr != 0xffffffff)
1440 i = ACC_WILDCARD_INDEX;
1442 i = ACC_GET_HASH_INDEX(filter4->ff_flow.fi_dst.s_addr);
1445 else if (filter->ff_flow.fi_family == AF_INET6) {
1446 struct flow_filter6 *filter6 =
1447 (struct flow_filter6 *)&afp->f_filter;
1448 #ifndef IN6MASK0 /* taken from kame ipv6 */
1449 #define IN6MASK0 {{{ 0, 0, 0, 0 }}}
1450 #define IN6MASK128 {{{ 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }}}
1451 const struct in6_addr in6mask0 = IN6MASK0;
1452 const struct in6_addr in6mask128 = IN6MASK128;
1455 if (IN6_IS_ADDR_UNSPECIFIED(&filter6->ff_flow6.fi6_dst))
1456 filter6->ff_mask6.mask6_dst = in6mask0;
1457 else if (IN6_IS_ADDR_UNSPECIFIED(&filter6->ff_mask6.mask6_dst))
1458 filter6->ff_mask6.mask6_dst = in6mask128;
1459 if (IN6_IS_ADDR_UNSPECIFIED(&filter6->ff_flow6.fi6_src))
1460 filter6->ff_mask6.mask6_src = in6mask0;
1461 else if (IN6_IS_ADDR_UNSPECIFIED(&filter6->ff_mask6.mask6_src))
1462 filter6->ff_mask6.mask6_src = in6mask128;
1464 /* clear extra bits in addresses */
1465 for (i = 0; i < 16; i++)
1466 filter6->ff_flow6.fi6_dst.s6_addr[i] &=
1467 filter6->ff_mask6.mask6_dst.s6_addr[i];
1468 for (i = 0; i < 16; i++)
1469 filter6->ff_flow6.fi6_src.s6_addr[i] &=
1470 filter6->ff_mask6.mask6_src.s6_addr[i];
1472 if (filter6->ff_flow6.fi6_flowlabel == 0)
1473 i = ACC_WILDCARD_INDEX;
1475 i = ACC_GET_HASH_INDEX(filter6->ff_flow6.fi6_flowlabel);
1479 afp->f_handle = get_filt_handle(classifier, i);
1481 /* update filter bitmask */
1482 afp->f_fbmask = filt2fibmask(filter);
1483 classifier->acc_fbmask |= afp->f_fbmask;
1486 * add this filter to the filter list.
1487 * filters are ordered from the highest rule number.
1495 LIST_FOREACH(tmp, &classifier->acc_filters[i], f_chain) {
1496 if (tmp->f_filter.ff_ruleno > afp->f_filter.ff_ruleno)
1502 LIST_INSERT_HEAD(&classifier->acc_filters[i], afp, f_chain);
1504 LIST_INSERT_AFTER(prev, afp, f_chain);
1507 *phandle = afp->f_handle;
1512 acc_delete_filter(classifier, handle)
1513 struct acc_classifier *classifier;
1516 struct acc_filter *afp;
1519 if ((afp = filth_to_filtp(classifier, handle)) == NULL)
1527 LIST_REMOVE(afp, f_chain);
1530 FREE(afp, M_DEVBUF);
1532 /* todo: update filt_bmask */
1538 * delete filters referencing to the specified class.
1539 * if the all flag is not 0, delete all the filters.
1542 acc_discard_filters(classifier, class, all)
1543 struct acc_classifier *classifier;
1547 struct acc_filter *afp;
1555 for (i = 0; i < ACC_FILTER_TABLESIZE; i++) {
1557 LIST_FOREACH(afp, &classifier->acc_filters[i], f_chain)
1558 if (all || afp->f_class == class) {
1559 LIST_REMOVE(afp, f_chain);
1560 FREE(afp, M_DEVBUF);
1561 /* start again from the head */
1564 } while (afp != NULL);
1569 classifier->acc_fbmask = 0;
1575 acc_classify(clfier, m, af)
1580 struct acc_classifier *classifier;
1581 struct flowinfo flow;
1582 struct acc_filter *afp;
1585 classifier = (struct acc_classifier *)clfier;
1586 altq_extractflow(m, af, &flow, classifier->acc_fbmask);
1588 if (flow.fi_family == AF_INET) {
1589 struct flowinfo_in *fp = (struct flowinfo_in *)&flow;
1591 if ((classifier->acc_fbmask & FIMB4_ALL) == FIMB4_TOS) {
1592 /* only tos is used */
1594 &classifier->acc_filters[ACC_WILDCARD_INDEX],
1596 if (apply_tosfilter4(afp->f_fbmask,
1597 &afp->f_filter, fp))
1598 /* filter matched */
1599 return (afp->f_class);
1600 } else if ((classifier->acc_fbmask &
1601 (~(FIMB4_PROTO|FIMB4_SPORT|FIMB4_DPORT) & FIMB4_ALL))
1603 /* only proto and ports are used */
1605 &classifier->acc_filters[ACC_WILDCARD_INDEX],
1607 if (apply_ppfilter4(afp->f_fbmask,
1608 &afp->f_filter, fp))
1609 /* filter matched */
1610 return (afp->f_class);
1612 /* get the filter hash entry from its dest address */
1613 i = ACC_GET_HASH_INDEX(fp->fi_dst.s_addr);
1616 * go through this loop twice. first for dst
1617 * hash, second for wildcards.
1619 LIST_FOREACH(afp, &classifier->acc_filters[i],
1621 if (apply_filter4(afp->f_fbmask,
1622 &afp->f_filter, fp))
1623 /* filter matched */
1624 return (afp->f_class);
1627 * check again for filters with a dst addr
1629 * (daddr == 0 || dmask != 0xffffffff).
1631 if (i != ACC_WILDCARD_INDEX)
1632 i = ACC_WILDCARD_INDEX;
1639 else if (flow.fi_family == AF_INET6) {
1640 struct flowinfo_in6 *fp6 = (struct flowinfo_in6 *)&flow;
1642 /* get the filter hash entry from its flow ID */
1643 if (fp6->fi6_flowlabel != 0)
1644 i = ACC_GET_HASH_INDEX(fp6->fi6_flowlabel);
1646 /* flowlable can be zero */
1647 i = ACC_WILDCARD_INDEX;
1649 /* go through this loop twice. first for flow hash, second
1652 LIST_FOREACH(afp, &classifier->acc_filters[i], f_chain)
1653 if (apply_filter6(afp->f_fbmask,
1654 (struct flow_filter6 *)&afp->f_filter,
1656 /* filter matched */
1657 return (afp->f_class);
1660 * check again for filters with a wildcard.
1662 if (i != ACC_WILDCARD_INDEX)
1663 i = ACC_WILDCARD_INDEX;
1670 /* no filter matched */
1675 apply_filter4(fbmask, filt, pkt)
1677 struct flow_filter *filt;
1678 struct flowinfo_in *pkt;
1680 if (filt->ff_flow.fi_family != AF_INET)
1682 if ((fbmask & FIMB4_SPORT) && filt->ff_flow.fi_sport != pkt->fi_sport)
1684 if ((fbmask & FIMB4_DPORT) && filt->ff_flow.fi_dport != pkt->fi_dport)
1686 if ((fbmask & FIMB4_DADDR) &&
1687 filt->ff_flow.fi_dst.s_addr !=
1688 (pkt->fi_dst.s_addr & filt->ff_mask.mask_dst.s_addr))
1690 if ((fbmask & FIMB4_SADDR) &&
1691 filt->ff_flow.fi_src.s_addr !=
1692 (pkt->fi_src.s_addr & filt->ff_mask.mask_src.s_addr))
1694 if ((fbmask & FIMB4_PROTO) && filt->ff_flow.fi_proto != pkt->fi_proto)
1696 if ((fbmask & FIMB4_TOS) && filt->ff_flow.fi_tos !=
1697 (pkt->fi_tos & filt->ff_mask.mask_tos))
1699 if ((fbmask & FIMB4_GPI) && filt->ff_flow.fi_gpi != (pkt->fi_gpi))
1706 * filter matching function optimized for a common case that checks
1707 * only protocol and port numbers
1710 apply_ppfilter4(fbmask, filt, pkt)
1712 struct flow_filter *filt;
1713 struct flowinfo_in *pkt;
1715 if (filt->ff_flow.fi_family != AF_INET)
1717 if ((fbmask & FIMB4_SPORT) && filt->ff_flow.fi_sport != pkt->fi_sport)
1719 if ((fbmask & FIMB4_DPORT) && filt->ff_flow.fi_dport != pkt->fi_dport)
1721 if ((fbmask & FIMB4_PROTO) && filt->ff_flow.fi_proto != pkt->fi_proto)
1728 * filter matching function only for tos field.
1731 apply_tosfilter4(fbmask, filt, pkt)
1733 struct flow_filter *filt;
1734 struct flowinfo_in *pkt;
1736 if (filt->ff_flow.fi_family != AF_INET)
1738 if ((fbmask & FIMB4_TOS) && filt->ff_flow.fi_tos !=
1739 (pkt->fi_tos & filt->ff_mask.mask_tos))
1747 apply_filter6(fbmask, filt, pkt)
1749 struct flow_filter6 *filt;
1750 struct flowinfo_in6 *pkt;
1754 if (filt->ff_flow6.fi6_family != AF_INET6)
1756 if ((fbmask & FIMB6_FLABEL) &&
1757 filt->ff_flow6.fi6_flowlabel != pkt->fi6_flowlabel)
1759 if ((fbmask & FIMB6_PROTO) &&
1760 filt->ff_flow6.fi6_proto != pkt->fi6_proto)
1762 if ((fbmask & FIMB6_SPORT) &&
1763 filt->ff_flow6.fi6_sport != pkt->fi6_sport)
1765 if ((fbmask & FIMB6_DPORT) &&
1766 filt->ff_flow6.fi6_dport != pkt->fi6_dport)
1768 if (fbmask & FIMB6_SADDR) {
1769 for (i = 0; i < 4; i++)
1770 if (filt->ff_flow6.fi6_src.s6_addr32[i] !=
1771 (pkt->fi6_src.s6_addr32[i] &
1772 filt->ff_mask6.mask6_src.s6_addr32[i]))
1775 if (fbmask & FIMB6_DADDR) {
1776 for (i = 0; i < 4; i++)
1777 if (filt->ff_flow6.fi6_dst.s6_addr32[i] !=
1778 (pkt->fi6_dst.s6_addr32[i] &
1779 filt->ff_mask6.mask6_dst.s6_addr32[i]))
1782 if ((fbmask & FIMB6_TCLASS) &&
1783 filt->ff_flow6.fi6_tclass !=
1784 (pkt->fi6_tclass & filt->ff_mask6.mask6_tclass))
1786 if ((fbmask & FIMB6_GPI) &&
1787 filt->ff_flow6.fi6_gpi != pkt->fi6_gpi)
1796 * bit 20-28: index to the filter hash table
1797 * bit 0-19: unique id in the hash bucket.
1800 get_filt_handle(classifier, i)
1801 struct acc_classifier *classifier;
1804 static u_long handle_number = 1;
1806 struct acc_filter *afp;
1809 handle = handle_number++ & 0x000fffff;
1811 if (LIST_EMPTY(&classifier->acc_filters[i]))
1814 LIST_FOREACH(afp, &classifier->acc_filters[i], f_chain)
1815 if ((afp->f_handle & 0x000fffff) == handle)
1819 /* this handle is already used, try again */
1822 return ((i << 20) | handle);
1825 /* convert filter handle to filter pointer */
1826 static struct acc_filter *
1827 filth_to_filtp(classifier, handle)
1828 struct acc_classifier *classifier;
1831 struct acc_filter *afp;
1834 i = ACC_GET_HINDEX(handle);
1836 LIST_FOREACH(afp, &classifier->acc_filters[i], f_chain)
1837 if (afp->f_handle == handle)
1843 /* create flowinfo bitmask */
1846 struct flow_filter *filt;
1850 struct flow_filter6 *filt6;
1853 switch (filt->ff_flow.fi_family) {
1855 if (filt->ff_flow.fi_proto != 0)
1856 mask |= FIMB4_PROTO;
1857 if (filt->ff_flow.fi_tos != 0)
1859 if (filt->ff_flow.fi_dst.s_addr != 0)
1860 mask |= FIMB4_DADDR;
1861 if (filt->ff_flow.fi_src.s_addr != 0)
1862 mask |= FIMB4_SADDR;
1863 if (filt->ff_flow.fi_sport != 0)
1864 mask |= FIMB4_SPORT;
1865 if (filt->ff_flow.fi_dport != 0)
1866 mask |= FIMB4_DPORT;
1867 if (filt->ff_flow.fi_gpi != 0)
1872 filt6 = (struct flow_filter6 *)filt;
1874 if (filt6->ff_flow6.fi6_proto != 0)
1875 mask |= FIMB6_PROTO;
1876 if (filt6->ff_flow6.fi6_tclass != 0)
1877 mask |= FIMB6_TCLASS;
1878 if (!IN6_IS_ADDR_UNSPECIFIED(&filt6->ff_flow6.fi6_dst))
1879 mask |= FIMB6_DADDR;
1880 if (!IN6_IS_ADDR_UNSPECIFIED(&filt6->ff_flow6.fi6_src))
1881 mask |= FIMB6_SADDR;
1882 if (filt6->ff_flow6.fi6_sport != 0)
1883 mask |= FIMB6_SPORT;
1884 if (filt6->ff_flow6.fi6_dport != 0)
1885 mask |= FIMB6_DPORT;
1886 if (filt6->ff_flow6.fi6_gpi != 0)
1888 if (filt6->ff_flow6.fi6_flowlabel != 0)
1889 mask |= FIMB6_FLABEL;
1898 * helper functions to handle IPv4 fragments.
1899 * currently only in-sequence fragments are handled.
1900 * - fragment info is cached in a LRU list.
1901 * - when a first fragment is found, cache its flow info.
1902 * - when a non-first fragment is found, lookup the cache.
1906 TAILQ_ENTRY(ip4_frag) ip4f_chain;
1909 struct flowinfo_in ip4f_info;
1912 static TAILQ_HEAD(ip4f_list, ip4_frag) ip4f_list; /* IPv4 fragment cache */
1914 #define IP4F_TABSIZE 16 /* IPv4 fragment cache size */
1920 struct flowinfo_in *fin;
1922 struct ip4_frag *fp;
1924 if (TAILQ_EMPTY(&ip4f_list)) {
1925 /* first time call, allocate fragment cache entries. */
1926 if (ip4f_init() < 0)
1927 /* allocation failed! */
1932 fp->ip4f_id = ip->ip_id;
1933 fp->ip4f_info.fi_proto = ip->ip_p;
1934 fp->ip4f_info.fi_src.s_addr = ip->ip_src.s_addr;
1935 fp->ip4f_info.fi_dst.s_addr = ip->ip_dst.s_addr;
1937 /* save port numbers */
1938 fp->ip4f_info.fi_sport = fin->fi_sport;
1939 fp->ip4f_info.fi_dport = fin->fi_dport;
1940 fp->ip4f_info.fi_gpi = fin->fi_gpi;
1944 ip4f_lookup(ip, fin)
1946 struct flowinfo_in *fin;
1948 struct ip4_frag *fp;
1950 for (fp = TAILQ_FIRST(&ip4f_list); fp != NULL && fp->ip4f_valid;
1951 fp = TAILQ_NEXT(fp, ip4f_chain))
1952 if (ip->ip_id == fp->ip4f_id &&
1953 ip->ip_src.s_addr == fp->ip4f_info.fi_src.s_addr &&
1954 ip->ip_dst.s_addr == fp->ip4f_info.fi_dst.s_addr &&
1955 ip->ip_p == fp->ip4f_info.fi_proto) {
1957 /* found the matching entry */
1958 fin->fi_sport = fp->ip4f_info.fi_sport;
1959 fin->fi_dport = fp->ip4f_info.fi_dport;
1960 fin->fi_gpi = fp->ip4f_info.fi_gpi;
1962 if ((ntohs(ip->ip_off) & IP_MF) == 0)
1963 /* this is the last fragment,
1964 release the entry. */
1970 /* no matching entry found */
1977 struct ip4_frag *fp;
1980 TAILQ_INIT(&ip4f_list);
1981 for (i=0; i<IP4F_TABSIZE; i++) {
1982 MALLOC(fp, struct ip4_frag *, sizeof(struct ip4_frag),
1983 M_DEVBUF, M_NOWAIT);
1985 printf("ip4f_init: can't alloc %dth entry!\n", i);
1991 TAILQ_INSERT_TAIL(&ip4f_list, fp, ip4f_chain);
1996 static struct ip4_frag *
1999 struct ip4_frag *fp;
2001 /* reclaim an entry at the tail, put it at the head */
2002 fp = TAILQ_LAST(&ip4f_list, ip4f_list);
2003 TAILQ_REMOVE(&ip4f_list, fp, ip4f_chain);
2005 TAILQ_INSERT_HEAD(&ip4f_list, fp, ip4f_chain);
2011 struct ip4_frag *fp;
2013 TAILQ_REMOVE(&ip4f_list, fp, ip4f_chain);
2015 TAILQ_INSERT_TAIL(&ip4f_list, fp, ip4f_chain);
2018 #endif /* ALTQ3_CLFIER_COMPAT */