kernel: Make SMP support default (and non-optional).
[dragonfly.git] / sys / netinet / ip_flow.c
CommitLineData
984263bc
MD
1/*-
2 * Copyright (c) 1998 The NetBSD Foundation, Inc.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by the 3am Software Foundry ("3am"). It was developed by Matt Thomas.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the NetBSD
19 * Foundation, Inc. and its contributors.
20 * 4. Neither the name of The NetBSD Foundation nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 * $FreeBSD: src/sys/netinet/ip_flow.c,v 1.9.2.2 2001/11/04 17:35:31 luigi Exp $
37 */
38
39#include <sys/param.h>
775a6411 40#include <sys/kernel.h>
984263bc
MD
41#include <sys/malloc.h>
42#include <sys/mbuf.h>
43#include <sys/protosw.h>
44#include <sys/socket.h>
984263bc 45#include <sys/sysctl.h>
1cae611f 46#include <sys/thread2.h>
8eb08577 47#include <sys/in_cksum.h>
984263bc 48
775a6411
SZ
49#include <machine/smp.h>
50
984263bc 51#include <net/if.h>
7d01720a 52#include <net/if_var.h>
984263bc 53#include <net/route.h>
775a6411
SZ
54#include <net/netisr.h>
55#include <net/netmsg2.h>
984263bc
MD
56
57#include <netinet/in.h>
984263bc
MD
58#include <netinet/ip.h>
59#include <netinet/in_var.h>
60#include <netinet/ip_var.h>
61#include <netinet/ip_flow.h>
62
63#define IPFLOW_TIMER (5 * PR_SLOWHZ)
64#define IPFLOW_HASHBITS 6 /* should not be a multiple of 8 */
65#define IPFLOW_HASHSIZE (1 << IPFLOW_HASHBITS)
984263bc
MD
66#define IPFLOW_MAX 256
67
775a6411 68#define IPFLOW_RTENTRY_ISDOWN(rt) \
a06d6365
SZ
69 (((rt)->rt_flags & RTF_UP) == 0 || \
70 ((rt)->rt_ifp->if_flags & IFF_UP) == 0)
775a6411 71
7d01720a 72struct netmsg_ipfaddr {
002c1265 73 struct netmsg_base base;
7d01720a
SZ
74 struct in_addr ipf_addr;
75};
76
4639df5f 77struct ipflow {
b9f8c879 78 LIST_ENTRY(ipflow) ipf_hash; /* next ipflow in hash bucket */
a716f015
SZ
79 LIST_ENTRY(ipflow) ipf_list; /* next ipflow in list */
80
4639df5f
SZ
81 struct in_addr ipf_dst; /* destination address */
82 struct in_addr ipf_src; /* source address */
4639df5f 83 uint8_t ipf_tos; /* type-of-service */
a716f015
SZ
84
85 uint8_t ipf_flags; /* see IPFLOW_FLAG_ */
86 uint8_t ipf_pad[2]; /* explicit pad */
87 int ipf_refcnt; /* reference count */
88
4639df5f
SZ
89 struct route ipf_ro; /* associated route entry */
90 u_long ipf_uses; /* number of uses in this period */
91
92 int ipf_timer; /* remaining lifetime of this entry */
93 u_long ipf_dropped; /* ENOBUFS returned by if_output */
94 u_long ipf_errors; /* other errors returned by if_output */
95 u_long ipf_last_uses; /* number of uses in last period */
96};
b9f8c879 97LIST_HEAD(ipflowhead, ipflow);
4639df5f 98
a716f015
SZ
99#define IPFLOW_FLAG_ONLIST 0x1
100
775a6411 101#define ipflow_inuse ipflow_inuse_pcpu[mycpuid]
b9f8c879
SZ
102#define ipflowtable ipflowtable_pcpu[mycpuid]
103#define ipflowlist ipflowlist_pcpu[mycpuid]
104
105static struct ipflowhead ipflowtable_pcpu[MAXCPU][IPFLOW_HASHSIZE];
106static struct ipflowhead ipflowlist_pcpu[MAXCPU];
107static int ipflow_inuse_pcpu[MAXCPU];
002c1265 108static struct netmsg_base ipflow_timo_netmsgs[MAXCPU];
b9f8c879
SZ
109static int ipflow_active = 0;
110
50e42f7f
SZ
111#define IPFLOW_REFCNT_INIT 1
112
113/* ipflow is alive and active */
114#define IPFLOW_IS_ACTIVE(ipf) ((ipf)->ipf_refcnt > IPFLOW_REFCNT_INIT)
115/* ipflow is alive but not active */
116#define IPFLOW_NOT_ACTIVE(ipf) ((ipf)->ipf_refcnt == IPFLOW_REFCNT_INIT)
117
a716f015
SZ
118#define IPFLOW_REF(ipf) \
119do { \
120 KKASSERT((ipf)->ipf_refcnt > 0); \
121 (ipf)->ipf_refcnt++; \
122} while (0)
123
124#define IPFLOW_FREE(ipf) \
125do { \
126 KKASSERT((ipf)->ipf_refcnt > 0); \
127 (ipf)->ipf_refcnt--; \
128 if ((ipf)->ipf_refcnt == 0) \
129 ipflow_free((ipf)); \
130} while (0)
131
b9f8c879
SZ
132#define IPFLOW_INSERT(bucket, ipf) \
133do { \
a716f015
SZ
134 KKASSERT(((ipf)->ipf_flags & IPFLOW_FLAG_ONLIST) == 0); \
135 (ipf)->ipf_flags |= IPFLOW_FLAG_ONLIST; \
b9f8c879
SZ
136 LIST_INSERT_HEAD((bucket), (ipf), ipf_hash); \
137 LIST_INSERT_HEAD(&ipflowlist, (ipf), ipf_list); \
138} while (0)
139
140#define IPFLOW_REMOVE(ipf) \
141do { \
a716f015
SZ
142 KKASSERT((ipf)->ipf_flags & IPFLOW_FLAG_ONLIST); \
143 (ipf)->ipf_flags &= ~IPFLOW_FLAG_ONLIST; \
b9f8c879
SZ
144 LIST_REMOVE((ipf), ipf_hash); \
145 LIST_REMOVE((ipf), ipf_list); \
146} while (0)
775a6411
SZ
147
148SYSCTL_NODE(_net_inet_ip, OID_AUTO, ipflow, CTLFLAG_RW, 0, "ip flow");
984263bc 149SYSCTL_INT(_net_inet_ip, IPCTL_FASTFORWARDING, fastforwarding, CTLFLAG_RW,
10c4b5fc 150 &ipflow_active, 0, "Enable flow-based IP forwarding");
984263bc
MD
151
152static MALLOC_DEFINE(M_IPFLOW, "ip_flow", "IP flow");
153
a716f015
SZ
154static void ipflow_free(struct ipflow *);
155
984263bc 156static unsigned
be23faf1 157ipflow_hash(struct in_addr dst, struct in_addr src, unsigned tos)
984263bc
MD
158{
159 unsigned hash = tos;
160 int idx;
be23faf1 161
984263bc
MD
162 for (idx = 0; idx < 32; idx += IPFLOW_HASHBITS)
163 hash += (dst.s_addr >> (32 - idx)) + (src.s_addr >> idx);
164 return hash & (IPFLOW_HASHSIZE-1);
165}
166
167static struct ipflow *
be23faf1 168ipflow_lookup(const struct ip *ip)
984263bc
MD
169{
170 unsigned hash;
171 struct ipflow *ipf;
172
173 hash = ipflow_hash(ip->ip_dst, ip->ip_src, ip->ip_tos);
b9f8c879 174 LIST_FOREACH(ipf, &ipflowtable[hash], ipf_hash) {
be23faf1
JH
175 if (ip->ip_dst.s_addr == ipf->ipf_dst.s_addr &&
176 ip->ip_src.s_addr == ipf->ipf_src.s_addr &&
177 ip->ip_tos == ipf->ipf_tos)
984263bc 178 break;
984263bc
MD
179 }
180 return ipf;
181}
182
183int
297c8124 184ipflow_fastforward(struct mbuf *m)
984263bc
MD
185{
186 struct ip *ip;
187 struct ipflow *ipf;
188 struct rtentry *rt;
189 struct sockaddr *dst;
10c4b5fc 190 struct ifnet *ifp;
97942f3f 191 int error, iplen;
984263bc
MD
192
193 /*
fab81f84 194 * Are we forwarding packets?
984263bc 195 */
97942f3f 196 if (!ipforwarding || !ipflow_active)
984263bc 197 return 0;
10c4b5fc 198
fab81f84
SZ
199 /*
200 * Was packet received as a link-level multicast or broadcast?
201 * If so, don't try to fast forward..
202 */
203 if (m->m_flags & (M_BCAST | M_MCAST))
204 return 0;
205
c3c96e44 206 /* length checks already done in ip_cpufn() */
97942f3f 207 KASSERT(m->m_len >= sizeof(struct ip), ("IP header not in one mbuf"));
9b161cc2 208 ip = mtod(m, struct ip *);
97942f3f 209
984263bc 210 /*
9b161cc2 211 * IP header with no option and valid version
984263bc 212 */
9b161cc2 213 if (ip->ip_v != IPVERSION || ip->ip_hl != (sizeof(struct ip) >> 2))
984263bc 214 return 0;
10c4b5fc 215
9b161cc2 216 iplen = ntohs(ip->ip_len);
c3c96e44 217 /* length checks already done in ip_cpufn() */
9b161cc2
SZ
218 KASSERT(iplen >= sizeof(struct ip),
219 ("total length less then header length"));
220 KASSERT(m->m_pkthdr.len >= iplen, ("mbuf too short"));
97942f3f 221
984263bc
MD
222 /*
223 * Find a flow.
224 */
10c4b5fc
SZ
225 ipf = ipflow_lookup(ip);
226 if (ipf == NULL)
984263bc
MD
227 return 0;
228
8eb08577
SZ
229 /*
230 * Verify the IP header checksum.
231 */
232 if (m->m_pkthdr.csum_flags & CSUM_IP_CHECKED) {
233 if (!(m->m_pkthdr.csum_flags & CSUM_IP_VALID))
234 return 0;
235 } else {
236 /* Must compute it ourselves. */
237 if (in_cksum_hdr(ip) != 0)
238 return 0;
239 }
240
984263bc
MD
241 /*
242 * Route and interface still up?
243 */
244 rt = ipf->ipf_ro.ro_rt;
775a6411 245 if (IPFLOW_RTENTRY_ISDOWN(rt))
984263bc 246 return 0;
10c4b5fc 247 ifp = rt->rt_ifp;
984263bc
MD
248
249 /*
250 * Packet size OK? TTL?
251 */
10c4b5fc 252 if (m->m_pkthdr.len > ifp->if_mtu || ip->ip_ttl <= IPTTLDEC)
984263bc
MD
253 return 0;
254
8eb08577
SZ
255 /*
256 * Clear any in-bound checksum flags for this packet.
257 */
258 m->m_pkthdr.csum_flags = 0;
259
984263bc
MD
260 /*
261 * Everything checks out and so we can forward this packet.
262 * Modify the TTL and incrementally change the checksum.
8eb08577
SZ
263 *
264 * This method of adding the checksum works on either endian CPU.
265 * If htons() is inlined, all the arithmetic is folded; otherwise
266 * the htons()s are combined by CSE due to the __const__ attribute.
267 *
268 * Don't bother using HW checksumming here -- the incremental
269 * update is pretty fast.
984263bc
MD
270 */
271 ip->ip_ttl -= IPTTLDEC;
8eb08577
SZ
272 if (ip->ip_sum >= (uint16_t)~htons(IPTTLDEC << 8))
273 ip->ip_sum -= ~htons(IPTTLDEC << 8);
be23faf1 274 else
984263bc 275 ip->ip_sum += htons(IPTTLDEC << 8);
984263bc 276
97942f3f
SZ
277 /*
278 * Trim the packet in case it's too long..
279 */
280 if (m->m_pkthdr.len > iplen) {
281 if (m->m_len == m->m_pkthdr.len) {
282 m->m_len = iplen;
283 m->m_pkthdr.len = iplen;
284 } else {
285 m_adj(m, iplen - m->m_pkthdr.len);
286 }
287 }
288
984263bc
MD
289 /*
290 * Send the packet on its way. All we can get back is ENOBUFS
291 */
292 ipf->ipf_uses++;
293 ipf->ipf_timer = IPFLOW_TIMER;
294
295 if (rt->rt_flags & RTF_GATEWAY)
296 dst = rt->rt_gateway;
297 else
298 dst = &ipf->ipf_ro.ro_dst;
10c4b5fc 299
a716f015
SZ
300 /*
301 * Reference count this ipflow, before the possible blocking
302 * ifnet.if_output(), so this ipflow will not be changed or
303 * reaped behind our back.
304 */
305 IPFLOW_REF(ipf);
306
10c4b5fc
SZ
307 error = ifp->if_output(ifp, m, dst, rt);
308 if (error) {
984263bc
MD
309 if (error == ENOBUFS)
310 ipf->ipf_dropped++;
311 else
312 ipf->ipf_errors++;
313 }
a716f015
SZ
314
315 IPFLOW_FREE(ipf);
984263bc
MD
316 return 1;
317}
be23faf1 318
984263bc 319static void
be23faf1 320ipflow_addstats(struct ipflow *ipf)
984263bc
MD
321{
322 ipf->ipf_ro.ro_rt->rt_use += ipf->ipf_uses;
323 ipstat.ips_cantforward += ipf->ipf_errors + ipf->ipf_dropped;
7a87da61 324 ipstat.ips_total += ipf->ipf_uses;
984263bc
MD
325 ipstat.ips_forward += ipf->ipf_uses;
326 ipstat.ips_fastforward += ipf->ipf_uses;
327}
328
329static void
be23faf1 330ipflow_free(struct ipflow *ipf)
984263bc 331{
a716f015
SZ
332 KKASSERT(ipf->ipf_refcnt == 0);
333 KKASSERT((ipf->ipf_flags & IPFLOW_FLAG_ONLIST) == 0);
775a6411
SZ
334
335 KKASSERT(ipflow_inuse > 0);
336 ipflow_inuse--;
10c4b5fc 337
984263bc
MD
338 ipflow_addstats(ipf);
339 RTFREE(ipf->ipf_ro.ro_rt);
efda3bd0 340 kfree(ipf, M_IPFLOW);
984263bc
MD
341}
342
a716f015
SZ
343static void
344ipflow_reset(struct ipflow *ipf)
345{
346 ipflow_addstats(ipf);
347 RTFREE(ipf->ipf_ro.ro_rt);
348 ipf->ipf_uses = ipf->ipf_last_uses = 0;
349 ipf->ipf_errors = ipf->ipf_dropped = 0;
350}
351
984263bc 352static struct ipflow *
be23faf1 353ipflow_reap(void)
984263bc
MD
354{
355 struct ipflow *ipf, *maybe_ipf = NULL;
984263bc 356
b9f8c879 357 LIST_FOREACH(ipf, &ipflowlist, ipf_list) {
a716f015
SZ
358 /*
359 * Skip actively used ipflow
360 */
50e42f7f 361 if (IPFLOW_IS_ACTIVE(ipf))
a716f015
SZ
362 continue;
363
b9f8c879
SZ
364 /*
365 * If this no longer points to a valid route
366 * reclaim it.
367 */
368 if ((ipf->ipf_ro.ro_rt->rt_flags & RTF_UP) == 0)
369 goto done;
370
371 /*
372 * choose the one that's been least recently used
373 * or has had the least uses in the last 1.5
374 * intervals.
375 */
376 if (maybe_ipf == NULL ||
377 ipf->ipf_timer < maybe_ipf->ipf_timer ||
378 (ipf->ipf_timer == maybe_ipf->ipf_timer &&
379 ipf->ipf_last_uses + ipf->ipf_uses <
380 maybe_ipf->ipf_last_uses + maybe_ipf->ipf_uses))
381 maybe_ipf = ipf;
984263bc 382 }
a716f015
SZ
383 if (maybe_ipf == NULL)
384 return NULL;
385
984263bc 386 ipf = maybe_ipf;
be23faf1 387done:
984263bc 388 /*
a716f015 389 * Remove the entry from the flow table and reset its states
984263bc 390 */
b9f8c879 391 IPFLOW_REMOVE(ipf);
a716f015 392 ipflow_reset(ipf);
984263bc
MD
393 return ipf;
394}
395
775a6411 396static void
002c1265 397ipflow_timo_dispatch(netmsg_t nmsg)
984263bc 398{
b9f8c879 399 struct ipflow *ipf, *next_ipf;
984263bc 400
775a6411 401 crit_enter();
002c1265 402 lwkt_replymsg(&nmsg->lmsg, 0); /* reply ASAP */
f1cc5f0f 403 crit_exit();
775a6411 404
b9f8c879
SZ
405 LIST_FOREACH_MUTABLE(ipf, &ipflowlist, ipf_list, next_ipf) {
406 if (--ipf->ipf_timer == 0) {
a716f015
SZ
407 IPFLOW_REMOVE(ipf);
408 IPFLOW_FREE(ipf);
b9f8c879
SZ
409 } else {
410 ipf->ipf_last_uses = ipf->ipf_uses;
411 ipf->ipf_ro.ro_rt->rt_use += ipf->ipf_uses;
412 ipstat.ips_total += ipf->ipf_uses;
413 ipstat.ips_forward += ipf->ipf_uses;
414 ipstat.ips_fastforward += ipf->ipf_uses;
415 ipf->ipf_uses = 0;
984263bc
MD
416 }
417 }
775a6411
SZ
418}
419
420static void
421ipflow_timo_ipi(void *arg __unused)
422{
002c1265 423 struct lwkt_msg *msg = &ipflow_timo_netmsgs[mycpuid].lmsg;
775a6411
SZ
424
425 crit_enter();
426 if (msg->ms_flags & MSGF_DONE)
3abced87 427 lwkt_sendmsg(netisr_portfn(mycpuid), msg);
775a6411 428 crit_exit();
984263bc
MD
429}
430
431void
775a6411
SZ
432ipflow_slowtimo(void)
433{
a2c55831 434 cpumask_t mask = 0;
7fe5db3b
SZ
435 int i;
436
437 for (i = 0; i < ncpus; ++i) {
438 if (ipflow_inuse_pcpu[i])
8ccefc8e 439 mask |= CPUMASK(i);
7fe5db3b 440 }
f1cc5f0f 441 mask &= smp_active_mask;
7fe5db3b
SZ
442 if (mask != 0)
443 lwkt_send_ipiq_mask(mask, ipflow_timo_ipi, NULL);
775a6411
SZ
444}
445
297c8124
SZ
446void
447ipflow_create(const struct route *ro, struct mbuf *m)
984263bc
MD
448{
449 const struct ip *const ip = mtod(m, struct ip *);
450 struct ipflow *ipf;
451 unsigned hash;
984263bc 452
297c8124
SZ
453 /*
454 * Don't create cache entries for ICMP messages.
455 */
456 if (!ipflow_active || ip->ip_p == IPPROTO_ICMP)
457 return;
458
984263bc
MD
459 /*
460 * See if an existing flow struct exists. If so remove it from it's
461 * list and free the old route. If not, try to malloc a new one
462 * (if we aren't at our limit).
463 */
464 ipf = ipflow_lookup(ip);
465 if (ipf == NULL) {
466 if (ipflow_inuse == IPFLOW_MAX) {
467 ipf = ipflow_reap();
a716f015
SZ
468 if (ipf == NULL)
469 return;
984263bc 470 } else {
a716f015
SZ
471 ipf = kmalloc(sizeof(*ipf), M_IPFLOW,
472 M_NOWAIT | M_ZERO);
984263bc
MD
473 if (ipf == NULL)
474 return;
50e42f7f 475 ipf->ipf_refcnt = IPFLOW_REFCNT_INIT;
a716f015 476
984263bc
MD
477 ipflow_inuse++;
478 }
297c8124 479 } else {
50e42f7f 480 if (IPFLOW_NOT_ACTIVE(ipf)) {
a716f015
SZ
481 IPFLOW_REMOVE(ipf);
482 ipflow_reset(ipf);
483 } else {
484 /* This ipflow is being used; don't change it */
50e42f7f 485 KKASSERT(IPFLOW_IS_ACTIVE(ipf));
a716f015
SZ
486 return;
487 }
984263bc 488 }
a716f015 489 /* This ipflow should not be actively used */
50e42f7f 490 KKASSERT(IPFLOW_NOT_ACTIVE(ipf));
984263bc
MD
491
492 /*
493 * Fill in the updated information.
494 */
495 ipf->ipf_ro = *ro;
496 ro->ro_rt->rt_refcnt++;
497 ipf->ipf_dst = ip->ip_dst;
498 ipf->ipf_src = ip->ip_src;
499 ipf->ipf_tos = ip->ip_tos;
500 ipf->ipf_timer = IPFLOW_TIMER;
10c4b5fc 501
984263bc
MD
502 /*
503 * Insert into the approriate bucket of the flow table.
504 */
505 hash = ipflow_hash(ip->ip_dst, ip->ip_src, ip->ip_tos);
b9f8c879 506 IPFLOW_INSERT(&ipflowtable[hash], ipf);
984263bc 507}
775a6411 508
c59311aa
SZ
509void
510ipflow_flush_oncpu(void)
511{
512 struct ipflow *ipf;
513
514 while ((ipf = LIST_FIRST(&ipflowlist)) != NULL) {
515 IPFLOW_REMOVE(ipf);
516 IPFLOW_FREE(ipf);
517 }
518}
519
7d01720a 520static void
002c1265 521ipflow_ifaddr_handler(netmsg_t nmsg)
7d01720a
SZ
522{
523 struct netmsg_ipfaddr *amsg = (struct netmsg_ipfaddr *)nmsg;
524 struct ipflow *ipf, *next_ipf;
525
526 LIST_FOREACH_MUTABLE(ipf, &ipflowlist, ipf_list, next_ipf) {
527 if (ipf->ipf_dst.s_addr == amsg->ipf_addr.s_addr ||
528 ipf->ipf_src.s_addr == amsg->ipf_addr.s_addr) {
529 IPFLOW_REMOVE(ipf);
530 IPFLOW_FREE(ipf);
531 }
532 }
002c1265 533 ifnet_forwardmsg(&nmsg->lmsg, mycpuid + 1);
7d01720a
SZ
534}
535
536static void
537ipflow_ifaddr(void *arg __unused, struct ifnet *ifp __unused,
538 enum ifaddr_event event, struct ifaddr *ifa)
539{
540 struct netmsg_ipfaddr amsg;
541
542 if (ifa->ifa_addr->sa_family != AF_INET)
543 return;
544
545 /* Only add/change events need to be handled */
546 switch (event) {
547 case IFADDR_EVENT_ADD:
548 case IFADDR_EVENT_CHANGE:
549 break;
550
551 case IFADDR_EVENT_DELETE:
552 return;
553 }
554
002c1265 555 netmsg_init(&amsg.base, NULL, &curthread->td_msgport,
48e7b118 556 MSGF_PRIORITY, ipflow_ifaddr_handler);
7d01720a
SZ
557 amsg.ipf_addr = ifatoia(ifa)->ia_addr.sin_addr;
558
002c1265 559 ifnet_domsg(&amsg.base.lmsg, 0);
7d01720a
SZ
560}
561
775a6411
SZ
562static void
563ipflow_init(void)
564{
565 char oid_name[32];
566 int i;
567
568 for (i = 0; i < ncpus; ++i) {
48e7b118 569 netmsg_init(&ipflow_timo_netmsgs[i], NULL, &netisr_adone_rport,
c3c96e44 570 0, ipflow_timo_dispatch);
775a6411
SZ
571
572 ksnprintf(oid_name, sizeof(oid_name), "inuse%d", i);
573
574 SYSCTL_ADD_INT(NULL,
575 SYSCTL_STATIC_CHILDREN(_net_inet_ip_ipflow),
576 OID_AUTO, oid_name, CTLFLAG_RD, &ipflow_inuse_pcpu[i], 0,
577 "# of ip flow being used");
578 }
7d01720a
SZ
579 EVENTHANDLER_REGISTER(ifaddr_event, ipflow_ifaddr, NULL,
580 EVENTHANDLER_PRI_ANY);
775a6411
SZ
581}
582SYSINIT(arp, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, ipflow_init, 0);