4 #include <netinet/ether.h>
6 #include "../include/ebtables_u.h"
7 #include <linux/netfilter_bridge/ebt_arpreply.h>
9 static int mac_supplied;
12 #define REPLY_TARGET '2'
13 static struct option opts[] =
15 { "arpreply-mac" , required_argument, 0, REPLY_MAC },
16 { "arpreply-target" , required_argument, 0, REPLY_TARGET },
20 static void print_help()
23 "arpreply target options:\n"
24 " --arpreply-mac address : source MAC of generated reply\n"
25 " --arpreply-target target : ACCEPT, DROP, RETURN or CONTINUE\n"
26 " (standard target is DROP)\n");
29 static void init(struct ebt_entry_target *target)
31 struct ebt_arpreply_info *replyinfo =
32 (struct ebt_arpreply_info *)target->data;
34 replyinfo->target = EBT_DROP;
35 memset(replyinfo->mac, 0, ETH_ALEN);
39 #define OPT_REPLY_MAC 0x01
40 #define OPT_REPLY_TARGET 0x02
41 static int parse(int c, char **argv, int argc,
42 const struct ebt_u_entry *entry, unsigned int *flags,
43 struct ebt_entry_target **target)
45 struct ebt_arpreply_info *replyinfo =
46 (struct ebt_arpreply_info *)(*target)->data;
47 struct ether_addr *addr;
51 check_option(flags, OPT_REPLY_MAC);
52 if (!(addr = ether_aton(optarg)))
53 print_error("Problem with specified "
54 "--arpreply-mac mac");
55 memcpy(replyinfo->mac, addr, ETH_ALEN);
59 check_option(flags, OPT_REPLY_TARGET);
60 if (FILL_TARGET(optarg, replyinfo->target))
61 print_error("Illegal --arpreply-target target");
70 static void final_check(const struct ebt_u_entry *entry,
71 const struct ebt_entry_target *target, const char *name,
72 unsigned int hookmask, unsigned int time)
74 struct ebt_arpreply_info *replyinfo =
75 (struct ebt_arpreply_info *)target->data;
77 if (entry->ethproto != ETH_P_ARP || entry->invflags & EBT_IPROTO)
78 print_error("For ARP replying the protocol must be "
80 if (time == 0 && mac_supplied == 0)
81 print_error("No arpreply mac supplied");
82 if (BASE_CHAIN && replyinfo->target == EBT_RETURN)
83 print_error("--arpreply-target RETURN not allowed on "
86 if (strcmp(name, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
87 print_error("arpreply only allowed in PREROUTING");
90 static void print(const struct ebt_u_entry *entry,
91 const struct ebt_entry_target *target)
93 struct ebt_arpreply_info *replyinfo =
94 (struct ebt_arpreply_info *)target->data;
96 printf("--arpreply-mac ");
97 print_mac(replyinfo->mac);
98 if (replyinfo->target == EBT_DROP)
100 printf(" --arpreply-target %s", TARGET_NAME(replyinfo->target));
103 static int compare(const struct ebt_entry_target *t1,
104 const struct ebt_entry_target *t2)
106 struct ebt_arpreply_info *replyinfo1 =
107 (struct ebt_arpreply_info *)t1->data;
108 struct ebt_arpreply_info *replyinfo2 =
109 (struct ebt_arpreply_info *)t2->data;
111 return memcmp(replyinfo1->mac, replyinfo2->mac, ETH_ALEN) == 0
112 && replyinfo1->target == replyinfo2->target;
115 static struct ebt_u_target arpreply_target =
117 .name = EBT_ARPREPLY_TARGET,
118 .size = sizeof(struct ebt_arpreply_info),
122 .final_check = final_check,
128 static void _init(void) __attribute__ ((constructor));
129 static void _init(void)
131 register_target(&arpreply_target);