1 /* $NetBSD: print-pfsync.c,v 1.1 2009/09/14 10:36:49 degroote Exp $ */
2 /* $OpenBSD: print-pfsync.c,v 1.30 2007/05/31 04:16:26 mcbride Exp $ */
5 * Copyright (c) 2002 Michael Shalayeff
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 THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
33 static const char rcsid
[] =
34 "@(#) $Header: /pub/NetBSD/misc/repositories/cvsroot/src/dist/tcpdump/print-pfsync.c,v 1.2 2009/09/14 15:18:15 he Exp $";
36 __RCSID("$NetBSD: print-pfsync.c,v 1.1 2009/09/14 10:36:49 degroote Exp $");
40 #include <sys/param.h>
42 #include <sys/socket.h>
44 #include <sys/ioctl.h>
52 #include <netinet/in.h>
53 #include <netinet/in_systm.h>
54 #include <netinet/ip.h>
56 #include <net/pfvar.h>
57 #include <net/if_pfsync.h>
66 #include "interface.h"
67 #include "addrtoname.h"
68 #include "pfctl_parser.h"
71 const char *pfsync_acts
[] = { PFSYNC_ACTIONS
};
73 static void pfsync_print(struct pfsync_header
*, int);
76 pfsync_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
78 u_int caplen
= h
->caplen
;
82 if (caplen
< PFSYNC_HDRLEN
) {
87 pfsync_print((struct pfsync_header
*)p
,
88 caplen
- sizeof(struct pfsync_header
));
91 default_print((const u_char
*)h
, caplen
);
99 pfsync_ip_print(const u_char
*bp
, u_int len
, const u_char
*bp2 __unused
)
101 struct pfsync_header
*hdr
= (struct pfsync_header
*)bp
;
103 if (len
< PFSYNC_HDRLEN
)
106 pfsync_print(hdr
, (len
- sizeof(struct pfsync_header
)));
111 pfsync_print(struct pfsync_header
*hdr
, int len
)
113 struct pfsync_state
*s
;
114 struct pfsync_state_upd
*u
;
115 struct pfsync_state_del
*d
;
116 struct pfsync_state_clr
*c
;
117 struct pfsync_state_upd_req
*r
;
118 struct pfsync_state_bus
*b
;
119 struct pfsync_tdb
*t
;
120 int i
, flags
= 0, min
, sec
;
124 printf("PFSYNCv%d count %d: ",
125 hdr
->version
, hdr
->count
);
127 if (hdr
->action
< PFSYNC_ACT_MAX
)
128 printf("%s %s:", (vflag
== 0) ? "PFSYNC" : "",
129 pfsync_acts
[hdr
->action
]);
131 printf("%s %d?:", (vflag
== 0) ? "PFSYNC" : "",
137 flags
|= PF_OPT_VERBOSE
;
139 flags
|= PF_OPT_VERBOSE2
;
141 flags
|= PF_OPT_USEDNS
;
143 switch (hdr
->action
) {
145 if (sizeof(*c
) <= len
) {
146 c
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
147 printf("\n\tcreatorid: %08x", htonl(c
->creatorid
));
148 if (c
->ifname
[0] != '\0')
149 printf(" interface: %s", c
->ifname
);
154 for (i
= 1, s
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
155 i
<= hdr
->count
&& i
* sizeof(*s
) <= len
; i
++, s
++) {
158 print_state(s
, flags
);
159 if (vflag
> 1 && hdr
->action
== PFSYNC_ACT_UPD
)
160 printf(" updates: %d", s
->updates
);
163 case PFSYNC_ACT_UPD_C
:
164 for (i
= 1, u
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
165 i
<= hdr
->count
&& i
* sizeof(*u
) <= len
; i
++, u
++) {
166 memcpy(&id
, &u
->id
, sizeof(id
));
167 printf("\n\tid: %" PRIu64
" creatorid: %08x",
168 be64toh(id
), ntohl(u
->creatorid
));
170 printf(" updates: %d", u
->updates
);
173 case PFSYNC_ACT_DEL_C
:
174 for (i
= 1, d
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
175 i
<= hdr
->count
&& i
* sizeof(*d
) <= len
; i
++, d
++) {
176 memcpy(&id
, &d
->id
, sizeof(id
));
177 printf("\n\tid: %" PRIu64
" creatorid: %08x",
178 be64toh(id
), ntohl(d
->creatorid
));
181 case PFSYNC_ACT_UREQ
:
182 for (i
= 1, r
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
183 i
<= hdr
->count
&& i
* sizeof(*r
) <= len
; i
++, r
++) {
184 memcpy(&id
, &r
->id
, sizeof(id
));
185 printf("\n\tid: %" PRIu64
" creatorid: %08x",
186 be64toh(id
), ntohl(r
->creatorid
));
190 if (sizeof(*b
) <= len
) {
191 b
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
192 printf("\n\tcreatorid: %08x", htonl(b
->creatorid
));
193 sec
= b
->endtime
% 60;
195 min
= b
->endtime
% 60;
197 printf(" age %.2u:%.2u:%.2u", b
->endtime
, min
, sec
);
199 case PFSYNC_BUS_START
:
200 printf(" status: start");
203 printf(" status: end");
206 printf(" status: ?");
211 case PFSYNC_ACT_TDB_UPD
:
212 for (i
= 1, t
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
213 i
<= hdr
->count
&& i
* sizeof(*t
) <= len
; i
++, t
++)
214 printf("\n\tspi: %08x rpl: %u cur_bytes: %" PRIu64
,
215 htonl(t
->spi
), htonl(t
->rpl
),
216 be64toh(t
->cur_bytes
));
217 /* XXX add dst and sproto? */