Add a helper function to convert a protocol qualifier number to string,
define a format string and replace 123 hard-coded proto and dir
qualifier error messages with one parametrised message. In the message
say "qualifier" rather than "modifier".
+// protocol qualifier keywords
+static const char *
+pqkw(const unsigned id)
+{
+ const char * tokens[] = {
+ [Q_LINK] = "link",
+ [Q_IP] = "ip",
+ [Q_ARP] = "arp",
+ [Q_RARP] = "rarp",
+ [Q_SCTP] = "sctp",
+ [Q_TCP] = "tcp",
+ [Q_UDP] = "udp",
+ [Q_ICMP] = "icmp",
+ [Q_IGMP] = "igmp",
+ [Q_IGRP] = "igrp",
+ [Q_ATALK] = "atalk",
+ [Q_DECNET] = "decnet",
+ [Q_LAT] = "lat",
+ [Q_SCA] = "sca",
+ [Q_MOPRC] = "moprc",
+ [Q_MOPDL] = "mopdl",
+ [Q_IPV6] = "ip6",
+ [Q_ICMPV6] = "icmp6",
+ [Q_AH] = "ah",
+ [Q_ESP] = "esp",
+ [Q_PIM] = "pim",
+ [Q_VRRP] = "vrrp",
+ [Q_AARP] = "aarp",
+ [Q_ISO] = "iso",
+ [Q_ESIS] = "esis",
+ [Q_ISIS] = "isis",
+ [Q_CLNP] = "clnp",
+ [Q_STP] = "stp",
+ [Q_IPX] = "ipx",
+ [Q_NETBEUI] = "netbeui",
+ [Q_ISIS_L1] = "l1",
+ [Q_ISIS_L2] = "l2",
+ [Q_ISIS_IIH] = "iih",
+ [Q_ISIS_SNP] = "snp",
+ [Q_ISIS_CSNP] = "csnp",
+ [Q_ISIS_PSNP] = "psnp",
+ [Q_ISIS_LSP] = "lsp",
+ [Q_RADIO] = "radio",
+ [Q_CARP] = "carp",
+ };
+ return qual2kw("proto", id, tokens, sizeof(tokens) / sizeof(tokens[0]));
+}
+
// direction qualifier keywords
static const char *
dqkw(const unsigned id)
// direction qualifier keywords
static const char *
dqkw(const unsigned id)
}
#define ERRSTR_802_11_ONLY_KW "'%s' is valid for 802.11 syntax only"
}
#define ERRSTR_802_11_ONLY_KW "'%s' is valid for 802.11 syntax only"
+#define ERRSTR_INVALID_QUAL "'%s' is not a valid qualifier for '%s'"
int
pcap_compile(pcap_t *p, struct bpf_program *program,
int
pcap_compile(pcap_t *p, struct bpf_program *program,
int proto, int dir, int type)
{
struct block *b0, *b1;
int proto, int dir, int type)
{
struct block *b0, *b1;
- const char *typestr;
-
- if (type == Q_NET)
- typestr = "net";
- else
- typestr = "host";
- bpf_error(cstate, "link-layer modifier applied to %s", typestr);
+ break; // invalid qualifier
case Q_IP:
b0 = gen_linktype(cstate, ETHERTYPE_IP);
case Q_IP:
b0 = gen_linktype(cstate, ETHERTYPE_IP);
- bpf_error(cstate, "'sctp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'tcp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'udp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'icmp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'igmp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'igrp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "AppleTalk host filtering not implemented");
+ break; // invalid qualifier
case Q_DECNET:
b0 = gen_linktype(cstate, ETHERTYPE_DN);
case Q_DECNET:
b0 = gen_linktype(cstate, ETHERTYPE_DN);
- bpf_error(cstate, "LAT host filtering not implemented");
-
- bpf_error(cstate, "SCA host filtering not implemented");
-
- bpf_error(cstate, "MOPRC host filtering not implemented");
-
- bpf_error(cstate, "MOPDL host filtering not implemented");
-
- bpf_error(cstate, "'ip6' modifier applied to ip host");
-
- bpf_error(cstate, "'icmp6' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'ah' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'esp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'pim' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'vrrp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "AARP host filtering not implemented");
-
- bpf_error(cstate, "ISO host filtering not implemented");
-
- bpf_error(cstate, "'esis' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'isis' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'clnp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'stp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "IPX host filtering not implemented");
-
- bpf_error(cstate, "'netbeui' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'l1' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'l2' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'iih' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'snp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'csnp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'psnp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'lsp' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'radio' modifier applied to %s", typestr);
-
- bpf_error(cstate, "'carp' modifier applied to %s", typestr);
+ break; // invalid qualifier
+ bpf_error(cstate, ERRSTR_INVALID_QUAL, pqkw(proto),
+ type == Q_NET ? "ip net" : "ip host");
struct in6_addr *mask, int proto, int dir, int type)
{
struct block *b0, *b1;
struct in6_addr *mask, int proto, int dir, int type)
{
struct block *b0, *b1;
- const char *typestr;
-
- if (type == Q_NET)
- typestr = "net";
- else
- typestr = "host";
- bpf_error(cstate, "link-layer modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'ip' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'rarp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'arp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'sctp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'tcp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'udp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'icmp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'igmp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'igrp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "AppleTalk modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'decnet' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'lat' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'sca' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'moprc' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'mopdl' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'icmp6' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'ah' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'esp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'pim' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'vrrp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'aarp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'iso' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'esis' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'isis' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'clnp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'stp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'ipx' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'netbeui' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'l1' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'l2' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'iih' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'snp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'csnp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'psnp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'lsp' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'radio' modifier applied to ip6 %s", typestr);
-
- bpf_error(cstate, "'carp' modifier applied to ip6 %s", typestr);
+ break; // invalid qualifier
+ bpf_error(cstate, ERRSTR_INVALID_QUAL, pqkw(proto),
+ type == Q_NET ? "ip6 net" : "ip6 host");
gen_and(b0, b1);
return b1;
}
gen_and(b0, b1);
return b1;
}
- bpf_error(cstate, "illegal modifier of 'gateway'");
+ bpf_error(cstate, ERRSTR_INVALID_QUAL, pqkw(proto), "gateway");
- bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for ports");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for ports");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for ports");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for ports");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'ra' is not a valid qualifier for ports");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'ta' is not a valid qualifier for ports");
+ bpf_error(cstate, ERRSTR_INVALID_QUAL, dqkw(dir), "port");
- bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for port ranges");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for port ranges");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for port ranges");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for port ranges");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'ra' is not a valid qualifier for port ranges");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'ta' is not a valid qualifier for port ranges");
+ bpf_error(cstate, ERRSTR_INVALID_QUAL, dqkw(dir), "portrange");
gen_or(b0, b);
return b;
default:
gen_or(b0, b);
return b;
default:
- bpf_error(cstate, "bad protocol applied for 'protochain'");
+ bpf_error(cstate, ERRSTR_INVALID_QUAL, pqkw(proto), "protochain");
- bpf_error(cstate, "arp does not encapsulate another protocol");
- /*NOTREACHED*/
-
- bpf_error(cstate, "rarp does not encapsulate another protocol");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'sctp proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'tcp proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'udp proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'icmp proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'igmp proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'igrp proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "AppleTalk encapsulation is not specifiable");
- /*NOTREACHED*/
-
- bpf_error(cstate, "DECNET encapsulation is not specifiable");
- /*NOTREACHED*/
-
- bpf_error(cstate, "LAT does not encapsulate another protocol");
- /*NOTREACHED*/
-
- bpf_error(cstate, "SCA does not encapsulate another protocol");
- /*NOTREACHED*/
-
- bpf_error(cstate, "MOPRC does not encapsulate another protocol");
- /*NOTREACHED*/
-
- bpf_error(cstate, "MOPDL does not encapsulate another protocol");
- /*NOTREACHED*/
+ break; // invalid qualifier
case Q_IPV6:
b0 = gen_linktype(cstate, ETHERTYPE_IPV6);
case Q_IPV6:
b0 = gen_linktype(cstate, ETHERTYPE_IPV6);
return b1;
case Q_ICMPV6:
return b1;
case Q_ICMPV6:
- bpf_error(cstate, "'icmp6 proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'ah proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'esp proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'pim proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'vrrp proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'aarp proto' is bogus");
- /*NOTREACHED*/
+ break; // invalid qualifier
case Q_ISO:
switch (cstate->linktype) {
case Q_ISO:
switch (cstate->linktype) {
- bpf_error(cstate, "'esis proto' is bogus");
- /*NOTREACHED*/
+ break; // invalid qualifier
case Q_ISIS:
b0 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT);
case Q_ISIS:
b0 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT);
- bpf_error(cstate, "'clnp proto' is not supported");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'stp proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'ipx proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'netbeui proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'l1 proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'l2 proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'iih proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'snp proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'csnp proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'psnp proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'lsp proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'radio proto' is bogus");
- /*NOTREACHED*/
-
- bpf_error(cstate, "'carp proto' is bogus");
- /*NOTREACHED*/
+ break; // invalid qualifier
default:
abort();
/*NOTREACHED*/
}
default:
abort();
/*NOTREACHED*/
}
+ bpf_error(cstate, ERRSTR_INVALID_QUAL, pqkw(proto), "proto");
gen_and(b0, b2);
return b2;
}
gen_and(b0, b2);
return b2;
}
- bpf_error(cstate, "only link-layer/IP broadcast filters supported");
+ bpf_error(cstate, ERRSTR_INVALID_QUAL, pqkw(proto), "broadcast");
gen_and(b0, b1);
return b1;
}
gen_and(b0, b1);
return b1;
}
- bpf_error(cstate, "link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/802.11/ATM LANE/Fibre Channel");
+ bpf_error(cstate, ERRSTR_INVALID_QUAL, pqkw(proto), "multicast");
skip => skip_config_def1 ('NO_PROTOCHAIN'),
DLT => 'EN10MB',
expr => 'arp protochain 17',
skip => skip_config_def1 ('NO_PROTOCHAIN'),
DLT => 'EN10MB',
expr => 'arp protochain 17',
- errstr => 'bad protocol applied for \'protochain\'',
+ errstr => '\'arp\' is not a valid qualifier for \'protochain\'',
},
{
name => 'arp_proto',
DLT => 'EN10MB',
expr => 'arp proto 17',
},
{
name => 'arp_proto',
DLT => 'EN10MB',
expr => 'arp proto 17',
- errstr => 'arp does not encapsulate another protocol',
+ errstr => '\'arp\' is not a valid qualifier for \'proto\'',
},
{
name => 'arp_host_ipv4_ipv6',
},
{
name => 'arp_host_ipv4_ipv6',
skip_no_hosts(),
DLT => 'FDDI',
expr => 'arp host eth-ipv4-ipv6.host123.libpcap.test',
skip_no_hosts(),
DLT => 'FDDI',
expr => 'arp host eth-ipv4-ipv6.host123.libpcap.test',
- errstr => '\'arp\' modifier applied to ip6 host',
+ errstr => '\'arp\' is not a valid qualifier for \'ip6 host\'',
},
{
name => 'rarp_host_ipv4_ipv6',
},
{
name => 'rarp_host_ipv4_ipv6',
skip_no_hosts(),
DLT => 'FDDI',
expr => 'rarp host eth-ipv4-ipv6.host123.libpcap.test',
skip_no_hosts(),
DLT => 'FDDI',
expr => 'rarp host eth-ipv4-ipv6.host123.libpcap.test',
- errstr => '\'rarp\' modifier applied to ip6 host',
+ errstr => '\'rarp\' is not a valid qualifier for \'ip6 host\'',
},
{
name => 'arp_host_noipv4_noipv6',
},
{
name => 'arp_host_noipv4_noipv6',
skip_no_hosts(),
DLT => 'EN10MB',
expr => "ip6 gateway eth-ipv4-ipv6.host123.libpcap.test",
skip_no_hosts(),
DLT => 'EN10MB',
expr => "ip6 gateway eth-ipv4-ipv6.host123.libpcap.test",
- errstr => 'illegal modifier of \'gateway\'',
+ errstr => '\'ip6\' is not a valid qualifier for \'gateway\'',
},
{
name => 'gateway_1',
},
{
name => 'gateway_1',