Deleted Added
full compact
if_pfsync.c (241394) if_pfsync.c (241610)
1/* $OpenBSD: if_pfsync.c,v 1.110 2009/02/24 05:39:19 dlg Exp $ */
2
3/*
4 * Copyright (c) 2002 Michael Shalayeff
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 41 unchanged lines hidden (view full) ---

50 * 1.128 - cleanups
51 * 1.146 - bzero() mbuf before sparsely filling it with data
52 * 1.170 - SIOCSIFMTU checks
53 * 1.126, 1.142 - deferred packets processing
54 * 1.173 - correct expire time processing
55 */
56
57#include <sys/cdefs.h>
1/* $OpenBSD: if_pfsync.c,v 1.110 2009/02/24 05:39:19 dlg Exp $ */
2
3/*
4 * Copyright (c) 2002 Michael Shalayeff
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 41 unchanged lines hidden (view full) ---

50 * 1.128 - cleanups
51 * 1.146 - bzero() mbuf before sparsely filling it with data
52 * 1.170 - SIOCSIFMTU checks
53 * 1.126, 1.142 - deferred packets processing
54 * 1.173 - correct expire time processing
55 */
56
57#include <sys/cdefs.h>
58__FBSDID("$FreeBSD: head/sys/netpfil/pf/if_pfsync.c 241394 2012-10-10 08:36:38Z kevlo $");
58__FBSDID("$FreeBSD: head/sys/netpfil/pf/if_pfsync.c 241610 2012-10-16 13:37:54Z glebius $");
59
60#include "opt_inet.h"
61#include "opt_inet6.h"
62#include "opt_pf.h"
63
64#include <sys/param.h>
65#include <sys/bus.h>
66#include <sys/endian.h>

--- 148 unchanged lines hidden (view full) ---

215#define PFSYNC_LOCK(sc) mtx_lock(&(sc)->sc_mtx)
216#define PFSYNC_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx)
217#define PFSYNC_LOCK_ASSERT(sc) mtx_assert(&(sc)->sc_mtx, MA_OWNED)
218
219#define PFSYNC_BLOCK(sc) mtx_lock(&(sc)->sc_bulk_mtx)
220#define PFSYNC_BUNLOCK(sc) mtx_unlock(&(sc)->sc_bulk_mtx)
221#define PFSYNC_BLOCK_ASSERT(sc) mtx_assert(&(sc)->sc_bulk_mtx, MA_OWNED)
222
59
60#include "opt_inet.h"
61#include "opt_inet6.h"
62#include "opt_pf.h"
63
64#include <sys/param.h>
65#include <sys/bus.h>
66#include <sys/endian.h>

--- 148 unchanged lines hidden (view full) ---

215#define PFSYNC_LOCK(sc) mtx_lock(&(sc)->sc_mtx)
216#define PFSYNC_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx)
217#define PFSYNC_LOCK_ASSERT(sc) mtx_assert(&(sc)->sc_mtx, MA_OWNED)
218
219#define PFSYNC_BLOCK(sc) mtx_lock(&(sc)->sc_bulk_mtx)
220#define PFSYNC_BUNLOCK(sc) mtx_unlock(&(sc)->sc_bulk_mtx)
221#define PFSYNC_BLOCK_ASSERT(sc) mtx_assert(&(sc)->sc_bulk_mtx, MA_OWNED)
222
223static MALLOC_DEFINE(M_PFSYNC, "pfsync", "pfsync(4) data");
223static const char pfsyncname[] = "pfsync";
224static MALLOC_DEFINE(M_PFSYNC, pfsyncname, "pfsync(4) data");
224static VNET_DEFINE(struct pfsync_softc *, pfsyncif) = NULL;
225#define V_pfsyncif VNET(pfsyncif)
226static VNET_DEFINE(void *, pfsync_swi_cookie) = NULL;
227#define V_pfsync_swi_cookie VNET(pfsync_swi_cookie)
228static VNET_DEFINE(struct pfsyncstats, pfsyncstats);
229#define V_pfsyncstats VNET(pfsyncstats)
230static VNET_DEFINE(int, pfsync_carp_adj) = CARP_MAXSKEW;
231#define V_pfsync_carp_adj VNET(pfsync_carp_adj)

--- 42 unchanged lines hidden (view full) ---

274static void pfsync_bulk_fail(void *);
275
276#ifdef IPSEC
277static void pfsync_update_net_tdb(struct pfsync_tdb *);
278#endif
279
280#define PFSYNC_MAX_BULKTRIES 12
281
225static VNET_DEFINE(struct pfsync_softc *, pfsyncif) = NULL;
226#define V_pfsyncif VNET(pfsyncif)
227static VNET_DEFINE(void *, pfsync_swi_cookie) = NULL;
228#define V_pfsync_swi_cookie VNET(pfsync_swi_cookie)
229static VNET_DEFINE(struct pfsyncstats, pfsyncstats);
230#define V_pfsyncstats VNET(pfsyncstats)
231static VNET_DEFINE(int, pfsync_carp_adj) = CARP_MAXSKEW;
232#define V_pfsync_carp_adj VNET(pfsync_carp_adj)

