4 #include <netinet/in.h>
5 //#include <linux/netfilter_bridge/ebtables.h>
6 #include <linux/netfilter/x_tables.h>
7 #include <linux/netfilter/nf_tables.h>
8 #include <net/ethernet.h>
9 #include <libiptc/libxtc.h>
11 extern unsigned char eb_mac_type_unicast
[ETH_ALEN
];
12 extern unsigned char eb_msk_type_unicast
[ETH_ALEN
];
13 extern unsigned char eb_mac_type_multicast
[ETH_ALEN
];
14 extern unsigned char eb_msk_type_multicast
[ETH_ALEN
];
15 extern unsigned char eb_mac_type_broadcast
[ETH_ALEN
];
16 extern unsigned char eb_msk_type_broadcast
[ETH_ALEN
];
17 extern unsigned char eb_mac_type_bridge_group
[ETH_ALEN
];
18 extern unsigned char eb_msk_type_bridge_group
[ETH_ALEN
];
20 int ebt_get_mac_and_mask(const char *from
, unsigned char *to
, unsigned char *mask
);
22 /* From: include/linux/netfilter_bridge/ebtables.h
24 * Adapted for the need of the ebtables-compat.
27 #define EBT_TABLE_MAXNAMELEN 32
28 #define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN
30 /* verdicts >0 are "branches" */
33 #define EBT_CONTINUE -3
35 #define NUM_STANDARD_TARGETS 4
37 #define EBT_ENTRY_OR_ENTRIES 0x01
38 /* these are the normal masks */
39 #define EBT_NOPROTO 0x02
40 #define EBT_802_3 0x04
41 #define EBT_SOURCEMAC 0x08
42 #define EBT_DESTMAC 0x10
43 #define EBT_F_MASK (EBT_NOPROTO | EBT_802_3 | EBT_SOURCEMAC | EBT_DESTMAC \
44 | EBT_ENTRY_OR_ENTRIES)
46 #define EBT_IPROTO 0x01
49 #define EBT_ISOURCE 0x8
50 #define EBT_IDEST 0x10
51 #define EBT_ILOGICALIN 0x20
52 #define EBT_ILOGICALOUT 0x40
53 #define EBT_INV_MASK (EBT_IPROTO | EBT_IIN | EBT_IOUT | EBT_ILOGICALIN \
54 | EBT_ILOGICALOUT | EBT_ISOURCE | EBT_IDEST)
56 /* ebtables target modules store the verdict inside an int. We can
57 * reclaim a part of this int for backwards compatible extensions.
58 * The 4 lsb are more than enough to store the verdict.
60 #define EBT_VERDICT_BITS 0x0000000F
63 struct iptables_command_state
;
65 static const char *ebt_standard_targets
[NUM_STANDARD_TARGETS
] = {
72 static inline const char *nft_ebt_standard_target(unsigned int num
)
74 if (num
>= NUM_STANDARD_TARGETS
)
77 return ebt_standard_targets
[num
];
80 static inline int ebt_fill_target(const char *str
, unsigned int *verdict
)
84 for (i
= 0; i
< NUM_STANDARD_TARGETS
; i
++) {
85 if (!strcmp(str
, nft_ebt_standard_target(i
))) {
91 if (i
== NUM_STANDARD_TARGETS
)
97 static inline const char *ebt_target_name(unsigned int verdict
)
99 return nft_ebt_standard_target(-verdict
- 1);
102 #define EBT_CHECK_OPTION(flags, mask) ({ \
104 xtables_error(PARAMETER_PROBLEM, \
105 "Multiple use of same " \
106 "option not allowed"); \
110 void ebt_cs_clean(struct iptables_command_state *cs);
111 struct xtables_match
*ebt_add_match(struct xtables_match
*m
,
112 struct iptables_command_state
*cs
);
113 struct xtables_target
*ebt_add_watcher(struct xtables_target
*watcher
,
114 struct iptables_command_state
*cs
);
115 int ebt_command_default(struct iptables_command_state
*cs
,
116 struct xtables_globals
*unused
, bool ebt_invert
);
118 struct nft_among_pair
{
119 struct ether_addr ether
;
120 struct in_addr in
__attribute__((aligned (4)));
123 struct nft_among_data
{
129 /* first source, then dest pairs */
130 struct nft_among_pair pairs
[0];
133 /* initialize fields, return offset into pairs array to write pairs to */
135 nft_among_prepare_data(struct nft_among_data
*data
, bool dst
,
136 size_t cnt
, bool inv
, bool ip
)
144 poff
= data
->src
.cnt
;
150 memmove(data
->pairs
+ cnt
, data
->pairs
,
151 data
->dst
.cnt
* sizeof(*data
->pairs
));
157 nft_among_insert_pair(struct nft_among_pair
*pairs
,
158 size_t *pcount
, const struct nft_among_pair
*new)
162 /* nftables automatically sorts set elements from smallest to largest,
163 * insert sorted so extension comparison works */
165 for (i
= 0; i
< *pcount
; i
++) {
166 if (memcmp(new, &pairs
[i
], sizeof(*new)) < 0)
169 memmove(&pairs
[i
+ 1], &pairs
[i
], sizeof(*pairs
) * (*pcount
- i
));
170 memcpy(&pairs
[i
], new, sizeof(*new));
174 /* from xtables-eb.c */
175 void nft_bridge_print_help(struct iptables_command_state
*cs
);