blob: eddcc1d7546fcd1113acfc3f2044af20739696d5 [file] [log] [blame]
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001/* \summary: Solaris DLT_IPNET printer */
2
JP Abgrall53f17a92014-02-12 14:02:41 -08003#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -07004#include <config.h>
JP Abgrall53f17a92014-02-12 14:02:41 -08005#endif
6
Elliott Hughes820eced2021-08-20 18:00:50 -07007#include "netdissect-stdinc.h"
JP Abgrall53f17a92014-02-12 14:02:41 -08008
Elliott Hughes820eced2021-08-20 18:00:50 -07009#define ND_LONGJMP_FROM_TCHECK
Elliott Hughese2e3bd12017-05-15 10:59:29 -070010#include "netdissect.h"
Elliott Hughes820eced2021-08-20 18:00:50 -070011#include "extract.h"
12
Elliott Hughes892a68b2015-10-19 14:43:53 -070013
14typedef struct ipnet_hdr {
Elliott Hughes820eced2021-08-20 18:00:50 -070015 nd_uint8_t iph_version;
16 nd_uint8_t iph_family;
17 nd_uint16_t iph_htype;
18 nd_uint32_t iph_pktlen;
19 nd_uint32_t iph_ifindex;
20 nd_uint32_t iph_grifindex;
21 nd_uint32_t iph_zsrc;
22 nd_uint32_t iph_zdst;
Elliott Hughes892a68b2015-10-19 14:43:53 -070023} ipnet_hdr_t;
24
25#define IPH_AF_INET 2 /* Matches Solaris's AF_INET */
26#define IPH_AF_INET6 26 /* Matches Solaris's AF_INET6 */
JP Abgrall53f17a92014-02-12 14:02:41 -080027
28#ifdef DLT_IPNET
29
30static const struct tok ipnet_values[] = {
31 { IPH_AF_INET, "IPv4" },
32 { IPH_AF_INET6, "IPv6" },
33 { 0, NULL }
34};
35
Elliott Hughes820eced2021-08-20 18:00:50 -070036static void
Elliott Hughes892a68b2015-10-19 14:43:53 -070037ipnet_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length)
JP Abgrall53f17a92014-02-12 14:02:41 -080038{
39 const ipnet_hdr_t *hdr;
40 hdr = (const ipnet_hdr_t *)bp;
41
Elliott Hughes820eced2021-08-20 18:00:50 -070042 ND_PRINT("%u > %u", GET_BE_U_4(hdr->iph_zsrc),
43 GET_BE_U_4(hdr->iph_zdst));
JP Abgrall53f17a92014-02-12 14:02:41 -080044
45 if (!ndo->ndo_qflag) {
Elliott Hughes820eced2021-08-20 18:00:50 -070046 ND_PRINT(", family %s (%u)",
JP Abgrall53f17a92014-02-12 14:02:41 -080047 tok2str(ipnet_values, "Unknown",
Elliott Hughes820eced2021-08-20 18:00:50 -070048 GET_U_1(hdr->iph_family)),
49 GET_U_1(hdr->iph_family));
JP Abgrall53f17a92014-02-12 14:02:41 -080050 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -070051 ND_PRINT(", %s",
JP Abgrall53f17a92014-02-12 14:02:41 -080052 tok2str(ipnet_values,
53 "Unknown Ethertype (0x%04x)",
Elliott Hughes820eced2021-08-20 18:00:50 -070054 GET_U_1(hdr->iph_family)));
JP Abgrall53f17a92014-02-12 14:02:41 -080055 }
56
Elliott Hughes820eced2021-08-20 18:00:50 -070057 ND_PRINT(", length %u: ", length);
JP Abgrall53f17a92014-02-12 14:02:41 -080058}
59
60static void
Elliott Hughes892a68b2015-10-19 14:43:53 -070061ipnet_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
JP Abgrall53f17a92014-02-12 14:02:41 -080062{
Elliott Hughese2e3bd12017-05-15 10:59:29 -070063 const ipnet_hdr_t *hdr;
JP Abgrall53f17a92014-02-12 14:02:41 -080064
Elliott Hughes820eced2021-08-20 18:00:50 -070065 ND_TCHECK_LEN(p, sizeof(ipnet_hdr_t));
66 ndo->ndo_ll_hdr_len += sizeof(ipnet_hdr_t);
JP Abgrall53f17a92014-02-12 14:02:41 -080067
68 if (ndo->ndo_eflag)
69 ipnet_hdr_print(ndo, p, length);
70
71 length -= sizeof(ipnet_hdr_t);
72 caplen -= sizeof(ipnet_hdr_t);
Elliott Hughese2e3bd12017-05-15 10:59:29 -070073 hdr = (const ipnet_hdr_t *)p;
JP Abgrall53f17a92014-02-12 14:02:41 -080074 p += sizeof(ipnet_hdr_t);
75
Elliott Hughes820eced2021-08-20 18:00:50 -070076 switch (GET_U_1(hdr->iph_family)) {
JP Abgrall53f17a92014-02-12 14:02:41 -080077
78 case IPH_AF_INET:
79 ip_print(ndo, p, length);
80 break;
81
JP Abgrall53f17a92014-02-12 14:02:41 -080082 case IPH_AF_INET6:
83 ip6_print(ndo, p, length);
84 break;
JP Abgrall53f17a92014-02-12 14:02:41 -080085
86 default:
87 if (!ndo->ndo_eflag)
Elliott Hughese2e3bd12017-05-15 10:59:29 -070088 ipnet_hdr_print(ndo, (const u_char *)hdr,
JP Abgrall53f17a92014-02-12 14:02:41 -080089 length + sizeof(ipnet_hdr_t));
90
91 if (!ndo->ndo_suppress_default_print)
Elliott Hughes892a68b2015-10-19 14:43:53 -070092 ND_DEFAULTPRINT(p, caplen);
JP Abgrall53f17a92014-02-12 14:02:41 -080093 break;
94 }
95}
96
97/*
98 * This is the top level routine of the printer. 'p' points
99 * to the ether header of the packet, 'h->ts' is the timestamp,
100 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
101 * is the number of bytes actually captured.
102 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700103void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700104ipnet_if_print(netdissect_options *ndo,
JP Abgrall53f17a92014-02-12 14:02:41 -0800105 const struct pcap_pkthdr *h, const u_char *p)
106{
Elliott Hughes820eced2021-08-20 18:00:50 -0700107 ndo->ndo_protocol = "ipnet";
JP Abgrall53f17a92014-02-12 14:02:41 -0800108 ipnet_print(ndo, p, h->len, h->caplen);
JP Abgrall53f17a92014-02-12 14:02:41 -0800109}
JP Abgrall53f17a92014-02-12 14:02:41 -0800110#endif /* DLT_IPNET */