if_pfsync.h revision 127145
1126261Smlaier/*	$FreeBSD: head/sys/contrib/pf/net/if_pfsync.h 127145 2004-03-17 21:11:02Z mlaier $	*/
2126258Smlaier/*	$OpenBSD: if_pfsync.h,v 1.2 2002/12/11 18:31:26 mickey Exp $	*/
3126258Smlaier
4126258Smlaier/*
5126258Smlaier * Copyright (c) 2001 Michael Shalayeff
6126258Smlaier * All rights reserved.
7126258Smlaier *
8126258Smlaier * Redistribution and use in source and binary forms, with or without
9126258Smlaier * modification, are permitted provided that the following conditions
10126258Smlaier * are met:
11126258Smlaier * 1. Redistributions of source code must retain the above copyright
12126258Smlaier *    notice, this list of conditions and the following disclaimer.
13126258Smlaier * 2. Redistributions in binary form must reproduce the above copyright
14126258Smlaier *    notice, this list of conditions and the following disclaimer in the
15126258Smlaier *    documentation and/or other materials provided with the distribution.
16126258Smlaier *
17126258Smlaier * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18126258Smlaier * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19126258Smlaier * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20126258Smlaier * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
21126258Smlaier * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22126258Smlaier * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23126258Smlaier * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24126258Smlaier * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25126258Smlaier * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26126258Smlaier * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27126258Smlaier * THE POSSIBILITY OF SUCH DAMAGE.
28126258Smlaier */
29126258Smlaier
30126258Smlaier#ifndef _NET_IF_PFSYNC_H_
31126258Smlaier#define _NET_IF_PFSYNC_H_
32126258Smlaier
33126258Smlaier#ifdef _KERNEL
34126258Smlaierstruct pfsync_softc {
35126258Smlaier	struct ifnet	sc_if;
36126258Smlaier
37127145Smlaier#ifdef __FreeBSD__
38126261Smlaier	struct callout	sc_tmo;
39126261Smlaier#else
40126258Smlaier	struct timeout	sc_tmo;
41126261Smlaier#endif
42126258Smlaier	struct mbuf	*sc_mbuf;	/* current cummulative mbuf */
43126258Smlaier	struct pf_state	*sc_ptr;	/* current ongoing state */
44126258Smlaier	int		 sc_count;	/* number of states in one mtu */
45127145Smlaier#ifdef __FreeBSD__
46126261Smlaier	LIST_ENTRY(pfsync_softc) sc_next;
47126261Smlaier#endif
48126258Smlaier};
49126258Smlaier#endif
50126258Smlaier
51126258Smlaierstruct pfsync_header {
52126258Smlaier	u_int8_t version;
53126258Smlaier#define	PFSYNC_VERSION	1
54126258Smlaier	u_int8_t af;
55126258Smlaier	u_int8_t action;
56126258Smlaier#define	PFSYNC_ACT_CLR	0
57126258Smlaier#define	PFSYNC_ACT_INS	1
58126258Smlaier#define	PFSYNC_ACT_UPD	2
59126258Smlaier#define	PFSYNC_ACT_DEL	3
60126258Smlaier#define	PFSYNC_ACT_MAX	4
61126258Smlaier	u_int8_t count;
62126258Smlaier};
63126258Smlaier
64126258Smlaier#define PFSYNC_HDRLEN	sizeof(struct pfsync_header)
65126258Smlaier#define	PFSYNC_ACTIONS \
66126258Smlaier	"CLR ST", "INS ST", "UPD ST", "DEL ST"
67126258Smlaier
68126258Smlaier#define pf_state_peer_hton(s,d) do {		\
69126258Smlaier	(d)->seqlo = htonl((s)->seqlo);		\
70126258Smlaier	(d)->seqhi = htonl((s)->seqhi);		\
71126258Smlaier	(d)->seqdiff = htonl((s)->seqdiff);	\
72126258Smlaier	(d)->max_win = htons((s)->max_win);	\
73126258Smlaier	(d)->state = (s)->state;		\
74126258Smlaier} while (0)
75126258Smlaier
76126258Smlaier#define pf_state_peer_ntoh(s,d) do {		\
77126258Smlaier	(d)->seqlo = ntohl((s)->seqlo);		\
78126258Smlaier	(d)->seqhi = ntohl((s)->seqhi);		\
79126258Smlaier	(d)->seqdiff = ntohl((s)->seqdiff);	\
80126258Smlaier	(d)->max_win = ntohs((s)->max_win);	\
81126258Smlaier	(d)->state = (s)->state;		\
82126258Smlaier} while (0)
83126258Smlaier
84126258Smlaier#ifdef _KERNEL
85126258Smlaierint pfsync_clear_state(struct pf_state *);
86126258Smlaierint pfsync_pack_state(u_int8_t, struct pf_state *);
87126258Smlaier#define pfsync_insert_state(st)	pfsync_pack_state(PFSYNC_ACT_INS, (st))
88126258Smlaier#define pfsync_update_state(st)	pfsync_pack_state(PFSYNC_ACT_UPD, (st))
89126258Smlaier#define pfsync_delete_state(st)	pfsync_pack_state(PFSYNC_ACT_DEL, (st))
90126258Smlaier#endif
91126258Smlaier
92126258Smlaier#endif /* _NET_IF_PFSYNC_H_ */
93