5 * Bart De Schuymer <bdschuym@pandora.be>
14 #include "../include/ebtables_u.h"
15 #include <linux/if_packet.h>
16 #include <linux/netfilter_bridge/ebt_pkttype.h>
30 static struct option opts[] =
32 { "pkttype-type" , required_argument, 0, '1' },
36 static void print_help()
40 "--pkttype-type [!] type: class the packet belongs to\n"
41 "Possible values: broadcast, multicast, host, otherhost any byte value.\n");
44 static void init(struct ebt_entry_match *match)
46 struct ebt_pkttype_info *pt = (struct ebt_pkttype_info *)match->data;
51 static int parse(int c, char **argv, int argc, const struct ebt_u_entry *entry,
52 unsigned int *flags, struct ebt_entry_match **match)
54 struct ebt_pkttype_info *ptinfo = (struct ebt_pkttype_info *)(*match)->data;
60 check_option(flags, 1);
61 if (check_inverse(optarg))
64 print_error("Missing pkttype class specification");
66 i = strtol(argv[optind - 1], &end, 16);
71 if (!strcasecmp(argv[optind - 1], classes[j++])) {
77 print_error("Problem with specified pkttype class");
78 ptinfo->pkt_type = (uint8_t)i;
87 static void final_check(const struct ebt_u_entry *entry,
88 const struct ebt_entry_match *match, const char *name,
89 unsigned int hookmask, unsigned int time)
93 static void print(const struct ebt_u_entry *entry,
94 const struct ebt_entry_match *match)
96 struct ebt_pkttype_info *pt = (struct ebt_pkttype_info *)match->data;
99 printf("--pkttype-type %s", pt->invert ? "! " : "");
100 while (classes[i++][0]);
101 if (pt->pkt_type < i - 1)
102 printf("%s ", classes[pt->pkt_type]);
104 printf("%d ", pt->pkt_type);
107 static int compare(const struct ebt_entry_match *m1,
108 const struct ebt_entry_match *m2)
110 struct ebt_pkttype_info *pt1 = (struct ebt_pkttype_info *)m1->data;
111 struct ebt_pkttype_info *pt2 = (struct ebt_pkttype_info *)m2->data;
113 if (pt1->invert != pt2->invert ||
114 pt1->pkt_type != pt2->pkt_type)
119 static struct ebt_u_match pkttype_match =
121 .name = EBT_PKTTYPE_MATCH,
122 .size = sizeof(struct ebt_pkttype_info),
126 .final_check = final_check,
132 static void _init(void) __attribute((constructor));
133 static void _init(void)
135 register_match(&pkttype_match);