• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <getopt.h>
14 #include <xtables.h>
15 #include <netinet/ether.h>
16 #include <linux/netfilter_bridge/ebt_arpreply.h>
17 #include "iptables/nft.h"
18 #include "iptables/nft-bridge.h"
19 
20 #define OPT_REPLY_MAC     0x01
21 #define OPT_REPLY_TARGET  0x02
22 
23 #define REPLY_MAC '1'
24 #define REPLY_TARGET '2'
25 static const struct option brarpreply_opts[] = {
26 	{ "arpreply-mac" ,    required_argument, 0, REPLY_MAC    },
27 	{ "arpreply-target" , required_argument, 0, REPLY_TARGET },
28 	XT_GETOPT_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 
47 static int
brarpreply_parse(int c,char ** argv,int invert,unsigned int * flags,const void * entry,struct xt_entry_target ** tg)48 brarpreply_parse(int c, char **argv, int invert, unsigned int *flags,
49 	    const void *entry, struct xt_entry_target **tg)
50 
51 {
52 	struct ebt_arpreply_info *replyinfo = (void *)(*tg)->data;
53 	struct ether_addr *addr;
54 
55 	switch (c) {
56 	case REPLY_MAC:
57 		EBT_CHECK_OPTION(flags, OPT_REPLY_MAC);
58 		if (!(addr = ether_aton(optarg)))
59 			xtables_error(PARAMETER_PROBLEM, "Problem with specified --arpreply-mac mac");
60 		memcpy(replyinfo->mac, addr, ETH_ALEN);
61 		break;
62 	case REPLY_TARGET:
63 		EBT_CHECK_OPTION(flags, OPT_REPLY_TARGET);
64 		if (ebt_fill_target(optarg, (unsigned int *)&replyinfo->target))
65 			xtables_error(PARAMETER_PROBLEM, "Illegal --arpreply-target target");
66 		break;
67 
68 	default:
69 		return 0;
70 	}
71 	return 1;
72 }
73 
brarpreply_print(const void * ip,const struct xt_entry_target * t,int numeric)74 static void brarpreply_print(const void *ip, const struct xt_entry_target *t, int numeric)
75 {
76 	struct ebt_arpreply_info *replyinfo = (void *)t->data;
77 
78 	printf("--arpreply-mac ");
79 	xtables_print_mac(replyinfo->mac);
80 	if (replyinfo->target == EBT_DROP)
81 		return;
82 	printf(" --arpreply-target %s", ebt_target_name(replyinfo->target));
83 }
84 
85 static struct xtables_target arpreply_target = {
86 	.name		= "arpreply",
87 	.version	= XTABLES_VERSION,
88 	.family		= NFPROTO_BRIDGE,
89 	.init		= brarpreply_init,
90 	.size		= XT_ALIGN(sizeof(struct ebt_arpreply_info)),
91 	.userspacesize	= XT_ALIGN(sizeof(struct ebt_arpreply_info)),
92 	.help		= brarpreply_print_help,
93 	.parse		= brarpreply_parse,
94 	.print		= brarpreply_print,
95 	.extra_opts	= brarpreply_opts,
96 };
97 
_init(void)98 void _init(void)
99 {
100 	xtables_register_target(&arpreply_target);
101 }
102