Deleted Added
sdiff udiff text old ( 241394 ) new ( 241610 )
full compact
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 $");
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");
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
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);
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 }
315 if_initname(ifp, ifc->ifc_name, 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;
323 mtx_init(&sc->sc_mtx, "pfsync", 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);
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,
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);
2348 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);
2369 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 = {
2403 "pfsync",
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);