13 #include <netinet/ether.h>
15 #include <linux/netfilter_bridge.h>
16 #include <linux/netfilter/nf_tables.h>
17 #include <libiptc/libxtc.h>
20 #include "xtables-multi.h"
21 #include "nft-bridge.h"
23 #include "nft-shared.h"
25 #define prog_name ebtables_globals.program_name
27 static void print_help(struct iptables_command_state
*cs
)
29 fprintf(stderr
, "%s: Translate ebtables command to nft syntax\n"
30 "no side effects occur, the translated command is written "
31 "to standard output.\n"
32 "A '#' followed by input means no translation "
33 "is available.\n", prog_name
);
37 static void print_ebt_cmd(int argc
, char *argv
[])
42 for (i
= 1; i
< argc
; i
++)
43 printf("%s ", argv
[i
]);
48 static int nft_rule_eb_xlate_add(struct nft_handle
*h
, const struct xt_cmd_parse
*p
,
49 const struct iptables_command_state
*cs
, bool append
)
51 struct xt_xlate
*xl
= xt_xlate_alloc(10240);
52 const char *tick
= cs
->restore
? "" : "'";
55 xt_xlate_add(xl
, "%s%s rule bridge %s %s ", tick
,
56 append
? "add" : "insert", p
->table
, p
->chain
);
58 ret
= h
->ops
->xlate(cs
, xl
);
60 printf("%s%s\n", xt_xlate_get(xl
), tick
);
68 static int do_commandeb_xlate(struct nft_handle
*h
, int argc
, char *argv
[], char **table
)
70 struct iptables_command_state cs
= {
73 .eb
.bitmask
= EBT_NOPROTO
,
75 struct xt_cmd_parse p
= {
78 .ops
= &h
->ops
->cmd_parse
,
80 struct xtables_args args
= {
85 p
.ops
->print_help
= print_help
;
87 do_parse(argc
, argv
, &p
, &cs
, &args
);
89 h
->verbose
= p
.verbose
;
91 /* Do the final checks */
92 if (!nft_table_builtin_find(h
, p
.table
))
93 xtables_error(VERSION_PROBLEM
,
94 "table '%s' does not exist", p
.table
);
100 printf("flush chain bridge %s %s\n", p
.table
, p
.chain
);
102 printf("flush table bridge %s\n", p
.table
);
107 ret
= nft_rule_eb_xlate_add(h
, &p
, &cs
, true);
109 print_ebt_cmd(argc
, argv
);
112 ret
= nft_rule_eb_xlate_add(h
, &p
, &cs
, false);
114 print_ebt_cmd(argc
, argv
);
117 printf("list table bridge %s\n", p
.table
);
121 printf("add chain bridge %s %s\n", p
.table
, p
.chain
);
124 case CMD_DELETE_CHAIN
:
125 printf("delete chain bridge %s %s\n", p
.table
, p
.chain
);
129 printf("flush table bridge %s\n", p
.table
);
138 case CMD_LIST
|CMD_ZERO
:
139 case CMD_LIST
|CMD_ZERO_NUM
:
141 case CMD_LIST_RULES
|CMD_ZERO
:
142 case CMD_LIST_RULES
|CMD_ZERO_NUM
:
143 case CMD_NEW_CHAIN
|CMD_SET_POLICY
:
145 case CMD_RENAME_CHAIN
:
146 case CMD_CHANGE_COUNTERS
:
149 /* We should never reach this... */
150 printf("Unsupported command?\n");
158 static int dummy_compat_rev(const char *name
, uint8_t rev
, int opt
)
163 int xtables_eb_xlate_main(int argc
, char *argv
[])
166 char *table
= "filter";
169 nft_init_eb(&h
, argv
[0]);
170 ebtables_globals
.compat_rev
= dummy_compat_rev
;
172 ret
= do_commandeb_xlate(&h
, argc
, argv
, &table
);
174 fprintf(stderr
, "Translation not implemented\n");