1 /* Shared library add-on to iptables to add bridge port matching support. */
8 #include <linux/netfilter_ipv6/ip6t_physdev.h>
9 #if defined(__GLIBC__) && __GLIBC__ == 2
10 #include <net/ethernet.h>
12 #include <linux/if_ether.h>
19 "physdev v%s options:\n"
20 " --physdev-in [!] input name[+] bridge port name ([+] for wildcard)\n"
21 " --physdev-out [!] output name[+] bridge port name ([+] for wildcard)\n"
22 " [!] --physdev-is-in arrived on a bridge device\n"
23 " [!] --physdev-is-out will leave on a bridge device\n"
24 " [!] --physdev-is-bridged it's a bridged packet\n"
25 "\n", IPTABLES_VERSION);
28 static struct option opts[] = {
29 { "physdev-in", 1, 0, '1' },
30 { "physdev-out", 1, 0, '2' },
31 { "physdev-is-in", 0, 0, '3' },
32 { "physdev-is-out", 0, 0, '4' },
33 { "physdev-is-bridged", 0, 0, '5' },
38 init(struct ip6t_entry_match *m, unsigned int *nfcache)
43 parse(int c, char **argv, int invert, unsigned int *flags,
44 const struct ip6t_entry *entry,
45 unsigned int *nfcache,
46 struct ip6t_entry_match **match)
48 struct ip6t_physdev_info *info =
49 (struct ip6t_physdev_info*)(*match)->data;
53 if (*flags & IP6T_PHYSDEV_OP_IN)
55 check_inverse(optarg, &invert, &optind, 0);
56 parse_interface(argv[optind-1], info->physindev, info->in_mask);
58 info->invert |= IP6T_PHYSDEV_OP_IN;
59 info->bitmask |= IP6T_PHYSDEV_OP_IN;
60 *flags |= IP6T_PHYSDEV_OP_IN;
64 if (*flags & IP6T_PHYSDEV_OP_OUT)
66 check_inverse(optarg, &invert, &optind, 0);
67 parse_interface(argv[optind-1], info->physoutdev,
70 info->invert |= IP6T_PHYSDEV_OP_OUT;
71 info->bitmask |= IP6T_PHYSDEV_OP_OUT;
72 *flags |= IP6T_PHYSDEV_OP_OUT;
76 if (*flags & IP6T_PHYSDEV_OP_ISIN)
78 check_inverse(optarg, &invert, &optind, 0);
79 info->bitmask |= IP6T_PHYSDEV_OP_ISIN;
81 info->invert |= IP6T_PHYSDEV_OP_ISIN;
82 *flags |= IP6T_PHYSDEV_OP_ISIN;
86 if (*flags & IP6T_PHYSDEV_OP_ISOUT)
88 check_inverse(optarg, &invert, &optind, 0);
89 info->bitmask |= IP6T_PHYSDEV_OP_ISOUT;
91 info->invert |= IP6T_PHYSDEV_OP_ISOUT;
92 *flags |= IP6T_PHYSDEV_OP_ISOUT;
96 if (*flags & IP6T_PHYSDEV_OP_BRIDGED)
98 check_inverse(optarg, &invert, &optind, 0);
100 info->invert |= IP6T_PHYSDEV_OP_BRIDGED;
101 *flags |= IP6T_PHYSDEV_OP_BRIDGED;
102 info->bitmask |= IP6T_PHYSDEV_OP_BRIDGED;
111 exit_error(PARAMETER_PROBLEM,
112 "multiple use of the same physdev option is not allowed");
116 static void final_check(unsigned int flags)
119 exit_error(PARAMETER_PROBLEM, "PHYSDEV: no physdev option specified");
123 print(const struct ip6t_ip6 *ip,
124 const struct ip6t_entry_match *match,
127 struct ip6t_physdev_info *info =
128 (struct ip6t_physdev_info*)match->data;
130 printf("PHYSDEV match");
131 if (info->bitmask & IP6T_PHYSDEV_OP_ISIN)
132 printf("%s --physdev-is-in",
133 info->invert & IP6T_PHYSDEV_OP_ISIN ? " !":"");
134 if (info->bitmask & IP6T_PHYSDEV_OP_IN)
135 printf("%s --physdev-in %s",
136 (info->invert & IP6T_PHYSDEV_OP_IN) ? " !":"", info->physindev);
138 if (info->bitmask & IP6T_PHYSDEV_OP_ISOUT)
139 printf("%s --physdev-is-out",
140 info->invert & IP6T_PHYSDEV_OP_ISOUT ? " !":"");
141 if (info->bitmask & IP6T_PHYSDEV_OP_OUT)
142 printf("%s --physdev-out %s",
143 (info->invert & IP6T_PHYSDEV_OP_OUT) ? " !":"", info->physoutdev);
144 if (info->bitmask & IP6T_PHYSDEV_OP_BRIDGED)
145 printf("%s --physdev-is-bridged",
146 info->invert & IP6T_PHYSDEV_OP_BRIDGED ? " !":"");
150 static void save(const struct ip6t_ip6 *ip, const struct ip6t_entry_match *match)
152 struct ip6t_physdev_info *info =
153 (struct ip6t_physdev_info*)match->data;
155 if (info->bitmask & IP6T_PHYSDEV_OP_ISIN)
156 printf("%s --physdev-is-in",
157 info->invert & IP6T_PHYSDEV_OP_ISIN ? " !":"");
158 if (info->bitmask & IP6T_PHYSDEV_OP_IN)
159 printf("%s --physdev-in %s",
160 (info->invert & IP6T_PHYSDEV_OP_IN) ? " !":"", info->physindev);
162 if (info->bitmask & IP6T_PHYSDEV_OP_ISOUT)
163 printf("%s --physdev-is-out",
164 info->invert & IP6T_PHYSDEV_OP_ISOUT ? " !":"");
165 if (info->bitmask & IP6T_PHYSDEV_OP_OUT)
166 printf("%s --physdev-out %s",
167 (info->invert & IP6T_PHYSDEV_OP_OUT) ? " !":"", info->physoutdev);
168 if (info->bitmask & IP6T_PHYSDEV_OP_BRIDGED)
169 printf("%s --physdev-is-bridged",
170 info->invert & IP6T_PHYSDEV_OP_BRIDGED ? " !":"");
174 static struct ip6tables_match physdev = {
176 .version = IPTABLES_VERSION,
177 .size = IP6T_ALIGN(sizeof(struct ip6t_physdev_info)),
178 .userspacesize = IP6T_ALIGN(sizeof(struct ip6t_physdev_info)),
182 .final_check = &final_check,
190 register_match6(&physdev);