--- 42 unchanged lines hidden (view full) ---

275static void pfsync_bulk_fail(void *);
276
277#ifdef IPSEC
278static void pfsync_update_net_tdb(struct pfsync_tdb *);
279#endif
280
281#define PFSYNC_MAX_BULKTRIES 12
282
282VNET_DEFINE(struct ifc_simple_data, pfsync_cloner_data);
283VNET_DEFINE(struct if_clone, pfsync_cloner);
284#define V_pfsync_cloner_data VNET(pfsync_cloner_data)
285#define V_pfsync_cloner VNET(pfsync_cloner)
286IFC_SIMPLE_DECLARE(pfsync, 1);
283VNET_DEFINE(struct if_clone *, pfsync_cloner);
284#define V_pfsync_cloner VNET(pfsync_cloner)
287
288static int
289pfsync_clone_create(struct if_clone *ifc, int unit, caddr_t param)
290{
291 struct pfsync_softc *sc;
292 struct ifnet *ifp;
293 int q;
294

--- 12 unchanged lines hidden (view full) ---

307 sc->sc_len = PFSYNC_MINPKT;
308 sc->sc_maxupdates = 128;
309
310 ifp = sc->sc_ifp = if_alloc(IFT_PFSYNC);
311 if (ifp == NULL) {
312 free(sc, M_PFSYNC);
313 return (ENOSPC);
314 }
285
286static int
287pfsync_clone_create(struct if_clone *ifc, int unit, caddr_t param)
288{
289 struct pfsync_softc *sc;
290 struct ifnet *ifp;
291 int q;
292

--- 12 unchanged lines hidden (view full) ---

305 sc->sc_len = PFSYNC_MINPKT;
306 sc->sc_maxupdates = 128;
307
308 ifp = sc->sc_ifp = if_alloc(IFT_PFSYNC);
309 if (ifp == NULL) {
310 free(sc, M_PFSYNC);
311 return (ENOSPC);
312 }
315 if_initname(ifp, ifc->ifc_name, unit);
313 if_initname(ifp, pfsyncname, unit);
316 ifp->if_softc = sc;
317 ifp->if_ioctl = pfsyncioctl;
318 ifp->if_output = pfsyncoutput;
319 ifp->if_type = IFT_PFSYNC;
320 ifp->if_snd.ifq_maxlen = ifqmaxlen;
321 ifp->if_hdrlen = sizeof(struct pfsync_header);
322 ifp->if_mtu = ETHERMTU;
314 ifp->if_softc = sc;
315 ifp->if_ioctl = pfsyncioctl;
316 ifp->if_output = pfsyncoutput;
317 ifp->if_type = IFT_PFSYNC;
318 ifp->if_snd.ifq_maxlen = ifqmaxlen;
319 ifp->if_hdrlen = sizeof(struct pfsync_header);
320 ifp->if_mtu = ETHERMTU;
323 mtx_init(&sc->sc_mtx, "pfsync", NULL, MTX_DEF);
321 mtx_init(&sc->sc_mtx, pfsyncname, NULL, MTX_DEF);
324 mtx_init(&sc->sc_bulk_mtx, "pfsync bulk", NULL, MTX_DEF);
325 callout_init(&sc->sc_tmo, CALLOUT_MPSAFE);
326 callout_init_mtx(&sc->sc_bulk_tmo, &sc->sc_bulk_mtx, 0);
327 callout_init_mtx(&sc->sc_bulkfail_tmo, &sc->sc_bulk_mtx, 0);
328
329 if_attach(ifp);
330
331 bpfattach(ifp, DLT_PFSYNC, PFSYNC_HDRLEN);

--- 1976 unchanged lines hidden (view full) ---

2308pfsync_init()
2309{
2310 VNET_ITERATOR_DECL(vnet_iter);
2311 int error = 0;
2312
2313 VNET_LIST_RLOCK();
2314 VNET_FOREACH(vnet_iter) {
2315 CURVNET_SET(vnet_iter);
322 mtx_init(&sc->sc_bulk_mtx, "pfsync bulk", NULL, MTX_DEF);
323 callout_init(&sc->sc_tmo, CALLOUT_MPSAFE);
324 callout_init_mtx(&sc->sc_bulk_tmo, &sc->sc_bulk_mtx, 0);
325 callout_init_mtx(&sc->sc_bulkfail_tmo, &sc->sc_bulk_mtx, 0);
326
327 if_attach(ifp);
328
329 bpfattach(ifp, DLT_PFSYNC, PFSYNC_HDRLEN);

--- 1976 unchanged lines hidden (view full) ---

2306pfsync_init()
2307{
2308 VNET_ITERATOR_DECL(vnet_iter);
2309 int error = 0;
2310
2311 VNET_LIST_RLOCK();
2312 VNET_FOREACH(vnet_iter) {
2313 CURVNET_SET(vnet_iter);
2316 V_pfsync_cloner = pfsync_cloner;
2317 V_pfsync_cloner_data = pfsync_cloner_data;
2318 V_pfsync_cloner.ifc_data = &V_pfsync_cloner_data;
2319 if_clone_attach(&V_pfsync_cloner);
2320 error = swi_add(NULL, "pfsync", pfsyncintr, V_pfsyncif,
2314 V_pfsync_cloner = if_clone_simple(pfsyncname,
2315 pfsync_clone_create, pfsync_clone_destroy, 1);
2316 error = swi_add(NULL, pfsyncname, pfsyncintr, V_pfsyncif,
2321 SWI_NET, INTR_MPSAFE, &V_pfsync_swi_cookie);
2322 CURVNET_RESTORE();
2323 if (error)
2324 goto fail_locked;
2325 }
2326 VNET_LIST_RUNLOCK();
2327#ifdef INET
2328 error = pf_proto_register(PF_INET, &in_pfsync_protosw);

--- 11 unchanged lines hidden (view full) ---

2340
2341fail:
2342 VNET_LIST_RLOCK();
2343fail_locked:
2344 VNET_FOREACH(vnet_iter) {
2345 CURVNET_SET(vnet_iter);
2346 if (V_pfsync_swi_cookie) {
2347 swi_remove(V_pfsync_swi_cookie);
2317 SWI_NET, INTR_MPSAFE, &V_pfsync_swi_cookie);
2318 CURVNET_RESTORE();
2319 if (error)
2320 goto fail_locked;
2321 }
2322 VNET_LIST_RUNLOCK();
2323#ifdef INET
2324 error = pf_proto_register(PF_INET, &in_pfsync_protosw);

--- 11 unchanged lines hidden (view full) ---

2336
2337fail:
2338 VNET_LIST_RLOCK();
2339fail_locked:
2340 VNET_FOREACH(vnet_iter) {
2341 CURVNET_SET(vnet_iter);
2342 if (V_pfsync_swi_cookie) {
2343 swi_remove(V_pfsync_swi_cookie);
2348 if_clone_detach(&V_pfsync_cloner);
2344 if_clone_detach(V_pfsync_cloner);
2349 }
2350 CURVNET_RESTORE();
2351 }
2352 VNET_LIST_RUNLOCK();
2353
2354 return (error);
2355}
2356

--- 4 unchanged lines hidden (view full) ---

2361
2362 pfsync_pointers_uninit();
2363
2364 ipproto_unregister(IPPROTO_PFSYNC);
2365 pf_proto_unregister(PF_INET, IPPROTO_PFSYNC, SOCK_RAW);
2366 VNET_LIST_RLOCK();
2367 VNET_FOREACH(vnet_iter) {
2368 CURVNET_SET(vnet_iter);
2345 }
2346 CURVNET_RESTORE();
2347 }
2348 VNET_LIST_RUNLOCK();
2349
2350 return (error);
2351}
2352

--- 4 unchanged lines hidden (view full) ---

2357
2358 pfsync_pointers_uninit();
2359
2360 ipproto_unregister(IPPROTO_PFSYNC);
2361 pf_proto_unregister(PF_INET, IPPROTO_PFSYNC, SOCK_RAW);
2362 VNET_LIST_RLOCK();
2363 VNET_FOREACH(vnet_iter) {
2364 CURVNET_SET(vnet_iter);
2369 if_clone_detach(&V_pfsync_cloner);
2365 if_clone_detach(V_pfsync_cloner);
2370 swi_remove(V_pfsync_swi_cookie);
2371 CURVNET_RESTORE();
2372 }
2373 VNET_LIST_RUNLOCK();
2374}
2375
2376static int
2377pfsync_modevent(module_t mod, int type, void *data)

--- 17 unchanged lines hidden (view full) ---

2395 error = EINVAL;
2396 break;
2397 }
2398
2399 return (error);
2400}
2401
2402static moduledata_t pfsync_mod = {
2366 swi_remove(V_pfsync_swi_cookie);
2367 CURVNET_RESTORE();
2368 }
2369 VNET_LIST_RUNLOCK();
2370}
2371
2372static int
2373pfsync_modevent(module_t mod, int type, void *data)

--- 17 unchanged lines hidden (view full) ---

2391 error = EINVAL;
2392 break;
2393 }
2394
2395 return (error);
2396}
2397
2398static moduledata_t pfsync_mod = {
2403 "pfsync",
2399 pfsyncname,
2404 pfsync_modevent,
2405 0
2406};
2407
2408#define PFSYNC_MODVER 1
2409
2410DECLARE_MODULE(pfsync, pfsync_mod, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY);
2411MODULE_VERSION(pfsync, PFSYNC_MODVER);
2412MODULE_DEPEND(pfsync, pf, PF_MODVER, PF_MODVER, PF_MODVER);
2400 pfsync_modevent,
2401 0
2402};
2403
2404#define PFSYNC_MODVER 1
2405
2406DECLARE_MODULE(pfsync, pfsync_mod, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY);
2407MODULE_VERSION(pfsync, PFSYNC_MODVER);
2408MODULE_DEPEND(pfsync, pf, PF_MODVER, PF_MODVER, PF_MODVER);