1 /* ebt_arpreply
2 *
3 * Authors:
4 * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
5 * Bart De Schuymer <bdschuym@pandora.be>
6 *
7 * August, 2003
8 */
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <xtables.h>
14 #include <netinet/ether.h>
15 #include <linux/netfilter_bridge/ebt_arpreply.h>
16 #include "iptables/nft.h"
17 #include "iptables/nft-bridge.h"
18
19 enum {
20 O_MAC,
21 O_TARGET,
22 };
23
24 static const struct xt_option_entry brarpreply_opts[] = {
25 { .name = "arpreply-mac" , .id = O_MAC, .type = XTTYPE_ETHERMAC,
26 .flags = XTOPT_PUT, XTOPT_POINTER(struct ebt_arpreply_info, mac) },
27 { .name = "arpreply-target" , .id = O_TARGET, .type = XTTYPE_STRING },
28 XTOPT_TABLEEND,
29 };
30
brarpreply_print_help(void)31 static void brarpreply_print_help(void)
32 {
33 printf(
34 "arpreply target options:\n"
35 " --arpreply-mac address : source MAC of generated reply\n"
36 " --arpreply-target target : ACCEPT, DROP, RETURN or CONTINUE\n"
37 " (standard target is DROP)\n");
38 }
39
brarpreply_init(struct xt_entry_target * target)40 static void brarpreply_init(struct xt_entry_target *target)
41 {
42 struct ebt_arpreply_info *replyinfo = (void *)target->data;
43
44 replyinfo->target = EBT_DROP;
45 }
46
brarpreply_parse(struct xt_option_call * cb)47 static void brarpreply_parse(struct xt_option_call *cb)
48 {
49 struct ebt_arpreply_info *replyinfo = cb->data;
50
51 xtables_option_parse(cb);
52 if (cb->entry->id == O_TARGET &&
53 ebt_fill_target(cb->arg, (unsigned int *)&replyinfo->target))
54 xtables_error(PARAMETER_PROBLEM,
55 "Illegal --arpreply-target target");
56 }
57
brarpreply_print(const void * ip,const struct xt_entry_target * t,int numeric)58 static void brarpreply_print(const void *ip, const struct xt_entry_target *t, int numeric)
59 {
60 struct ebt_arpreply_info *replyinfo = (void *)t->data;
61
62 printf("--arpreply-mac ");
63 xtables_print_mac(replyinfo->mac);
64 if (replyinfo->target == EBT_DROP)
65 return;
66 printf(" --arpreply-target %s", ebt_target_name(replyinfo->target));
67 }
68
69 static struct xtables_target arpreply_target = {
70 .name = "arpreply",
71 .version = XTABLES_VERSION,
72 .family = NFPROTO_BRIDGE,
73 .init = brarpreply_init,
74 .size = XT_ALIGN(sizeof(struct ebt_arpreply_info)),
75 .userspacesize = XT_ALIGN(sizeof(struct ebt_arpreply_info)),
76 .help = brarpreply_print_help,
77 .x6_parse = brarpreply_parse,
78 .print = brarpreply_print,
79 .x6_options = brarpreply_opts,
80 };
81
_init(void)82 void _init(void)
83 {
84 xtables_register_target(&arpreply_target);
85 }
86