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__)
34 #include "opt_inet6.h"
36 #endif /* __FreeBSD__ || __NetBSD__ */
38 #include <sys/param.h>
39 #include <sys/malloc.h>
41 #include <sys/systm.h>
43 #include <sys/socket.h>
44 #include <sys/socketvar.h>
45 #include <sys/kernel.h>
46 #include <sys/errno.h>
47 #include <sys/syslog.h>
48 #include <sys/sysctl.h>
49 #include <sys/queue.h>
52 #include <net/if_dl.h>
53 #include <net/if_types.h>
58 #include <netinet/in.h>
59 #include <netinet/in_systm.h>
60 #include <netinet/ip.h>
62 #include <netinet/ip6.h>
64 #include <netinet/tcp.h>
65 #include <netinet/udp.h>
67 #include <net/pfvar.h>
68 #include <altq/altq.h>
70 #include <altq/altq_conf.h>
73 /* machine dependent clock related includes */
76 #include "opt_cpu.h" /* for FreeBSD-2.2.8 to get i586_ctr_freq */
80 #include <sys/eventhandler.h>
81 #include <machine/clock.h>
84 #include <machine/cpufunc.h> /* for pentium tsc */
85 #include <machine/specialreg.h> /* for CPUID_TSC */
87 #include <machine/md_var.h> /* for cpu_feature */
88 #elif defined(__NetBSD__) || defined(__OpenBSD__)
89 #include <machine/cpu.h> /* for cpu_feature */
94 * internal function prototypes
96 static void tbr_timeout(void *);
97 int (*altq_input)(struct mbuf *, int) = NULL;
98 static struct mbuf *tbr_dequeue(struct ifaltq *, int);
99 static int tbr_timer = 0; /* token bucket regulator timer */
100 #if !defined(__FreeBSD__) || (__FreeBSD_version < 600000)
101 static struct callout tbr_callout = CALLOUT_INITIALIZER;
103 static struct callout tbr_callout;
106 #ifdef ALTQ3_CLFIER_COMPAT
107 static int extract_ports4(struct mbuf *, struct ip *, struct flowinfo_in *);
109 static int extract_ports6(struct mbuf *, struct ip6_hdr *,
110 struct flowinfo_in6 *);
112 static int apply_filter4(u_int32_t, struct flow_filter *,
113 struct flowinfo_in *);
114 static int apply_ppfilter4(u_int32_t, struct flow_filter *,
115 struct flowinfo_in *);
117 static int apply_filter6(u_int32_t, struct flow_filter6 *,
118 struct flowinfo_in6 *);
120 static int apply_tosfilter4(u_int32_t, struct flow_filter *,
121 struct flowinfo_in *);
122 static u_long get_filt_handle(struct acc_classifier *, int);
123 static struct acc_filter *filth_to_filtp(struct acc_classifier *, u_long);
124 static u_int32_t filt2fibmask(struct flow_filter *);
126 static void ip4f_cache(struct ip *, struct flowinfo_in *);
127 static int ip4f_lookup(struct ip *, struct flowinfo_in *);
128 static int ip4f_init(void);
129 static struct ip4_frag *ip4f_alloc(void);
130 static void ip4f_free(struct ip4_frag *);
131 #endif /* ALTQ3_CLFIER_COMPAT */
134 * alternate queueing support routines
137 /* look up the queue state by the interface name and the queueing type. */
139 altq_lookup(name, type)
145 if ((ifp = ifunit(name)) != NULL) {
146 /* read if_snd unlocked */
147 if (type != ALTQT_NONE && ifp->if_snd.altq_type == type)
148 return (ifp->if_snd.altq_disc);
155 altq_attach(ifq, type, discipline, enqueue, dequeue, request, clfier, classify)
159 int (*enqueue)(struct ifaltq *, struct mbuf *, struct altq_pktattr *);
160 struct mbuf *(*dequeue)(struct ifaltq *, int);
161 int (*request)(struct ifaltq *, int, void *);
163 void *(*classify)(void *, struct mbuf *, int);
166 if (!ALTQ_IS_READY(ifq)) {
173 * pfaltq can override the existing discipline, but altq3 cannot.
174 * check these if clfier is not NULL (which implies altq3).
176 if (clfier != NULL) {
177 if (ALTQ_IS_ENABLED(ifq)) {
181 if (ALTQ_IS_ATTACHED(ifq)) {
187 ifq->altq_type = type;
188 ifq->altq_disc = discipline;
189 ifq->altq_enqueue = enqueue;
190 ifq->altq_dequeue = dequeue;
191 ifq->altq_request = request;
192 ifq->altq_clfier = clfier;
193 ifq->altq_classify = classify;
194 ifq->altq_flags &= (ALTQF_CANTCHANGE|ALTQF_ENABLED);
197 altq_module_incref(type);
210 if (!ALTQ_IS_READY(ifq)) {
214 if (ALTQ_IS_ENABLED(ifq)) {
218 if (!ALTQ_IS_ATTACHED(ifq)) {
224 altq_module_declref(ifq->altq_type);
228 ifq->altq_type = ALTQT_NONE;
229 ifq->altq_disc = NULL;
230 ifq->altq_enqueue = NULL;
231 ifq->altq_dequeue = NULL;
232 ifq->altq_request = NULL;
233 ifq->altq_clfier = NULL;
234 ifq->altq_classify = NULL;
235 ifq->altq_flags &= ALTQF_CANTCHANGE;
249 if (!ALTQ_IS_READY(ifq)) {
253 if (ALTQ_IS_ENABLED(ifq)) {
263 IFQ_PURGE_NOLOCK(ifq);
264 ASSERT(ifq->ifq_len == 0);
265 ifq->ifq_drv_maxlen = 0; /* disable bulk dequeue */
266 ifq->altq_flags |= ALTQF_ENABLED;
267 if (ifq->altq_clfier != NULL)
268 ifq->altq_flags |= ALTQF_CLASSIFY;
282 if (!ALTQ_IS_ENABLED(ifq)) {
292 IFQ_PURGE_NOLOCK(ifq);
293 ASSERT(ifq->ifq_len == 0);
294 ifq->altq_flags &= ~(ALTQF_ENABLED|ALTQF_CLASSIFY);
303 altq_assert(file, line, failedexpr)
304 const char *file, *failedexpr;
307 (void)printf("altq assertion \"%s\" failed: file \"%s\", line %d\n",
308 failedexpr, file, line);
309 panic("altq assertion");
315 * internal representation of token bucket parameters
316 * rate: byte_per_unittime << 32
317 * (((bits_per_sec) / 8) << 32) / machclk_freq
322 #define TBR_SCALE(x) ((int64_t)(x) << TBR_SHIFT)
323 #define TBR_UNSCALE(x) ((x) >> TBR_SHIFT)
330 struct tb_regulator *tbr;
335 IFQ_LOCK_ASSERT(ifq);
337 if (op == ALTDQ_REMOVE && tbr->tbr_lastop == ALTDQ_POLL) {
338 /* if this is a remove after poll, bypass tbr check */
340 /* update token only when it is negative */
341 if (tbr->tbr_token <= 0) {
342 now = read_machclk();
343 interval = now - tbr->tbr_last;
344 if (interval >= tbr->tbr_filluptime)
345 tbr->tbr_token = tbr->tbr_depth;
347 tbr->tbr_token += interval * tbr->tbr_rate;
348 if (tbr->tbr_token > tbr->tbr_depth)
349 tbr->tbr_token = tbr->tbr_depth;
353 /* if token is still negative, don't allow dequeue */
354 if (tbr->tbr_token <= 0)
358 if (ALTQ_IS_ENABLED(ifq))
359 m = (*ifq->altq_dequeue)(ifq, op);
361 if (op == ALTDQ_POLL)
367 if (m != NULL && op == ALTDQ_REMOVE)
368 tbr->tbr_token -= TBR_SCALE(m_pktlen(m));
369 tbr->tbr_lastop = op;
374 * set a token bucket regulator.
375 * if the specified rate is zero, the token bucket regulator is deleted.
378 tbr_set(ifq, profile)
380 struct tb_profile *profile;
382 struct tb_regulator *tbr, *otbr;
384 if (tbr_dequeue_ptr == NULL)
385 tbr_dequeue_ptr = tbr_dequeue;
387 if (machclk_freq == 0)
389 if (machclk_freq == 0) {
390 printf("tbr_set: no cpu clock available!\n");
395 if (profile->rate == 0) {
396 /* delete this tbr */
397 if ((tbr = ifq->altq_tbr) == NULL) {
401 ifq->altq_tbr = NULL;
408 tbr = malloc(sizeof(struct tb_regulator),
410 if (tbr == NULL) { /* can not happen */
414 bzero(tbr, sizeof(struct tb_regulator));
416 tbr->tbr_rate = TBR_SCALE(profile->rate / 8) / machclk_freq;
417 tbr->tbr_depth = TBR_SCALE(profile->depth);
418 if (tbr->tbr_rate > 0)
419 tbr->tbr_filluptime = tbr->tbr_depth / tbr->tbr_rate;
421 tbr->tbr_filluptime = 0xffffffffffffffffLL;
422 tbr->tbr_token = tbr->tbr_depth;
423 tbr->tbr_last = read_machclk();
424 tbr->tbr_lastop = ALTDQ_REMOVE;
427 otbr = ifq->altq_tbr;
428 ifq->altq_tbr = tbr; /* set the new tbr */
431 free(otbr, M_DEVBUF);
433 if (tbr_timer == 0) {
434 CALLOUT_RESET(&tbr_callout, 1, tbr_timeout, (void *)0);
443 * tbr_timeout goes through the interface list, and kicks the drivers
452 #if defined(__FreeBSD__)
453 VNET_ITERATOR_DECL(vnet_iter);
464 #if defined(__FreeBSD__) && (__FreeBSD_version >= 500000)
467 VNET_FOREACH(vnet_iter) {
468 CURVNET_SET(vnet_iter);
470 for (ifp = TAILQ_FIRST(&V_ifnet); ifp;
471 ifp = TAILQ_NEXT(ifp, if_list)) {
472 /* read from if_snd unlocked */
473 if (!TBR_IS_ENABLED(&ifp->if_snd))
476 if (!IFQ_IS_EMPTY(&ifp->if_snd) &&
477 ifp->if_start != NULL)
478 (*ifp->if_start)(ifp);
480 #if defined(__FreeBSD__) && (__FreeBSD_version >= 500000)
488 CALLOUT_RESET(&tbr_callout, 1, tbr_timeout, (void *)0);
490 tbr_timer = 0; /* don't need tbr_timer anymore */
491 #if defined(__alpha__) && !defined(ALTQ_NOPCC)
494 * XXX read out the machine dependent clock once a second
495 * to detect counter wrap-around.
500 (void)read_machclk();
504 #endif /* __alpha__ && !ALTQ_NOPCC */
508 * get token bucket regulator profile
511 tbr_get(ifq, profile)
513 struct tb_profile *profile;
515 struct tb_regulator *tbr;
518 if ((tbr = ifq->altq_tbr) == NULL) {
523 (u_int)TBR_UNSCALE(tbr->tbr_rate * 8 * machclk_freq);
524 profile->depth = (u_int)TBR_UNSCALE(tbr->tbr_depth);
531 * attach a discipline to the interface. if one already exists, it is
533 * Locking is done in the discipline specific attach functions. Basically
534 * they call back to altq_attach which takes care of the attach and locking.
537 altq_pfattach(struct pf_altq *a)
541 switch (a->scheduler) {
546 error = cbq_pfattach(a);
551 error = priq_pfattach(a);
556 error = hfsc_pfattach(a);
567 * detach a discipline from the interface.
568 * it is possible that the discipline was already overridden by another
572 altq_pfdetach(struct pf_altq *a)
577 if ((ifp = ifunit(a->ifname)) == NULL)
580 /* if this discipline is no longer referenced, just return */
581 /* read unlocked from if_snd */
582 if (a->altq_disc == NULL || a->altq_disc != ifp->if_snd.altq_disc)
590 /* read unlocked from if_snd, _disable and _detach take care */
591 if (ALTQ_IS_ENABLED(&ifp->if_snd))
592 error = altq_disable(&ifp->if_snd);
594 error = altq_detach(&ifp->if_snd);
601 * add a discipline or a queue
602 * Locking is done in the discipline specific functions with regards to
603 * malloc with WAITOK, also it is not yet clear which lock to use.
606 altq_add(struct pf_altq *a)
610 if (a->qname[0] != 0)
611 return (altq_add_queue(a));
613 if (machclk_freq == 0)
615 if (machclk_freq == 0)
616 panic("altq_add: no cpu clock");
618 switch (a->scheduler) {
621 error = cbq_add_altq(a);
626 error = priq_add_altq(a);
631 error = hfsc_add_altq(a);
642 * remove a discipline or a queue
643 * It is yet unclear what lock to use to protect this operation, the
644 * discipline specific functions will determine and grab it
647 altq_remove(struct pf_altq *a)
651 if (a->qname[0] != 0)
652 return (altq_remove_queue(a));
654 switch (a->scheduler) {
657 error = cbq_remove_altq(a);
662 error = priq_remove_altq(a);
667 error = hfsc_remove_altq(a);
678 * add a queue to the discipline
679 * It is yet unclear what lock to use to protect this operation, the
680 * discipline specific functions will determine and grab it
683 altq_add_queue(struct pf_altq *a)
687 switch (a->scheduler) {
690 error = cbq_add_queue(a);
695 error = priq_add_queue(a);
700 error = hfsc_add_queue(a);
711 * remove a queue from the discipline
712 * It is yet unclear what lock to use to protect this operation, the
713 * discipline specific functions will determine and grab it
716 altq_remove_queue(struct pf_altq *a)
720 switch (a->scheduler) {
723 error = cbq_remove_queue(a);
728 error = priq_remove_queue(a);
733 error = hfsc_remove_queue(a);
744 * get queue statistics
745 * Locking is done in the discipline specific functions with regards to
746 * copyout operations, also it is not yet clear which lock to use.
749 altq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes)
753 switch (a->scheduler) {
756 error = cbq_getqstats(a, ubuf, nbytes);
761 error = priq_getqstats(a, ubuf, nbytes);
766 error = hfsc_getqstats(a, ubuf, nbytes);
777 * read and write diffserv field in IPv4 or IPv6 header
780 read_dsfield(m, pktattr)
782 struct altq_pktattr *pktattr;
785 u_int8_t ds_field = 0;
787 if (pktattr == NULL ||
788 (pktattr->pattr_af != AF_INET && pktattr->pattr_af != AF_INET6))
789 return ((u_int8_t)0);
791 /* verify that pattr_hdr is within the mbuf data */
792 for (m0 = m; m0 != NULL; m0 = m0->m_next)
793 if ((pktattr->pattr_hdr >= m0->m_data) &&
794 (pktattr->pattr_hdr < m0->m_data + m0->m_len))
797 /* ick, pattr_hdr is stale */
798 pktattr->pattr_af = AF_UNSPEC;
800 printf("read_dsfield: can't locate header!\n");
802 return ((u_int8_t)0);
805 if (pktattr->pattr_af == AF_INET) {
806 struct ip *ip = (struct ip *)pktattr->pattr_hdr;
809 return ((u_int8_t)0); /* version mismatch! */
810 ds_field = ip->ip_tos;
813 else if (pktattr->pattr_af == AF_INET6) {
814 struct ip6_hdr *ip6 = (struct ip6_hdr *)pktattr->pattr_hdr;
817 flowlabel = ntohl(ip6->ip6_flow);
818 if ((flowlabel >> 28) != 6)
819 return ((u_int8_t)0); /* version mismatch! */
820 ds_field = (flowlabel >> 20) & 0xff;
827 write_dsfield(struct mbuf *m, struct altq_pktattr *pktattr, u_int8_t dsfield)
831 if (pktattr == NULL ||
832 (pktattr->pattr_af != AF_INET && pktattr->pattr_af != AF_INET6))
835 /* verify that pattr_hdr is within the mbuf data */
836 for (m0 = m; m0 != NULL; m0 = m0->m_next)
837 if ((pktattr->pattr_hdr >= m0->m_data) &&
838 (pktattr->pattr_hdr < m0->m_data + m0->m_len))
841 /* ick, pattr_hdr is stale */
842 pktattr->pattr_af = AF_UNSPEC;
844 printf("write_dsfield: can't locate header!\n");
849 if (pktattr->pattr_af == AF_INET) {
850 struct ip *ip = (struct ip *)pktattr->pattr_hdr;
855 return; /* version mismatch! */
857 dsfield |= old & 3; /* leave CU bits */
860 ip->ip_tos = dsfield;
862 * update checksum (from RFC1624)
863 * HC' = ~(~HC + ~m + m')
865 sum = ~ntohs(ip->ip_sum) & 0xffff;
866 sum += 0xff00 + (~old & 0xff) + dsfield;
867 sum = (sum >> 16) + (sum & 0xffff);
868 sum += (sum >> 16); /* add carry */
870 ip->ip_sum = htons(~sum & 0xffff);
873 else if (pktattr->pattr_af == AF_INET6) {
874 struct ip6_hdr *ip6 = (struct ip6_hdr *)pktattr->pattr_hdr;
877 flowlabel = ntohl(ip6->ip6_flow);
878 if ((flowlabel >> 28) != 6)
879 return; /* version mismatch! */
880 flowlabel = (flowlabel & 0xf03fffff) | (dsfield << 20);
881 ip6->ip6_flow = htonl(flowlabel);
889 * high resolution clock support taking advantage of a machine dependent
890 * high resolution time counter (e.g., timestamp counter of intel pentium).
892 * - 64-bit-long monotonically-increasing counter
893 * - frequency range is 100M-4GHz (CPU speed)
895 /* if pcc is not available or disabled, emulate 256MHz using microtime() */
896 #define MACHCLK_SHIFT 8
899 u_int32_t machclk_freq;
900 u_int32_t machclk_per_tick;
904 extern u_int32_t cycles_per_sec; /* alpha cpu clock frequency */
905 #elif defined(__NetBSD__) || defined(__OpenBSD__)
906 extern u_int64_t cycles_per_usec; /* alpha cpu clock frequency */
908 #endif /* __alpha__ */
909 #if defined(__i386__) && defined(__NetBSD__)
910 extern u_int64_t cpu_tsc_freq;
911 #endif /* __alpha__ */
913 #if (__FreeBSD_version >= 700035)
914 /* Update TSC freq with the value indicated by the caller. */
916 tsc_freq_changed(void *arg, const struct cf_level *level, int status)
918 /* If there was an error during the transition, don't do anything. */
922 #if (__FreeBSD_version >= 701102) && (defined(__amd64__) || defined(__i386__))
923 /* If TSC is P-state invariant, don't do anything. */
924 if (tsc_is_invariant)
928 /* Total setting for this level gives the new frequency in MHz. */
931 EVENTHANDLER_DEFINE(cpufreq_post_change, tsc_freq_changed, NULL,
932 EVENTHANDLER_PRI_LAST);
933 #endif /* __FreeBSD_version >= 700035 */
936 init_machclk_setup(void)
938 #if (__FreeBSD_version >= 600000)
939 callout_init(&tbr_callout, 0);
944 #if (!defined(__i386__) && !defined(__alpha__)) || defined(ALTQ_NOPCC)
947 #if defined(__FreeBSD__) && defined(SMP)
950 #if defined(__NetBSD__) && defined(MULTIPROCESSOR)
954 /* check if TSC is available */
955 if (machclk_usepcc == 1 && ((cpu_feature & CPUID_TSC) == 0 ||
966 /* Call one-time initialization function. */
968 init_machclk_setup();
972 if (machclk_usepcc == 0) {
973 /* emulate 256MHz using microtime() */
974 machclk_freq = 1000000 << MACHCLK_SHIFT;
975 machclk_per_tick = machclk_freq / hz;
977 printf("altq: emulate %uHz cpu clock\n", machclk_freq);
983 * if the clock frequency (of Pentium TSC or Alpha PCC) is
984 * accessible, just use it.
988 #if (__FreeBSD_version > 300000)
989 machclk_freq = tsc_freq;
991 machclk_freq = i586_ctr_freq;
993 #elif defined(__NetBSD__)
994 machclk_freq = (u_int32_t)cpu_tsc_freq;
995 #elif defined(__OpenBSD__) && (defined(I586_CPU) || defined(I686_CPU))
996 machclk_freq = pentium_mhz * 1000000;
998 #elif defined(__alpha__)
1000 machclk_freq = cycles_per_sec;
1001 #elif defined(__NetBSD__) || defined(__OpenBSD__)
1002 machclk_freq = (u_int32_t)(cycles_per_usec * 1000000);
1004 #endif /* __alpha__ */
1007 * if we don't know the clock frequency, measure it.
1009 if (machclk_freq == 0) {
1011 struct timeval tv_start, tv_end;
1012 u_int64_t start, end, diff;
1015 microtime(&tv_start);
1016 start = read_machclk();
1017 timo = hz; /* 1 sec */
1018 (void)tsleep(&wait, PWAIT | PCATCH, "init_machclk", timo);
1020 end = read_machclk();
1021 diff = (u_int64_t)(tv_end.tv_sec - tv_start.tv_sec) * 1000000
1022 + tv_end.tv_usec - tv_start.tv_usec;
1024 machclk_freq = (u_int)((end - start) * 1000000 / diff);
1027 machclk_per_tick = machclk_freq / hz;
1030 printf("altq: CPU clock: %uHz\n", machclk_freq);
1034 #if defined(__OpenBSD__) && defined(__i386__)
1035 static __inline u_int64_t
1039 __asm __volatile(".byte 0x0f, 0x31" : "=A" (rv));
1042 #endif /* __OpenBSD__ && __i386__ */
1049 if (machclk_usepcc) {
1050 #if defined(__i386__)
1052 #elif defined(__alpha__)
1053 static u_int32_t last_pcc, upper;
1057 * for alpha, make a 64bit counter value out of the 32bit
1058 * alpha processor cycle counter.
1059 * read_machclk must be called within a half of its
1060 * wrap-around cycle (about 5 sec for 400MHz cpu) to properly
1061 * detect a counter wrap-around.
1062 * tbr_timeout calls read_machclk once a second.
1064 pcc = (u_int32_t)alpha_rpcc();
1065 if (pcc <= last_pcc)
1068 val = ((u_int64_t)upper << 32) + pcc;
1070 panic("read_machclk");
1076 val = (((u_int64_t)(tv.tv_sec - boottime.tv_sec) * 1000000
1077 + tv.tv_usec) << MACHCLK_SHIFT);
1082 #ifdef ALTQ3_CLFIER_COMPAT
1085 #define IPPROTO_ESP 50 /* encapsulating security payload */
1088 #define IPPROTO_AH 51 /* authentication header */
1092 * extract flow information from a given packet.
1093 * filt_mask shows flowinfo fields required.
1094 * we assume the ip header is in one mbuf, and addresses and ports are
1095 * in network byte order.
1098 altq_extractflow(m, af, flow, filt_bmask)
1101 struct flowinfo *flow;
1102 u_int32_t filt_bmask;
1107 struct flowinfo_in *fin;
1110 ip = mtod(m, struct ip *);
1115 fin = (struct flowinfo_in *)flow;
1116 fin->fi_len = sizeof(struct flowinfo_in);
1117 fin->fi_family = AF_INET;
1119 fin->fi_proto = ip->ip_p;
1120 fin->fi_tos = ip->ip_tos;
1122 fin->fi_src.s_addr = ip->ip_src.s_addr;
1123 fin->fi_dst.s_addr = ip->ip_dst.s_addr;
1125 if (filt_bmask & FIMB4_PORTS)
1126 /* if port info is required, extract port numbers */
1127 extract_ports4(m, ip, fin);
1138 struct flowinfo_in6 *fin6;
1139 struct ip6_hdr *ip6;
1141 ip6 = mtod(m, struct ip6_hdr *);
1142 /* should we check the ip version? */
1144 fin6 = (struct flowinfo_in6 *)flow;
1145 fin6->fi6_len = sizeof(struct flowinfo_in6);
1146 fin6->fi6_family = AF_INET6;
1148 fin6->fi6_proto = ip6->ip6_nxt;
1149 fin6->fi6_tclass = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
1151 fin6->fi6_flowlabel = ip6->ip6_flow & htonl(0x000fffff);
1152 fin6->fi6_src = ip6->ip6_src;
1153 fin6->fi6_dst = ip6->ip6_dst;
1155 if ((filt_bmask & FIMB6_PORTS) ||
1156 ((filt_bmask & FIMB6_PROTO)
1157 && ip6->ip6_nxt > IPPROTO_IPV6))
1159 * if port info is required, or proto is required
1160 * but there are option headers, extract port
1161 * and protocol numbers.
1163 extract_ports6(m, ip6, fin6);
1165 fin6->fi6_sport = 0;
1166 fin6->fi6_dport = 0;
1178 flow->fi_len = sizeof(struct flowinfo);
1179 flow->fi_family = AF_UNSPEC;
1184 * helper routine to extract port numbers
1186 /* structure for ipsec and ipv6 option header template */
1188 u_int8_t opt6_nxt; /* next header */
1189 u_int8_t opt6_hlen; /* header extension length */
1191 u_int32_t ah_spi; /* security parameter index
1192 for authentication header */
1196 * extract port numbers from a ipv4 packet.
1199 extract_ports4(m, ip, fin)
1202 struct flowinfo_in *fin;
1213 ip_off = ntohs(ip->ip_off);
1214 /* if it is a fragment, try cached fragment info */
1215 if (ip_off & IP_OFFMASK) {
1216 ip4f_lookup(ip, fin);
1220 /* locate the mbuf containing the protocol header */
1221 for (m0 = m; m0 != NULL; m0 = m0->m_next)
1222 if (((caddr_t)ip >= m0->m_data) &&
1223 ((caddr_t)ip < m0->m_data + m0->m_len))
1227 printf("extract_ports4: can't locate header! ip=%p\n", ip);
1231 off = ((caddr_t)ip - m0->m_data) + (ip->ip_hl << 2);
1237 while (off >= m0->m_len) {
1241 return (0); /* bogus ip_hl! */
1243 if (m0->m_len < off + 4)
1251 udp = (struct udphdr *)(mtod(m0, caddr_t) + off);
1252 fin->fi_sport = udp->uh_sport;
1253 fin->fi_dport = udp->uh_dport;
1254 fin->fi_proto = proto;
1260 if (fin->fi_gpi == 0){
1263 gpi = (u_int32_t *)(mtod(m0, caddr_t) + off);
1266 fin->fi_proto = proto;
1270 /* get next header and header length */
1273 opt6 = (struct _opt6 *)(mtod(m0, caddr_t) + off);
1274 proto = opt6->opt6_nxt;
1275 off += 8 + (opt6->opt6_hlen * 4);
1276 if (fin->fi_gpi == 0 && m0->m_len >= off + 8)
1277 fin->fi_gpi = opt6->ah_spi;
1279 /* goto the next header */
1281 #endif /* ALTQ_IPSEC */
1284 fin->fi_proto = proto;
1288 /* if this is a first fragment, cache it. */
1290 ip4f_cache(ip, fin);
1297 extract_ports6(m, ip6, fin6)
1299 struct ip6_hdr *ip6;
1300 struct flowinfo_in6 *fin6;
1307 fin6->fi6_sport = 0;
1308 fin6->fi6_dport = 0;
1310 /* locate the mbuf containing the protocol header */
1311 for (m0 = m; m0 != NULL; m0 = m0->m_next)
1312 if (((caddr_t)ip6 >= m0->m_data) &&
1313 ((caddr_t)ip6 < m0->m_data + m0->m_len))
1317 printf("extract_ports6: can't locate header! ip6=%p\n", ip6);
1321 off = ((caddr_t)ip6 - m0->m_data) + sizeof(struct ip6_hdr);
1323 proto = ip6->ip6_nxt;
1325 while (off >= m0->m_len) {
1331 if (m0->m_len < off + 4)
1339 udp = (struct udphdr *)(mtod(m0, caddr_t) + off);
1340 fin6->fi6_sport = udp->uh_sport;
1341 fin6->fi6_dport = udp->uh_dport;
1342 fin6->fi6_proto = proto;
1347 if (fin6->fi6_gpi == 0) {
1350 gpi = (u_int32_t *)(mtod(m0, caddr_t) + off);
1351 fin6->fi6_gpi = *gpi;
1353 fin6->fi6_proto = proto;
1357 /* get next header and header length */
1360 opt6 = (struct _opt6 *)(mtod(m0, caddr_t) + off);
1361 if (fin6->fi6_gpi == 0 && m0->m_len >= off + 8)
1362 fin6->fi6_gpi = opt6->ah_spi;
1363 proto = opt6->opt6_nxt;
1364 off += 8 + (opt6->opt6_hlen * 4);
1365 /* goto the next header */
1369 case IPPROTO_HOPOPTS:
1370 case IPPROTO_ROUTING:
1371 case IPPROTO_DSTOPTS: {
1372 /* get next header and header length */
1375 opt6 = (struct _opt6 *)(mtod(m0, caddr_t) + off);
1376 proto = opt6->opt6_nxt;
1377 off += (opt6->opt6_hlen + 1) * 8;
1378 /* goto the next header */
1382 case IPPROTO_FRAGMENT:
1383 /* ipv6 fragmentations are not supported yet */
1385 fin6->fi6_proto = proto;
1394 * altq common classifier
1397 acc_add_filter(classifier, filter, class, phandle)
1398 struct acc_classifier *classifier;
1399 struct flow_filter *filter;
1403 struct acc_filter *afp, *prev, *tmp;
1407 if (filter->ff_flow.fi_family != AF_INET &&
1408 filter->ff_flow.fi_family != AF_INET6)
1411 if (filter->ff_flow.fi_family != AF_INET)
1415 afp = malloc(sizeof(struct acc_filter),
1416 M_DEVBUF, M_WAITOK);
1419 bzero(afp, sizeof(struct acc_filter));
1421 afp->f_filter = *filter;
1422 afp->f_class = class;
1424 i = ACC_WILDCARD_INDEX;
1425 if (filter->ff_flow.fi_family == AF_INET) {
1426 struct flow_filter *filter4 = &afp->f_filter;
1429 * if address is 0, it's a wildcard. if address mask
1430 * isn't set, use full mask.
1432 if (filter4->ff_flow.fi_dst.s_addr == 0)
1433 filter4->ff_mask.mask_dst.s_addr = 0;
1434 else if (filter4->ff_mask.mask_dst.s_addr == 0)
1435 filter4->ff_mask.mask_dst.s_addr = 0xffffffff;
1436 if (filter4->ff_flow.fi_src.s_addr == 0)
1437 filter4->ff_mask.mask_src.s_addr = 0;
1438 else if (filter4->ff_mask.mask_src.s_addr == 0)
1439 filter4->ff_mask.mask_src.s_addr = 0xffffffff;
1441 /* clear extra bits in addresses */
1442 filter4->ff_flow.fi_dst.s_addr &=
1443 filter4->ff_mask.mask_dst.s_addr;
1444 filter4->ff_flow.fi_src.s_addr &=
1445 filter4->ff_mask.mask_src.s_addr;
1448 * if dst address is a wildcard, use hash-entry
1449 * ACC_WILDCARD_INDEX.
1451 if (filter4->ff_mask.mask_dst.s_addr != 0xffffffff)
1452 i = ACC_WILDCARD_INDEX;
1454 i = ACC_GET_HASH_INDEX(filter4->ff_flow.fi_dst.s_addr);
1457 else if (filter->ff_flow.fi_family == AF_INET6) {
1458 struct flow_filter6 *filter6 =
1459 (struct flow_filter6 *)&afp->f_filter;
1460 #ifndef IN6MASK0 /* taken from kame ipv6 */
1461 #define IN6MASK0 {{{ 0, 0, 0, 0 }}}
1462 #define IN6MASK128 {{{ 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }}}
1463 const struct in6_addr in6mask0 = IN6MASK0;
1464 const struct in6_addr in6mask128 = IN6MASK128;
1467 if (IN6_IS_ADDR_UNSPECIFIED(&filter6->ff_flow6.fi6_dst))
1468 filter6->ff_mask6.mask6_dst = in6mask0;
1469 else if (IN6_IS_ADDR_UNSPECIFIED(&filter6->ff_mask6.mask6_dst))
1470 filter6->ff_mask6.mask6_dst = in6mask128;
1471 if (IN6_IS_ADDR_UNSPECIFIED(&filter6->ff_flow6.fi6_src))
1472 filter6->ff_mask6.mask6_src = in6mask0;
1473 else if (IN6_IS_ADDR_UNSPECIFIED(&filter6->ff_mask6.mask6_src))
1474 filter6->ff_mask6.mask6_src = in6mask128;
1476 /* clear extra bits in addresses */
1477 for (i = 0; i < 16; i++)
1478 filter6->ff_flow6.fi6_dst.s6_addr[i] &=
1479 filter6->ff_mask6.mask6_dst.s6_addr[i];
1480 for (i = 0; i < 16; i++)
1481 filter6->ff_flow6.fi6_src.s6_addr[i] &=
1482 filter6->ff_mask6.mask6_src.s6_addr[i];
1484 if (filter6->ff_flow6.fi6_flowlabel == 0)
1485 i = ACC_WILDCARD_INDEX;
1487 i = ACC_GET_HASH_INDEX(filter6->ff_flow6.fi6_flowlabel);
1491 afp->f_handle = get_filt_handle(classifier, i);
1493 /* update filter bitmask */
1494 afp->f_fbmask = filt2fibmask(filter);
1495 classifier->acc_fbmask |= afp->f_fbmask;
1498 * add this filter to the filter list.
1499 * filters are ordered from the highest rule number.
1507 LIST_FOREACH(tmp, &classifier->acc_filters[i], f_chain) {
1508 if (tmp->f_filter.ff_ruleno > afp->f_filter.ff_ruleno)
1514 LIST_INSERT_HEAD(&classifier->acc_filters[i], afp, f_chain);
1516 LIST_INSERT_AFTER(prev, afp, f_chain);
1519 *phandle = afp->f_handle;
1524 acc_delete_filter(classifier, handle)
1525 struct acc_classifier *classifier;
1528 struct acc_filter *afp;
1531 if ((afp = filth_to_filtp(classifier, handle)) == NULL)
1539 LIST_REMOVE(afp, f_chain);
1542 free(afp, M_DEVBUF);
1544 /* todo: update filt_bmask */
1550 * delete filters referencing to the specified class.
1551 * if the all flag is not 0, delete all the filters.
1554 acc_discard_filters(classifier, class, all)
1555 struct acc_classifier *classifier;
1559 struct acc_filter *afp;
1567 for (i = 0; i < ACC_FILTER_TABLESIZE; i++) {
1569 LIST_FOREACH(afp, &classifier->acc_filters[i], f_chain)
1570 if (all || afp->f_class == class) {
1571 LIST_REMOVE(afp, f_chain);
1572 free(afp, M_DEVBUF);
1573 /* start again from the head */
1576 } while (afp != NULL);
1581 classifier->acc_fbmask = 0;
1587 acc_classify(clfier, m, af)
1592 struct acc_classifier *classifier;
1593 struct flowinfo flow;
1594 struct acc_filter *afp;
1597 classifier = (struct acc_classifier *)clfier;
1598 altq_extractflow(m, af, &flow, classifier->acc_fbmask);
1600 if (flow.fi_family == AF_INET) {
1601 struct flowinfo_in *fp = (struct flowinfo_in *)&flow;
1603 if ((classifier->acc_fbmask & FIMB4_ALL) == FIMB4_TOS) {
1604 /* only tos is used */
1606 &classifier->acc_filters[ACC_WILDCARD_INDEX],
1608 if (apply_tosfilter4(afp->f_fbmask,
1609 &afp->f_filter, fp))
1610 /* filter matched */
1611 return (afp->f_class);
1612 } else if ((classifier->acc_fbmask &
1613 (~(FIMB4_PROTO|FIMB4_SPORT|FIMB4_DPORT) & FIMB4_ALL))
1615 /* only proto and ports are used */
1617 &classifier->acc_filters[ACC_WILDCARD_INDEX],
1619 if (apply_ppfilter4(afp->f_fbmask,
1620 &afp->f_filter, fp))
1621 /* filter matched */
1622 return (afp->f_class);
1624 /* get the filter hash entry from its dest address */
1625 i = ACC_GET_HASH_INDEX(fp->fi_dst.s_addr);
1628 * go through this loop twice. first for dst
1629 * hash, second for wildcards.
1631 LIST_FOREACH(afp, &classifier->acc_filters[i],
1633 if (apply_filter4(afp->f_fbmask,
1634 &afp->f_filter, fp))
1635 /* filter matched */
1636 return (afp->f_class);
1639 * check again for filters with a dst addr
1641 * (daddr == 0 || dmask != 0xffffffff).
1643 if (i != ACC_WILDCARD_INDEX)
1644 i = ACC_WILDCARD_INDEX;
1651 else if (flow.fi_family == AF_INET6) {
1652 struct flowinfo_in6 *fp6 = (struct flowinfo_in6 *)&flow;
1654 /* get the filter hash entry from its flow ID */
1655 if (fp6->fi6_flowlabel != 0)
1656 i = ACC_GET_HASH_INDEX(fp6->fi6_flowlabel);
1658 /* flowlable can be zero */
1659 i = ACC_WILDCARD_INDEX;
1661 /* go through this loop twice. first for flow hash, second
1664 LIST_FOREACH(afp, &classifier->acc_filters[i], f_chain)
1665 if (apply_filter6(afp->f_fbmask,
1666 (struct flow_filter6 *)&afp->f_filter,
1668 /* filter matched */
1669 return (afp->f_class);
1672 * check again for filters with a wildcard.
1674 if (i != ACC_WILDCARD_INDEX)
1675 i = ACC_WILDCARD_INDEX;
1682 /* no filter matched */
1687 apply_filter4(fbmask, filt, pkt)
1689 struct flow_filter *filt;
1690 struct flowinfo_in *pkt;
1692 if (filt->ff_flow.fi_family != AF_INET)
1694 if ((fbmask & FIMB4_SPORT) && filt->ff_flow.fi_sport != pkt->fi_sport)
1696 if ((fbmask & FIMB4_DPORT) && filt->ff_flow.fi_dport != pkt->fi_dport)
1698 if ((fbmask & FIMB4_DADDR) &&
1699 filt->ff_flow.fi_dst.s_addr !=
1700 (pkt->fi_dst.s_addr & filt->ff_mask.mask_dst.s_addr))
1702 if ((fbmask & FIMB4_SADDR) &&
1703 filt->ff_flow.fi_src.s_addr !=
1704 (pkt->fi_src.s_addr & filt->ff_mask.mask_src.s_addr))
1706 if ((fbmask & FIMB4_PROTO) && filt->ff_flow.fi_proto != pkt->fi_proto)
1708 if ((fbmask & FIMB4_TOS) && filt->ff_flow.fi_tos !=
1709 (pkt->fi_tos & filt->ff_mask.mask_tos))
1711 if ((fbmask & FIMB4_GPI) && filt->ff_flow.fi_gpi != (pkt->fi_gpi))
1718 * filter matching function optimized for a common case that checks
1719 * only protocol and port numbers
1722 apply_ppfilter4(fbmask, filt, pkt)
1724 struct flow_filter *filt;
1725 struct flowinfo_in *pkt;
1727 if (filt->ff_flow.fi_family != AF_INET)
1729 if ((fbmask & FIMB4_SPORT) && filt->ff_flow.fi_sport != pkt->fi_sport)
1731 if ((fbmask & FIMB4_DPORT) && filt->ff_flow.fi_dport != pkt->fi_dport)
1733 if ((fbmask & FIMB4_PROTO) && filt->ff_flow.fi_proto != pkt->fi_proto)
1740 * filter matching function only for tos field.
1743 apply_tosfilter4(fbmask, filt, pkt)
1745 struct flow_filter *filt;
1746 struct flowinfo_in *pkt;
1748 if (filt->ff_flow.fi_family != AF_INET)
1750 if ((fbmask & FIMB4_TOS) && filt->ff_flow.fi_tos !=
1751 (pkt->fi_tos & filt->ff_mask.mask_tos))
1759 apply_filter6(fbmask, filt, pkt)
1761 struct flow_filter6 *filt;
1762 struct flowinfo_in6 *pkt;
1766 if (filt->ff_flow6.fi6_family != AF_INET6)
1768 if ((fbmask & FIMB6_FLABEL) &&
1769 filt->ff_flow6.fi6_flowlabel != pkt->fi6_flowlabel)
1771 if ((fbmask & FIMB6_PROTO) &&
1772 filt->ff_flow6.fi6_proto != pkt->fi6_proto)
1774 if ((fbmask & FIMB6_SPORT) &&
1775 filt->ff_flow6.fi6_sport != pkt->fi6_sport)
1777 if ((fbmask & FIMB6_DPORT) &&
1778 filt->ff_flow6.fi6_dport != pkt->fi6_dport)
1780 if (fbmask & FIMB6_SADDR) {
1781 for (i = 0; i < 4; i++)
1782 if (filt->ff_flow6.fi6_src.s6_addr32[i] !=
1783 (pkt->fi6_src.s6_addr32[i] &
1784 filt->ff_mask6.mask6_src.s6_addr32[i]))
1787 if (fbmask & FIMB6_DADDR) {
1788 for (i = 0; i < 4; i++)
1789 if (filt->ff_flow6.fi6_dst.s6_addr32[i] !=
1790 (pkt->fi6_dst.s6_addr32[i] &
1791 filt->ff_mask6.mask6_dst.s6_addr32[i]))
1794 if ((fbmask & FIMB6_TCLASS) &&
1795 filt->ff_flow6.fi6_tclass !=
1796 (pkt->fi6_tclass & filt->ff_mask6.mask6_tclass))
1798 if ((fbmask & FIMB6_GPI) &&
1799 filt->ff_flow6.fi6_gpi != pkt->fi6_gpi)
1808 * bit 20-28: index to the filter hash table
1809 * bit 0-19: unique id in the hash bucket.
1812 get_filt_handle(classifier, i)
1813 struct acc_classifier *classifier;
1816 static u_long handle_number = 1;
1818 struct acc_filter *afp;
1821 handle = handle_number++ & 0x000fffff;
1823 if (LIST_EMPTY(&classifier->acc_filters[i]))
1826 LIST_FOREACH(afp, &classifier->acc_filters[i], f_chain)
1827 if ((afp->f_handle & 0x000fffff) == handle)
1831 /* this handle is already used, try again */
1834 return ((i << 20) | handle);
1837 /* convert filter handle to filter pointer */
1838 static struct acc_filter *
1839 filth_to_filtp(classifier, handle)
1840 struct acc_classifier *classifier;
1843 struct acc_filter *afp;
1846 i = ACC_GET_HINDEX(handle);
1848 LIST_FOREACH(afp, &classifier->acc_filters[i], f_chain)
1849 if (afp->f_handle == handle)
1855 /* create flowinfo bitmask */
1858 struct flow_filter *filt;
1862 struct flow_filter6 *filt6;
1865 switch (filt->ff_flow.fi_family) {
1867 if (filt->ff_flow.fi_proto != 0)
1868 mask |= FIMB4_PROTO;
1869 if (filt->ff_flow.fi_tos != 0)
1871 if (filt->ff_flow.fi_dst.s_addr != 0)
1872 mask |= FIMB4_DADDR;
1873 if (filt->ff_flow.fi_src.s_addr != 0)
1874 mask |= FIMB4_SADDR;
1875 if (filt->ff_flow.fi_sport != 0)
1876 mask |= FIMB4_SPORT;
1877 if (filt->ff_flow.fi_dport != 0)
1878 mask |= FIMB4_DPORT;
1879 if (filt->ff_flow.fi_gpi != 0)
1884 filt6 = (struct flow_filter6 *)filt;
1886 if (filt6->ff_flow6.fi6_proto != 0)
1887 mask |= FIMB6_PROTO;
1888 if (filt6->ff_flow6.fi6_tclass != 0)
1889 mask |= FIMB6_TCLASS;
1890 if (!IN6_IS_ADDR_UNSPECIFIED(&filt6->ff_flow6.fi6_dst))
1891 mask |= FIMB6_DADDR;
1892 if (!IN6_IS_ADDR_UNSPECIFIED(&filt6->ff_flow6.fi6_src))
1893 mask |= FIMB6_SADDR;
1894 if (filt6->ff_flow6.fi6_sport != 0)
1895 mask |= FIMB6_SPORT;
1896 if (filt6->ff_flow6.fi6_dport != 0)
1897 mask |= FIMB6_DPORT;
1898 if (filt6->ff_flow6.fi6_gpi != 0)
1900 if (filt6->ff_flow6.fi6_flowlabel != 0)
1901 mask |= FIMB6_FLABEL;
1910 * helper functions to handle IPv4 fragments.
1911 * currently only in-sequence fragments are handled.
1912 * - fragment info is cached in a LRU list.
1913 * - when a first fragment is found, cache its flow info.
1914 * - when a non-first fragment is found, lookup the cache.
1918 TAILQ_ENTRY(ip4_frag) ip4f_chain;
1921 struct flowinfo_in ip4f_info;
1924 static TAILQ_HEAD(ip4f_list, ip4_frag) ip4f_list; /* IPv4 fragment cache */
1926 #define IP4F_TABSIZE 16 /* IPv4 fragment cache size */
1932 struct flowinfo_in *fin;
1934 struct ip4_frag *fp;
1936 if (TAILQ_EMPTY(&ip4f_list)) {
1937 /* first time call, allocate fragment cache entries. */
1938 if (ip4f_init() < 0)
1939 /* allocation failed! */
1944 fp->ip4f_id = ip->ip_id;
1945 fp->ip4f_info.fi_proto = ip->ip_p;
1946 fp->ip4f_info.fi_src.s_addr = ip->ip_src.s_addr;
1947 fp->ip4f_info.fi_dst.s_addr = ip->ip_dst.s_addr;
1949 /* save port numbers */
1950 fp->ip4f_info.fi_sport = fin->fi_sport;
1951 fp->ip4f_info.fi_dport = fin->fi_dport;
1952 fp->ip4f_info.fi_gpi = fin->fi_gpi;
1956 ip4f_lookup(ip, fin)
1958 struct flowinfo_in *fin;
1960 struct ip4_frag *fp;
1962 for (fp = TAILQ_FIRST(&ip4f_list); fp != NULL && fp->ip4f_valid;
1963 fp = TAILQ_NEXT(fp, ip4f_chain))
1964 if (ip->ip_id == fp->ip4f_id &&
1965 ip->ip_src.s_addr == fp->ip4f_info.fi_src.s_addr &&
1966 ip->ip_dst.s_addr == fp->ip4f_info.fi_dst.s_addr &&
1967 ip->ip_p == fp->ip4f_info.fi_proto) {
1969 /* found the matching entry */
1970 fin->fi_sport = fp->ip4f_info.fi_sport;
1971 fin->fi_dport = fp->ip4f_info.fi_dport;
1972 fin->fi_gpi = fp->ip4f_info.fi_gpi;
1974 if ((ntohs(ip->ip_off) & IP_MF) == 0)
1975 /* this is the last fragment,
1976 release the entry. */
1982 /* no matching entry found */
1989 struct ip4_frag *fp;
1992 TAILQ_INIT(&ip4f_list);
1993 for (i=0; i<IP4F_TABSIZE; i++) {
1994 fp = malloc(sizeof(struct ip4_frag),
1995 M_DEVBUF, M_NOWAIT);
1997 printf("ip4f_init: can't alloc %dth entry!\n", i);
2003 TAILQ_INSERT_TAIL(&ip4f_list, fp, ip4f_chain);
2008 static struct ip4_frag *
2011 struct ip4_frag *fp;
2013 /* reclaim an entry at the tail, put it at the head */
2014 fp = TAILQ_LAST(&ip4f_list, ip4f_list);
2015 TAILQ_REMOVE(&ip4f_list, fp, ip4f_chain);
2017 TAILQ_INSERT_HEAD(&ip4f_list, fp, ip4f_chain);
2023 struct ip4_frag *fp;
2025 TAILQ_REMOVE(&ip4f_list, fp, ip4f_chain);
2027 TAILQ_INSERT_TAIL(&ip4f_list, fp, ip4f_chain);
2030 #endif /* ALTQ3_CLFIER_COMPAT */