1 /* $NetBSD: print-pfsync.c,v 1.2 2014/11/20 03:05:03 christos 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: /cvsroot/src/external/bsd/tcpdump/dist/print-pfsync.c,v 1.2 2014/11/20 03:05:03 christos Exp $";
36 __RCSID("$NetBSD: print-pfsync.c,v 1.2 2014/11/20 03:05:03 christos Exp $");
40 #define NETDISECT_REWORKED
45 #include <tcpdump-stdinc.h>
47 #include <sys/param.h>
49 #include <sys/socket.h>
51 #include <sys/ioctl.h>
60 #include <netinet/in.h>
61 #include <netinet/in_systm.h>
62 #include <netinet/ip.h>
65 #include <net/pfvar.h>
66 #include <net/if_pfsync.h>
75 #include "interface.h"
76 #include "addrtoname.h"
77 #include "pfctl_parser.h"
80 const char *pfsync_acts
[] = { PFSYNC_ACTIONS
};
82 static void pfsync_print(struct pfsync_header
*, int);
85 pfsync_if_print(netdissect_options
*ndo
, const struct pcap_pkthdr
*h
, const u_char
*p
)
87 u_int caplen
= h
->caplen
;
89 ts_print(ndo
, &h
->ts
);
91 if (caplen
< PFSYNC_HDRLEN
) {
92 ND_PRINT((ndo
, "[|pfsync]"));
96 pfsync_print((struct pfsync_header
*)p
,
97 caplen
- sizeof(struct pfsync_header
));
100 default_print((const u_char
*)h
, caplen
);
108 pfsync_ip_print(const u_char
*bp
, u_int len
, const u_char
*bp2 __unused
)
110 struct pfsync_header
*hdr
= (struct pfsync_header
*)bp
;
112 if (len
< PFSYNC_HDRLEN
)
115 pfsync_print(hdr
, (len
- sizeof(struct pfsync_header
)));
120 pfsync_print(struct pfsync_header
*hdr
, int len
)
122 struct pfsync_state
*s
;
123 struct pfsync_state_upd
*u
;
124 struct pfsync_state_del
*d
;
125 struct pfsync_state_clr
*c
;
126 struct pfsync_state_upd_req
*r
;
127 struct pfsync_state_bus
*b
;
128 struct pfsync_tdb
*t
;
129 int i
, flags
= 0, min
, sec
;
133 printf("PFSYNCv%d count %d: ",
134 hdr
->version
, hdr
->count
);
136 if (hdr
->action
< PFSYNC_ACT_MAX
)
137 printf("%s %s:", (vflag
== 0) ? "PFSYNC" : "",
138 pfsync_acts
[hdr
->action
]);
140 printf("%s %d?:", (vflag
== 0) ? "PFSYNC" : "",
146 flags
|= PF_OPT_VERBOSE
;
148 flags
|= PF_OPT_VERBOSE2
;
150 flags
|= PF_OPT_USEDNS
;
152 switch (hdr
->action
) {
154 if (sizeof(*c
) <= len
) {
155 c
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
156 printf("\n\tcreatorid: %08x", htonl(c
->creatorid
));
157 if (c
->ifname
[0] != '\0')
158 printf(" interface: %s", c
->ifname
);
163 for (i
= 1, s
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
164 i
<= hdr
->count
&& i
* sizeof(*s
) <= len
; i
++, s
++) {
167 print_state(s
, flags
);
168 if (vflag
> 1 && hdr
->action
== PFSYNC_ACT_UPD
)
169 printf(" updates: %d", s
->updates
);
172 case PFSYNC_ACT_UPD_C
:
173 for (i
= 1, u
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
174 i
<= hdr
->count
&& i
* sizeof(*u
) <= len
; i
++, u
++) {
175 memcpy(&id
, &u
->id
, sizeof(id
));
176 printf("\n\tid: %" PRIu64
" creatorid: %08x",
177 be64toh(id
), ntohl(u
->creatorid
));
179 printf(" updates: %d", u
->updates
);
182 case PFSYNC_ACT_DEL_C
:
183 for (i
= 1, d
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
184 i
<= hdr
->count
&& i
* sizeof(*d
) <= len
; i
++, d
++) {
185 memcpy(&id
, &d
->id
, sizeof(id
));
186 printf("\n\tid: %" PRIu64
" creatorid: %08x",
187 be64toh(id
), ntohl(d
->creatorid
));
190 case PFSYNC_ACT_UREQ
:
191 for (i
= 1, r
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
192 i
<= hdr
->count
&& i
* sizeof(*r
) <= len
; i
++, r
++) {
193 memcpy(&id
, &r
->id
, sizeof(id
));
194 printf("\n\tid: %" PRIu64
" creatorid: %08x",
195 be64toh(id
), ntohl(r
->creatorid
));
199 if (sizeof(*b
) <= len
) {
200 b
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
201 printf("\n\tcreatorid: %08x", htonl(b
->creatorid
));
202 sec
= b
->endtime
% 60;
204 min
= b
->endtime
% 60;
206 printf(" age %.2u:%.2u:%.2u", b
->endtime
, min
, sec
);
208 case PFSYNC_BUS_START
:
209 printf(" status: start");
212 printf(" status: end");
215 printf(" status: ?");
220 case PFSYNC_ACT_TDB_UPD
:
221 for (i
= 1, t
= (void *)((char *)hdr
+ PFSYNC_HDRLEN
);
222 i
<= hdr
->count
&& i
* sizeof(*t
) <= len
; i
++, t
++)
223 printf("\n\tspi: %08x rpl: %u cur_bytes: %" PRIu64
,
224 htonl(t
->spi
), htonl(t
->rpl
),
225 be64toh(t
->cur_bytes
));
226 /* XXX add dst and sproto? */