print-pfsync.c (276788) | print-pfsync.c (281938) |
---|---|
1/* 2 * Copyright (c) 2012 Gleb Smirnoff <glebius@FreeBSD.org> 3 * Copyright (c) 2002 Michael Shalayeff 4 * Copyright (c) 2001 Daniel Hartmeier 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 --- 33 unchanged lines hidden (view full) --- 42#define TCPSTATES 43#include <netinet/tcp_fsm.h> 44 45#include <string.h> 46 47#include "interface.h" 48#include "addrtoname.h" 49 | 1/* 2 * Copyright (c) 2012 Gleb Smirnoff <glebius@FreeBSD.org> 3 * Copyright (c) 2002 Michael Shalayeff 4 * Copyright (c) 2001 Daniel Hartmeier 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 --- 33 unchanged lines hidden (view full) --- 42#define TCPSTATES 43#include <netinet/tcp_fsm.h> 44 45#include <string.h> 46 47#include "interface.h" 48#include "addrtoname.h" 49 |
50static void pfsync_print(struct pfsync_header *, const u_char *, u_int); 51static void print_src_dst(const struct pfsync_state_peer *, | 50static void pfsync_print(netdissect_options *, struct pfsync_header *, 51 const u_char *, u_int); 52static void print_src_dst(netdissect_options *, 53 const struct pfsync_state_peer *, |
52 const struct pfsync_state_peer *, uint8_t); | 54 const struct pfsync_state_peer *, uint8_t); |
53static void print_state(struct pfsync_state *); | 55static void print_state(netdissect_options *, struct pfsync_state *); |
54 55#ifdef notyet 56void 57pfsync_if_print(u_char *user, const struct pcap_pkthdr *h, 58 register const u_char *p) 59{ 60 u_int caplen = h->caplen; 61 62 ts_print(&h->ts); 63 64 if (caplen < PFSYNC_HDRLEN) { | 56 57#ifdef notyet 58void 59pfsync_if_print(u_char *user, const struct pcap_pkthdr *h, 60 register const u_char *p) 61{ 62 u_int caplen = h->caplen; 63 64 ts_print(&h->ts); 65 66 if (caplen < PFSYNC_HDRLEN) { |
65 printf("[|pfsync]"); | 67 ND_PRINT((ndo, "[|pfsync]")); |
66 goto out; 67 } 68 69 pfsync_print((struct pfsync_header *)p, 70 p + sizeof(struct pfsync_header), 71 caplen - sizeof(struct pfsync_header)); 72out: 73 if (xflag) { 74 default_print((const u_char *)p, caplen); 75 } | 68 goto out; 69 } 70 71 pfsync_print((struct pfsync_header *)p, 72 p + sizeof(struct pfsync_header), 73 caplen - sizeof(struct pfsync_header)); 74out: 75 if (xflag) { 76 default_print((const u_char *)p, caplen); 77 } |
76 putchar('\n'); | 78 safeputchar(ndo, '\n'); |
77} 78#endif /* notyet */ 79 80void | 79} 80#endif /* notyet */ 81 82void |
81pfsync_ip_print(const u_char *bp, u_int len) | 83pfsync_ip_print(netdissect_options *ndo , const u_char *bp, u_int len) |
82{ 83 struct pfsync_header *hdr = (struct pfsync_header *)bp; 84 85 if (len < PFSYNC_HDRLEN) | 84{ 85 struct pfsync_header *hdr = (struct pfsync_header *)bp; 86 87 if (len < PFSYNC_HDRLEN) |
86 printf("[|pfsync]"); | 88 ND_PRINT((ndo, "[|pfsync]")); |
87 else | 89 else |
88 pfsync_print(hdr, bp + sizeof(struct pfsync_header), | 90 pfsync_print(ndo, hdr, bp + sizeof(struct pfsync_header), |
89 len - sizeof(struct pfsync_header)); 90} 91 92struct pfsync_actions { 93 const char *name; 94 size_t len; | 91 len - sizeof(struct pfsync_header)); 92} 93 94struct pfsync_actions { 95 const char *name; 96 size_t len; |
95 void (*print)(const void *); | 97 void (*print)(netdissect_options *, const void *); |
96}; 97 | 98}; 99 |
98static void pfsync_print_clr(const void *); 99static void pfsync_print_state(const void *); 100static void pfsync_print_ins_ack(const void *); 101static void pfsync_print_upd_c(const void *); 102static void pfsync_print_upd_req(const void *); 103static void pfsync_print_del_c(const void *); 104static void pfsync_print_bus(const void *); 105static void pfsync_print_tdb(const void *); | 100static void pfsync_print_clr(netdissect_options *, const void *); 101static void pfsync_print_state(netdissect_options *, const void *); 102static void pfsync_print_ins_ack(netdissect_options *, const void *); 103static void pfsync_print_upd_c(netdissect_options *, const void *); 104static void pfsync_print_upd_req(netdissect_options *, const void *); 105static void pfsync_print_del_c(netdissect_options *, const void *); 106static void pfsync_print_bus(netdissect_options *, const void *); 107static void pfsync_print_tdb(netdissect_options *, const void *); |
106 107struct pfsync_actions actions[] = { 108 { "clear all", sizeof(struct pfsync_clr), pfsync_print_clr }, 109 { "insert", sizeof(struct pfsync_state), pfsync_print_state }, 110 { "insert ack", sizeof(struct pfsync_ins_ack), pfsync_print_ins_ack }, 111 { "update", sizeof(struct pfsync_ins_ack), pfsync_print_state }, 112 { "update compressed", sizeof(struct pfsync_upd_c), 113 pfsync_print_upd_c }, --- 6 unchanged lines hidden (view full) --- 120 { "frag delete", 0, NULL }, 121 { "bulk update status", sizeof(struct pfsync_bus), 122 pfsync_print_bus }, 123 { "tdb", 0, pfsync_print_tdb }, 124 { "eof", 0, NULL }, 125}; 126 127static void | 108 109struct pfsync_actions actions[] = { 110 { "clear all", sizeof(struct pfsync_clr), pfsync_print_clr }, 111 { "insert", sizeof(struct pfsync_state), pfsync_print_state }, 112 { "insert ack", sizeof(struct pfsync_ins_ack), pfsync_print_ins_ack }, 113 { "update", sizeof(struct pfsync_ins_ack), pfsync_print_state }, 114 { "update compressed", sizeof(struct pfsync_upd_c), 115 pfsync_print_upd_c }, --- 6 unchanged lines hidden (view full) --- 122 { "frag delete", 0, NULL }, 123 { "bulk update status", sizeof(struct pfsync_bus), 124 pfsync_print_bus }, 125 { "tdb", 0, pfsync_print_tdb }, 126 { "eof", 0, NULL }, 127}; 128 129static void |
128pfsync_print(struct pfsync_header *hdr, const u_char *bp, u_int len) | 130pfsync_print(netdissect_options *ndo, struct pfsync_header *hdr, 131 const u_char *bp, u_int len) |
129{ 130 struct pfsync_subheader *subh; 131 int count, plen, i; 132 u_int alen; 133 134 plen = ntohs(hdr->len); 135 | 132{ 133 struct pfsync_subheader *subh; 134 int count, plen, i; 135 u_int alen; 136 137 plen = ntohs(hdr->len); 138 |
136 printf("PFSYNCv%d len %d", hdr->version, plen); | 139 ND_PRINT((ndo, "PFSYNCv%d len %d", hdr->version, plen)); |
137 138 if (hdr->version != PFSYNC_VERSION) 139 return; 140 141 plen -= sizeof(*hdr); 142 143 while (plen > 0) { 144 if (len < sizeof(*subh)) 145 break; 146 147 subh = (struct pfsync_subheader *)bp; 148 bp += sizeof(*subh); 149 len -= sizeof(*subh); 150 plen -= sizeof(*subh); 151 152 if (subh->action >= PFSYNC_ACT_MAX) { | 140 141 if (hdr->version != PFSYNC_VERSION) 142 return; 143 144 plen -= sizeof(*hdr); 145 146 while (plen > 0) { 147 if (len < sizeof(*subh)) 148 break; 149 150 subh = (struct pfsync_subheader *)bp; 151 bp += sizeof(*subh); 152 len -= sizeof(*subh); 153 plen -= sizeof(*subh); 154 155 if (subh->action >= PFSYNC_ACT_MAX) { |
153 printf("\n act UNKNOWN id %d", subh->action); | 156 ND_PRINT((ndo, "\n act UNKNOWN id %d", 157 subh->action)); |
154 return; 155 } 156 157 count = ntohs(subh->count); | 158 return; 159 } 160 161 count = ntohs(subh->count); |
158 printf("\n %s count %d", actions[subh->action].name, count); | 162 ND_PRINT((ndo, "\n %s count %d", actions[subh->action].name, 163 count)); |
159 alen = actions[subh->action].len; 160 161 if (subh->action == PFSYNC_ACT_EOF) 162 return; 163 164 if (actions[subh->action].print == NULL) { | 164 alen = actions[subh->action].len; 165 166 if (subh->action == PFSYNC_ACT_EOF) 167 return; 168 169 if (actions[subh->action].print == NULL) { |
165 printf("\n unimplemented action %hhu", subh->action); | 170 ND_PRINT((ndo, "\n unimplemented action %hhu", 171 subh->action)); |
166 return; 167 } 168 169 for (i = 0; i < count; i++) { 170 if (len < alen) { 171 len = 0; 172 break; 173 } 174 175 if (vflag) | 172 return; 173 } 174 175 for (i = 0; i < count; i++) { 176 if (len < alen) { 177 len = 0; 178 break; 179 } 180 181 if (vflag) |
176 actions[subh->action].print(bp); | 182 actions[subh->action].print(ndo, bp); |
177 178 bp += alen; 179 len -= alen; 180 plen -= alen; 181 } 182 } 183 184 if (plen > 0) { | 183 184 bp += alen; 185 len -= alen; 186 plen -= alen; 187 } 188 } 189 190 if (plen > 0) { |
185 printf("\n ..."); | 191 ND_PRINT((ndo, "\n ...")); |
186 return; 187 } 188 if (plen < 0) { | 192 return; 193 } 194 if (plen < 0) { |
189 printf("\n invalid header length"); | 195 ND_PRINT((ndo, "\n invalid header length")); |
190 return; 191 } 192 if (len > 0) | 196 return; 197 } 198 if (len > 0) |
193 printf("\n invalid packet length"); | 199 ND_PRINT((ndo, "\n invalid packet length")); |
194} 195 196static void | 200} 201 202static void |
197pfsync_print_clr(const void *bp) | 203pfsync_print_clr(netdissect_options *ndo, const void *bp) |
198{ 199 const struct pfsync_clr *clr = bp; 200 | 204{ 205 const struct pfsync_clr *clr = bp; 206 |
201 printf("\n\tcreatorid: %08x", htonl(clr->creatorid)); | 207 ND_PRINT((ndo, "\n\tcreatorid: %08x", htonl(clr->creatorid))); |
202 if (clr->ifname[0] != '\0') | 208 if (clr->ifname[0] != '\0') |
203 printf(" interface: %s", clr->ifname); | 209 ND_PRINT((ndo, " interface: %s", clr->ifname)); |
204} 205 206static void | 210} 211 212static void |
207pfsync_print_state(const void *bp) | 213pfsync_print_state(netdissect_options *ndo, const void *bp) |
208{ 209 struct pfsync_state *st = (struct pfsync_state *)bp; 210 | 214{ 215 struct pfsync_state *st = (struct pfsync_state *)bp; 216 |
211 putchar('\n'); 212 print_state(st); | 217 safeputchar(ndo, '\n'); 218 print_state(ndo, st); |
213} 214 215static void | 219} 220 221static void |
216pfsync_print_ins_ack(const void *bp) | 222pfsync_print_ins_ack(netdissect_options *ndo, const void *bp) |
217{ 218 const struct pfsync_ins_ack *iack = bp; 219 | 223{ 224 const struct pfsync_ins_ack *iack = bp; 225 |
220 printf("\n\tid: %016jx creatorid: %08x", (uintmax_t )be64toh(iack->id), 221 ntohl(iack->creatorid)); | 226 ND_PRINT((ndo, "\n\tid: %016jx creatorid: %08x", 227 (uintmax_t)be64toh(iack->id), ntohl(iack->creatorid))); |
222} 223 224static void | 228} 229 230static void |
225pfsync_print_upd_c(const void *bp) | 231pfsync_print_upd_c(netdissect_options *ndo, const void *bp) |
226{ 227 const struct pfsync_upd_c *u = bp; 228 | 232{ 233 const struct pfsync_upd_c *u = bp; 234 |
229 printf("\n\tid: %016jx creatorid: %08x", (uintmax_t )be64toh(u->id), 230 ntohl(u->creatorid)); | 235 ND_PRINT((ndo, "\n\tid: %016jx creatorid: %08x", 236 (uintmax_t)be64toh(u->id), ntohl(u->creatorid))); |
231 if (vflag > 2) { | 237 if (vflag > 2) { |
232 printf("\n\tTCP? :"); 233 print_src_dst(&u->src, &u->dst, IPPROTO_TCP); | 238 ND_PRINT((ndo, "\n\tTCP? :")); 239 print_src_dst(ndo, &u->src, &u->dst, IPPROTO_TCP); |
234 } 235} 236 237static void | 240 } 241} 242 243static void |
238pfsync_print_upd_req(const void *bp) | 244pfsync_print_upd_req(netdissect_options *ndo, const void *bp) |
239{ 240 const struct pfsync_upd_req *ur = bp; 241 | 245{ 246 const struct pfsync_upd_req *ur = bp; 247 |
242 printf("\n\tid: %016jx creatorid: %08x", (uintmax_t )be64toh(ur->id), 243 ntohl(ur->creatorid)); | 248 ND_PRINT((ndo, "\n\tid: %016jx creatorid: %08x", 249 (uintmax_t)be64toh(ur->id), ntohl(ur->creatorid))); |
244} 245 246static void | 250} 251 252static void |
247pfsync_print_del_c(const void *bp) | 253pfsync_print_del_c(netdissect_options *ndo, const void *bp) |
248{ 249 const struct pfsync_del_c *d = bp; 250 | 254{ 255 const struct pfsync_del_c *d = bp; 256 |
251 printf("\n\tid: %016jx creatorid: %08x", (uintmax_t )be64toh(d->id), 252 ntohl(d->creatorid)); | 257 ND_PRINT((ndo, "\n\tid: %016jx creatorid: %08x", 258 (uintmax_t)be64toh(d->id), ntohl(d->creatorid))); |
253} 254 255static void | 259} 260 261static void |
256pfsync_print_bus(const void *bp) | 262pfsync_print_bus(netdissect_options *ndo, const void *bp) |
257{ 258 const struct pfsync_bus *b = bp; 259 uint32_t endtime; 260 int min, sec; 261 const char *status; 262 263 endtime = ntohl(b->endtime); 264 sec = endtime % 60; --- 8 unchanged lines hidden (view full) --- 273 case PFSYNC_BUS_END: 274 status = "end"; 275 break; 276 default: 277 status = "UNKNOWN"; 278 break; 279 } 280 | 263{ 264 const struct pfsync_bus *b = bp; 265 uint32_t endtime; 266 int min, sec; 267 const char *status; 268 269 endtime = ntohl(b->endtime); 270 sec = endtime % 60; --- 8 unchanged lines hidden (view full) --- 279 case PFSYNC_BUS_END: 280 status = "end"; 281 break; 282 default: 283 status = "UNKNOWN"; 284 break; 285 } 286 |
281 printf("\n\tcreatorid: %08x age: %.2u:%.2u:%.2u status: %s", 282 htonl(b->creatorid), endtime, min, sec, status); | 287 ND_PRINT((ndo, "\n\tcreatorid: %08x age: %.2u:%.2u:%.2u status: %s", 288 htonl(b->creatorid), endtime, min, sec, status)); |
283} 284 285static void | 289} 290 291static void |
286pfsync_print_tdb(const void *bp) | 292pfsync_print_tdb(netdissect_options *ndo, const void *bp) |
287{ 288 const struct pfsync_tdb *t = bp; 289 | 293{ 294 const struct pfsync_tdb *t = bp; 295 |
290 printf("\n\tspi: 0x%08x rpl: %ju cur_bytes: %ju", | 296 ND_PRINT((ndo, "\n\tspi: 0x%08x rpl: %ju cur_bytes: %ju", |
291 ntohl(t->spi), (uintmax_t )be64toh(t->rpl), | 297 ntohl(t->spi), (uintmax_t )be64toh(t->rpl), |
292 (uintmax_t )be64toh(t->cur_bytes)); | 298 (uintmax_t )be64toh(t->cur_bytes))); |
293} 294 295static void | 299} 300 301static void |
296print_host(struct pf_addr *addr, uint16_t port, sa_family_t af, 297 const char *proto) | 302print_host(netdissect_options *ndo, struct pf_addr *addr, uint16_t port, 303 sa_family_t af, const char *proto) |
298{ 299 char buf[48]; 300 301 if (inet_ntop(af, addr, buf, sizeof(buf)) == NULL) | 304{ 305 char buf[48]; 306 307 if (inet_ntop(af, addr, buf, sizeof(buf)) == NULL) |
302 printf("?"); | 308 ND_PRINT((ndo, "?")); |
303 else | 309 else |
304 printf("%s", buf); | 310 ND_PRINT((ndo, "%s", buf)); |
305 306 if (port) | 311 312 if (port) |
307 printf(".%hu", ntohs(port)); | 313 ND_PRINT((ndo, ".%hu", ntohs(port))); |
308} 309 310static void | 314} 315 316static void |
311print_seq(const struct pfsync_state_peer *p) | 317print_seq(netdissect_options *ndo, const struct pfsync_state_peer *p) |
312{ 313 if (p->seqdiff) | 318{ 319 if (p->seqdiff) |
314 printf("[%u + %u](+%u)", ntohl(p->seqlo), 315 ntohl(p->seqhi) - ntohl(p->seqlo), ntohl(p->seqdiff)); | 320 ND_PRINT((ndo, "[%u + %u](+%u)", ntohl(p->seqlo), 321 ntohl(p->seqhi) - ntohl(p->seqlo), ntohl(p->seqdiff))); |
316 else | 322 else |
317 printf("[%u + %u]", ntohl(p->seqlo), 318 ntohl(p->seqhi) - ntohl(p->seqlo)); | 323 ND_PRINT((ndo, "[%u + %u]", ntohl(p->seqlo), 324 ntohl(p->seqhi) - ntohl(p->seqlo))); |
319} 320 321static void | 325} 326 327static void |
322print_src_dst(const struct pfsync_state_peer *src, | 328print_src_dst(netdissect_options *ndo, const struct pfsync_state_peer *src, |
323 const struct pfsync_state_peer *dst, uint8_t proto) 324{ 325 326 if (proto == IPPROTO_TCP) { 327 if (src->state <= TCPS_TIME_WAIT && 328 dst->state <= TCPS_TIME_WAIT) | 329 const struct pfsync_state_peer *dst, uint8_t proto) 330{ 331 332 if (proto == IPPROTO_TCP) { 333 if (src->state <= TCPS_TIME_WAIT && 334 dst->state <= TCPS_TIME_WAIT) |
329 printf(" %s:%s", tcpstates[src->state], 330 tcpstates[dst->state]); | 335 ND_PRINT((ndo, " %s:%s", tcpstates[src->state], 336 tcpstates[dst->state])); |
331 else if (src->state == PF_TCPS_PROXY_SRC || 332 dst->state == PF_TCPS_PROXY_SRC) | 337 else if (src->state == PF_TCPS_PROXY_SRC || 338 dst->state == PF_TCPS_PROXY_SRC) |
333 printf(" PROXY:SRC"); | 339 ND_PRINT((ndo, " PROXY:SRC")); |
334 else if (src->state == PF_TCPS_PROXY_DST || 335 dst->state == PF_TCPS_PROXY_DST) | 340 else if (src->state == PF_TCPS_PROXY_DST || 341 dst->state == PF_TCPS_PROXY_DST) |
336 printf(" PROXY:DST"); | 342 ND_PRINT((ndo, " PROXY:DST")); |
337 else | 343 else |
338 printf(" <BAD STATE LEVELS %u:%u>", 339 src->state, dst->state); | 344 ND_PRINT((ndo, " <BAD STATE LEVELS %u:%u>", 345 src->state, dst->state)); |
340 if (vflag > 1) { | 346 if (vflag > 1) { |
341 printf("\n\t"); 342 print_seq(src); | 347 ND_PRINT((ndo, "\n\t")); 348 print_seq(ndo, src); |
343 if (src->wscale && dst->wscale) | 349 if (src->wscale && dst->wscale) |
344 printf(" wscale %u", 345 src->wscale & PF_WSCALE_MASK); 346 printf(" "); 347 print_seq(dst); | 350 ND_PRINT((ndo, " wscale %u", 351 src->wscale & PF_WSCALE_MASK)); 352 ND_PRINT((ndo, " ")); 353 print_seq(ndo, dst); |
348 if (src->wscale && dst->wscale) | 354 if (src->wscale && dst->wscale) |
349 printf(" wscale %u", 350 dst->wscale & PF_WSCALE_MASK); | 355 ND_PRINT((ndo, " wscale %u", 356 dst->wscale & PF_WSCALE_MASK)); |
351 } 352 } else if (proto == IPPROTO_UDP && src->state < PFUDPS_NSTATES && 353 dst->state < PFUDPS_NSTATES) { 354 const char *states[] = PFUDPS_NAMES; 355 | 357 } 358 } else if (proto == IPPROTO_UDP && src->state < PFUDPS_NSTATES && 359 dst->state < PFUDPS_NSTATES) { 360 const char *states[] = PFUDPS_NAMES; 361 |
356 printf(" %s:%s", states[src->state], states[dst->state]); | 362 ND_PRINT((ndo, " %s:%s", states[src->state], states[dst->state])); |
357 } else if (proto != IPPROTO_ICMP && src->state < PFOTHERS_NSTATES && 358 dst->state < PFOTHERS_NSTATES) { 359 /* XXX ICMP doesn't really have state levels */ 360 const char *states[] = PFOTHERS_NAMES; 361 | 363 } else if (proto != IPPROTO_ICMP && src->state < PFOTHERS_NSTATES && 364 dst->state < PFOTHERS_NSTATES) { 365 /* XXX ICMP doesn't really have state levels */ 366 const char *states[] = PFOTHERS_NAMES; 367 |
362 printf(" %s:%s", states[src->state], states[dst->state]); | 368 ND_PRINT((ndo, " %s:%s", states[src->state], states[dst->state])); |
363 } else { | 369 } else { |
364 printf(" %u:%u", src->state, dst->state); | 370 ND_PRINT((ndo, " %u:%u", src->state, dst->state)); |
365 } 366} 367 368static void | 371 } 372} 373 374static void |
369print_state(struct pfsync_state *s) | 375print_state(netdissect_options *ndo, struct pfsync_state *s) |
370{ 371 struct pfsync_state_peer *src, *dst; 372 struct pfsync_state_key *sk, *nk; 373 int min, sec; 374 375 if (s->direction == PF_OUT) { 376 src = &s->src; 377 dst = &s->dst; --- 4 unchanged lines hidden (view full) --- 382 } else { 383 src = &s->dst; 384 dst = &s->src; 385 sk = &s->key[PF_SK_WIRE]; 386 nk = &s->key[PF_SK_STACK]; 387 if (s->proto == IPPROTO_ICMP || s->proto == IPPROTO_ICMPV6) 388 sk->port[1] = nk->port[1]; 389 } | 376{ 377 struct pfsync_state_peer *src, *dst; 378 struct pfsync_state_key *sk, *nk; 379 int min, sec; 380 381 if (s->direction == PF_OUT) { 382 src = &s->src; 383 dst = &s->dst; --- 4 unchanged lines hidden (view full) --- 388 } else { 389 src = &s->dst; 390 dst = &s->src; 391 sk = &s->key[PF_SK_WIRE]; 392 nk = &s->key[PF_SK_STACK]; 393 if (s->proto == IPPROTO_ICMP || s->proto == IPPROTO_ICMPV6) 394 sk->port[1] = nk->port[1]; 395 } |
390 printf("\t%s ", s->ifname); 391 printf("proto %u ", s->proto); | 396 ND_PRINT((ndo, "\t%s ", s->ifname)); 397 ND_PRINT((ndo, "proto %u ", s->proto)); |
392 | 398 |
393 print_host(&nk->addr[1], nk->port[1], s->af, NULL); | 399 print_host(ndo, &nk->addr[1], nk->port[1], s->af, NULL); |
394 if (PF_ANEQ(&nk->addr[1], &sk->addr[1], s->af) || 395 nk->port[1] != sk->port[1]) { | 400 if (PF_ANEQ(&nk->addr[1], &sk->addr[1], s->af) || 401 nk->port[1] != sk->port[1]) { |
396 printf(" ("); 397 print_host(&sk->addr[1], sk->port[1], s->af, NULL); 398 printf(")"); | 402 ND_PRINT((ndo, " (")); 403 print_host(ndo, &sk->addr[1], sk->port[1], s->af, NULL); 404 ND_PRINT((ndo, ")")); |
399 } 400 if (s->direction == PF_OUT) | 405 } 406 if (s->direction == PF_OUT) |
401 printf(" -> "); | 407 ND_PRINT((ndo, " -> ")); |
402 else | 408 else |
403 printf(" <- "); 404 print_host(&nk->addr[0], nk->port[0], s->af, NULL); | 409 ND_PRINT((ndo, " <- ")); 410 print_host(ndo, &nk->addr[0], nk->port[0], s->af, NULL); |
405 if (PF_ANEQ(&nk->addr[0], &sk->addr[0], s->af) || 406 nk->port[0] != sk->port[0]) { | 411 if (PF_ANEQ(&nk->addr[0], &sk->addr[0], s->af) || 412 nk->port[0] != sk->port[0]) { |
407 printf(" ("); 408 print_host(&sk->addr[0], sk->port[0], s->af, NULL); 409 printf(")"); | 413 ND_PRINT((ndo, " (")); 414 print_host(ndo, &sk->addr[0], sk->port[0], s->af, NULL); 415 ND_PRINT((ndo, ")")); |
410 } 411 | 416 } 417 |
412 print_src_dst(src, dst, s->proto); | 418 print_src_dst(ndo, src, dst, s->proto); |
413 414 if (vflag > 1) { 415 uint64_t packets[2]; 416 uint64_t bytes[2]; 417 uint32_t creation = ntohl(s->creation); 418 uint32_t expire = ntohl(s->expire); 419 420 sec = creation % 60; 421 creation /= 60; 422 min = creation % 60; 423 creation /= 60; | 419 420 if (vflag > 1) { 421 uint64_t packets[2]; 422 uint64_t bytes[2]; 423 uint32_t creation = ntohl(s->creation); 424 uint32_t expire = ntohl(s->expire); 425 426 sec = creation % 60; 427 creation /= 60; 428 min = creation % 60; 429 creation /= 60; |
424 printf("\n\tage %.2u:%.2u:%.2u", creation, min, sec); | 430 ND_PRINT((ndo, "\n\tage %.2u:%.2u:%.2u", creation, min, sec)); |
425 sec = expire % 60; 426 expire /= 60; 427 min = expire % 60; 428 expire /= 60; | 431 sec = expire % 60; 432 expire /= 60; 433 min = expire % 60; 434 expire /= 60; |
429 printf(", expires in %.2u:%.2u:%.2u", expire, min, sec); | 435 ND_PRINT((ndo, ", expires in %.2u:%.2u:%.2u", expire, min, sec)); |
430 431 bcopy(s->packets[0], &packets[0], sizeof(uint64_t)); 432 bcopy(s->packets[1], &packets[1], sizeof(uint64_t)); 433 bcopy(s->bytes[0], &bytes[0], sizeof(uint64_t)); 434 bcopy(s->bytes[1], &bytes[1], sizeof(uint64_t)); | 436 437 bcopy(s->packets[0], &packets[0], sizeof(uint64_t)); 438 bcopy(s->packets[1], &packets[1], sizeof(uint64_t)); 439 bcopy(s->bytes[0], &bytes[0], sizeof(uint64_t)); 440 bcopy(s->bytes[1], &bytes[1], sizeof(uint64_t)); |
435 printf(", %ju:%ju pkts, %ju:%ju bytes", | 441 ND_PRINT((ndo, ", %ju:%ju pkts, %ju:%ju bytes", |
436 be64toh(packets[0]), be64toh(packets[1]), | 442 be64toh(packets[0]), be64toh(packets[1]), |
437 be64toh(bytes[0]), be64toh(bytes[1])); | 443 be64toh(bytes[0]), be64toh(bytes[1]))); |
438 if (s->anchor != ntohl(-1)) | 444 if (s->anchor != ntohl(-1)) |
439 printf(", anchor %u", ntohl(s->anchor)); | 445 ND_PRINT((ndo, ", anchor %u", ntohl(s->anchor))); |
440 if (s->rule != ntohl(-1)) | 446 if (s->rule != ntohl(-1)) |
441 printf(", rule %u", ntohl(s->rule)); | 447 ND_PRINT((ndo, ", rule %u", ntohl(s->rule))); |
442 } 443 if (vflag > 1) { 444 uint64_t id; 445 446 bcopy(&s->id, &id, sizeof(uint64_t)); | 448 } 449 if (vflag > 1) { 450 uint64_t id; 451 452 bcopy(&s->id, &id, sizeof(uint64_t)); |
447 printf("\n\tid: %016jx creatorid: %08x", 448 (uintmax_t )be64toh(id), ntohl(s->creatorid)); | 453 ND_PRINT((ndo, "\n\tid: %016jx creatorid: %08x", 454 (uintmax_t )be64toh(id), ntohl(s->creatorid))); |
449 } 450} | 455 } 456} |