Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Pkg Iptables
Commits
290749d4
Commit
290749d4
authored
Dec 03, 2019
by
Arturo Borrero Gonzalez
Browse files
New upstream version 1.8.4
parent
89c92f0c
Changes
87
Expand all
Hide whitespace changes
Inline
Side-by-side
iptables/nft-cache.h
0 → 100644
View file @
290749d4
#ifndef _NFT_CACHE_H_
#define _NFT_CACHE_H_
struct
nft_handle
;
void
nft_fake_cache
(
struct
nft_handle
*
h
);
void
nft_build_cache
(
struct
nft_handle
*
h
,
struct
nftnl_chain
*
c
);
void
nft_rebuild_cache
(
struct
nft_handle
*
h
);
void
nft_release_cache
(
struct
nft_handle
*
h
);
void
flush_chain_cache
(
struct
nft_handle
*
h
,
const
char
*
tablename
);
int
flush_rule_cache
(
struct
nft_handle
*
h
,
const
char
*
table
,
struct
nftnl_chain
*
c
);
struct
nftnl_chain_list
*
nft_chain_list_get
(
struct
nft_handle
*
h
,
const
char
*
table
,
const
char
*
chain
);
struct
nftnl_set_list
*
nft_set_list_get
(
struct
nft_handle
*
h
,
const
char
*
table
,
const
char
*
set
);
struct
nftnl_table_list
*
nftnl_table_list_get
(
struct
nft_handle
*
h
);
#endif
/* _NFT_CACHE_H_ */
iptables/nft-ipv4.c
View file @
290749d4
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
#include "nft.h"
#include "nft.h"
#include "nft-shared.h"
#include "nft-shared.h"
static
int
nft_ipv4_add
(
struct
nftnl_rule
*
r
,
void
*
data
)
static
int
nft_ipv4_add
(
struct
nft_handle
*
h
,
struct
nftnl_rule
*
r
,
void
*
data
)
{
{
struct
iptables_command_state
*
cs
=
data
;
struct
iptables_command_state
*
cs
=
data
;
struct
xtables_rule_match
*
matchp
;
struct
xtables_rule_match
*
matchp
;
...
@@ -77,7 +77,7 @@ static int nft_ipv4_add(struct nftnl_rule *r, void *data)
...
@@ -77,7 +77,7 @@ static int nft_ipv4_add(struct nftnl_rule *r, void *data)
add_compat
(
r
,
cs
->
fw
.
ip
.
proto
,
cs
->
fw
.
ip
.
invflags
&
XT_INV_PROTO
);
add_compat
(
r
,
cs
->
fw
.
ip
.
proto
,
cs
->
fw
.
ip
.
invflags
&
XT_INV_PROTO
);
for
(
matchp
=
cs
->
matches
;
matchp
;
matchp
=
matchp
->
next
)
{
for
(
matchp
=
cs
->
matches
;
matchp
;
matchp
=
matchp
->
next
)
{
ret
=
add_match
(
r
,
matchp
->
match
->
m
);
ret
=
add_match
(
h
,
r
,
matchp
->
match
->
m
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
ret
;
return
ret
;
}
}
...
@@ -261,12 +261,12 @@ static void print_fragment(unsigned int flags, unsigned int invflags,
...
@@ -261,12 +261,12 @@ static void print_fragment(unsigned int flags, unsigned int invflags,
fputc
(
' '
,
stdout
);
fputc
(
' '
,
stdout
);
}
}
static
void
nft_ipv4_print_rule
(
struct
nft
nl_ru
le
*
r
,
unsigned
int
num
,
static
void
nft_ipv4_print_rule
(
struct
nft
_hand
le
*
h
,
struct
nftnl_rule
*
r
,
unsigned
int
format
)
unsigned
int
num
,
unsigned
int
format
)
{
{
struct
iptables_command_state
cs
=
{};
struct
iptables_command_state
cs
=
{};
nft_rule_to_iptables_command_state
(
r
,
&
cs
);
nft_rule_to_iptables_command_state
(
h
,
r
,
&
cs
);
print_rule_details
(
&
cs
,
cs
.
jumpto
,
cs
.
fw
.
ip
.
flags
,
print_rule_details
(
&
cs
,
cs
.
jumpto
,
cs
.
fw
.
ip
.
flags
,
cs
.
fw
.
ip
.
invflags
,
cs
.
fw
.
ip
.
proto
,
num
,
format
);
cs
.
fw
.
ip
.
invflags
,
cs
.
fw
.
ip
.
proto
,
num
,
format
);
...
...
iptables/nft-ipv6.c
View file @
290749d4
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
#include "nft.h"
#include "nft.h"
#include "nft-shared.h"
#include "nft-shared.h"
static
int
nft_ipv6_add
(
struct
nftnl_rule
*
r
,
void
*
data
)
static
int
nft_ipv6_add
(
struct
nft_handle
*
h
,
struct
nftnl_rule
*
r
,
void
*
data
)
{
{
struct
iptables_command_state
*
cs
=
data
;
struct
iptables_command_state
*
cs
=
data
;
struct
xtables_rule_match
*
matchp
;
struct
xtables_rule_match
*
matchp
;
...
@@ -66,7 +66,7 @@ static int nft_ipv6_add(struct nftnl_rule *r, void *data)
...
@@ -66,7 +66,7 @@ static int nft_ipv6_add(struct nftnl_rule *r, void *data)
add_compat
(
r
,
cs
->
fw6
.
ipv6
.
proto
,
cs
->
fw6
.
ipv6
.
invflags
&
XT_INV_PROTO
);
add_compat
(
r
,
cs
->
fw6
.
ipv6
.
proto
,
cs
->
fw6
.
ipv6
.
invflags
&
XT_INV_PROTO
);
for
(
matchp
=
cs
->
matches
;
matchp
;
matchp
=
matchp
->
next
)
{
for
(
matchp
=
cs
->
matches
;
matchp
;
matchp
=
matchp
->
next
)
{
ret
=
add_match
(
r
,
matchp
->
match
->
m
);
ret
=
add_match
(
h
,
r
,
matchp
->
match
->
m
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
ret
;
return
ret
;
}
}
...
@@ -187,12 +187,12 @@ static void nft_ipv6_parse_immediate(const char *jumpto, bool nft_goto,
...
@@ -187,12 +187,12 @@ static void nft_ipv6_parse_immediate(const char *jumpto, bool nft_goto,
cs
->
fw6
.
ipv6
.
flags
|=
IP6T_F_GOTO
;
cs
->
fw6
.
ipv6
.
flags
|=
IP6T_F_GOTO
;
}
}
static
void
nft_ipv6_print_rule
(
struct
nft
nl_ru
le
*
r
,
unsigned
int
num
,
static
void
nft_ipv6_print_rule
(
struct
nft
_hand
le
*
h
,
struct
nftnl_rule
*
r
,
unsigned
int
format
)
unsigned
int
num
,
unsigned
int
format
)
{
{
struct
iptables_command_state
cs
=
{};
struct
iptables_command_state
cs
=
{};
nft_rule_to_iptables_command_state
(
r
,
&
cs
);
nft_rule_to_iptables_command_state
(
h
,
r
,
&
cs
);
print_rule_details
(
&
cs
,
cs
.
jumpto
,
cs
.
fw6
.
ipv6
.
flags
,
print_rule_details
(
&
cs
,
cs
.
jumpto
,
cs
.
fw6
.
ipv6
.
flags
,
cs
.
fw6
.
ipv6
.
invflags
,
cs
.
fw6
.
ipv6
.
proto
,
cs
.
fw6
.
ipv6
.
invflags
,
cs
.
fw6
.
ipv6
.
proto
,
...
...
iptables/nft-shared.c
View file @
290749d4
...
@@ -69,7 +69,7 @@ void add_payload(struct nftnl_rule *r, int offset, int len, uint32_t base)
...
@@ -69,7 +69,7 @@ void add_payload(struct nftnl_rule *r, int offset, int len, uint32_t base)
}
}
/* bitwise operation is = sreg & mask ^ xor */
/* bitwise operation is = sreg & mask ^ xor */
void
add_bitwise_u16
(
struct
nftnl_rule
*
r
,
int
mask
,
int
xor
)
void
add_bitwise_u16
(
struct
nftnl_rule
*
r
,
u
int
16_t
mask
,
u
int
16_t
xor
)
{
{
struct
nftnl_expr
*
expr
;
struct
nftnl_expr
*
expr
;
...
@@ -310,7 +310,6 @@ static void nft_parse_target(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
...
@@ -310,7 +310,6 @@ static void nft_parse_target(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
struct
xtables_target
*
target
;
struct
xtables_target
*
target
;
struct
xt_entry_target
*
t
;
struct
xt_entry_target
*
t
;
size_t
size
;
size_t
size
;
struct
nft_family_ops
*
ops
;
void
*
data
=
ctx
->
cs
;
void
*
data
=
ctx
->
cs
;
target
=
xtables_find_target
(
targname
,
XTF_TRY_LOAD
);
target
=
xtables_find_target
(
targname
,
XTF_TRY_LOAD
);
...
@@ -327,8 +326,7 @@ static void nft_parse_target(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
...
@@ -327,8 +326,7 @@ static void nft_parse_target(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
target
->
t
=
t
;
target
->
t
=
t
;
ops
=
nft_family_ops_lookup
(
ctx
->
family
);
ctx
->
h
->
ops
->
parse_target
(
target
,
data
);
ops
->
parse_target
(
target
,
data
);
}
}
static
void
nft_parse_match
(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
)
static
void
nft_parse_match
(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
)
...
@@ -339,9 +337,8 @@ static void nft_parse_match(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
...
@@ -339,9 +337,8 @@ static void nft_parse_match(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
struct
xtables_match
*
match
;
struct
xtables_match
*
match
;
struct
xtables_rule_match
**
matches
;
struct
xtables_rule_match
**
matches
;
struct
xt_entry_match
*
m
;
struct
xt_entry_match
*
m
;
struct
nft_family_ops
*
ops
;
switch
(
ctx
->
family
)
{
switch
(
ctx
->
h
->
family
)
{
case
NFPROTO_IPV4
:
case
NFPROTO_IPV4
:
case
NFPROTO_IPV6
:
case
NFPROTO_IPV6
:
case
NFPROTO_BRIDGE
:
case
NFPROTO_BRIDGE
:
...
@@ -349,7 +346,7 @@ static void nft_parse_match(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
...
@@ -349,7 +346,7 @@ static void nft_parse_match(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
break
;
break
;
default:
default:
fprintf
(
stderr
,
"BUG: nft_parse_match() unknown family %d
\n
"
,
fprintf
(
stderr
,
"BUG: nft_parse_match() unknown family %d
\n
"
,
ctx
->
family
);
ctx
->
h
->
family
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
@@ -365,9 +362,8 @@ static void nft_parse_match(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
...
@@ -365,9 +362,8 @@ static void nft_parse_match(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
match
->
m
=
m
;
match
->
m
=
m
;
ops
=
nft_family_ops_lookup
(
ctx
->
family
);
if
(
ctx
->
h
->
ops
->
parse_match
!=
NULL
)
if
(
ops
->
parse_match
!=
NULL
)
ctx
->
h
->
ops
->
parse_match
(
match
,
ctx
->
cs
);
ops
->
parse_match
(
match
,
ctx
->
cs
);
}
}
void
print_proto
(
uint16_t
proto
,
int
invert
)
void
print_proto
(
uint16_t
proto
,
int
invert
)
...
@@ -400,7 +396,6 @@ void get_cmp_data(struct nftnl_expr *e, void *data, size_t dlen, bool *inv)
...
@@ -400,7 +396,6 @@ void get_cmp_data(struct nftnl_expr *e, void *data, size_t dlen, bool *inv)
static
void
nft_meta_set_to_target
(
struct
nft_xt_ctx
*
ctx
)
static
void
nft_meta_set_to_target
(
struct
nft_xt_ctx
*
ctx
)
{
{
const
struct
nft_family_ops
*
ops
;
struct
xtables_target
*
target
;
struct
xtables_target
*
target
;
struct
xt_entry_target
*
t
;
struct
xt_entry_target
*
t
;
unsigned
int
size
;
unsigned
int
size
;
...
@@ -429,8 +424,7 @@ static void nft_meta_set_to_target(struct nft_xt_ctx *ctx)
...
@@ -429,8 +424,7 @@ static void nft_meta_set_to_target(struct nft_xt_ctx *ctx)
target
->
t
=
t
;
target
->
t
=
t
;
ops
=
nft_family_ops_lookup
(
ctx
->
family
);
ctx
->
h
->
ops
->
parse_target
(
target
,
ctx
->
cs
);
ops
->
parse_target
(
target
,
ctx
->
cs
);
}
}
static
void
nft_parse_meta
(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
)
static
void
nft_parse_meta
(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
)
...
@@ -451,8 +445,16 @@ static void nft_parse_meta(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
...
@@ -451,8 +445,16 @@ static void nft_parse_meta(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
static
void
nft_parse_payload
(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
)
static
void
nft_parse_payload
(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
)
{
{
if
(
ctx
->
flags
&
NFT_XT_CTX_PAYLOAD
)
{
memcpy
(
&
ctx
->
prev_payload
,
&
ctx
->
payload
,
sizeof
(
ctx
->
prev_payload
));
ctx
->
flags
|=
NFT_XT_CTX_PREV_PAYLOAD
;
}
ctx
->
reg
=
nftnl_expr_get_u32
(
e
,
NFTNL_EXPR_META_DREG
);
ctx
->
reg
=
nftnl_expr_get_u32
(
e
,
NFTNL_EXPR_META_DREG
);
ctx
->
payload
.
base
=
nftnl_expr_get_u32
(
e
,
NFTNL_EXPR_PAYLOAD_BASE
);
ctx
->
payload
.
offset
=
nftnl_expr_get_u32
(
e
,
NFTNL_EXPR_PAYLOAD_OFFSET
);
ctx
->
payload
.
offset
=
nftnl_expr_get_u32
(
e
,
NFTNL_EXPR_PAYLOAD_OFFSET
);
ctx
->
payload
.
len
=
nftnl_expr_get_u32
(
e
,
NFTNL_EXPR_PAYLOAD_LEN
);
ctx
->
flags
|=
NFT_XT_CTX_PAYLOAD
;
ctx
->
flags
|=
NFT_XT_CTX_PAYLOAD
;
}
}
...
@@ -474,7 +476,6 @@ static void nft_parse_bitwise(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
...
@@ -474,7 +476,6 @@ static void nft_parse_bitwise(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
static
void
nft_parse_cmp
(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
)
static
void
nft_parse_cmp
(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
)
{
{
struct
nft_family_ops
*
ops
=
nft_family_ops_lookup
(
ctx
->
family
);
void
*
data
=
ctx
->
cs
;
void
*
data
=
ctx
->
cs
;
uint32_t
reg
;
uint32_t
reg
;
...
@@ -483,12 +484,12 @@ static void nft_parse_cmp(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
...
@@ -483,12 +484,12 @@ static void nft_parse_cmp(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
return
;
return
;
if
(
ctx
->
flags
&
NFT_XT_CTX_META
)
{
if
(
ctx
->
flags
&
NFT_XT_CTX_META
)
{
ops
->
parse_meta
(
ctx
,
e
,
data
);
ctx
->
h
->
ops
->
parse_meta
(
ctx
,
e
,
data
);
ctx
->
flags
&=
~
NFT_XT_CTX_META
;
ctx
->
flags
&=
~
NFT_XT_CTX_META
;
}
}
/* bitwise context is interpreted from payload */
/* bitwise context is interpreted from payload */
if
(
ctx
->
flags
&
NFT_XT_CTX_PAYLOAD
)
{
if
(
ctx
->
flags
&
NFT_XT_CTX_PAYLOAD
)
{
ops
->
parse_payload
(
ctx
,
e
,
data
);
ctx
->
h
->
ops
->
parse_payload
(
ctx
,
e
,
data
);
ctx
->
flags
&=
~
NFT_XT_CTX_PAYLOAD
;
ctx
->
flags
&=
~
NFT_XT_CTX_PAYLOAD
;
}
}
}
}
...
@@ -502,7 +503,6 @@ static void nft_parse_counter(struct nftnl_expr *e, struct xt_counters *counters
...
@@ -502,7 +503,6 @@ static void nft_parse_counter(struct nftnl_expr *e, struct xt_counters *counters
static
void
nft_parse_immediate
(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
)
static
void
nft_parse_immediate
(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
)
{
{
const
char
*
chain
=
nftnl_expr_get_str
(
e
,
NFTNL_EXPR_IMM_CHAIN
);
const
char
*
chain
=
nftnl_expr_get_str
(
e
,
NFTNL_EXPR_IMM_CHAIN
);
struct
nft_family_ops
*
ops
;
const
char
*
jumpto
=
NULL
;
const
char
*
jumpto
=
NULL
;
bool
nft_goto
=
false
;
bool
nft_goto
=
false
;
void
*
data
=
ctx
->
cs
;
void
*
data
=
ctx
->
cs
;
...
@@ -544,8 +544,7 @@ static void nft_parse_immediate(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
...
@@ -544,8 +544,7 @@ static void nft_parse_immediate(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
break
;
break
;
}
}
ops
=
nft_family_ops_lookup
(
ctx
->
family
);
ctx
->
h
->
ops
->
parse_immediate
(
jumpto
,
nft_goto
,
data
);
ops
->
parse_immediate
(
jumpto
,
nft_goto
,
data
);
}
}
static
void
nft_parse_limit
(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
)
static
void
nft_parse_limit
(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
)
...
@@ -555,19 +554,18 @@ static void nft_parse_limit(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
...
@@ -555,19 +554,18 @@ static void nft_parse_limit(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
__u64
rate
=
nftnl_expr_get_u64
(
e
,
NFTNL_EXPR_LIMIT_RATE
);
__u64
rate
=
nftnl_expr_get_u64
(
e
,
NFTNL_EXPR_LIMIT_RATE
);
struct
xtables_rule_match
**
matches
;
struct
xtables_rule_match
**
matches
;
struct
xtables_match
*
match
;
struct
xtables_match
*
match
;
struct
nft_family_ops
*
ops
;
struct
xt_rateinfo
*
rinfo
;
struct
xt_rateinfo
*
rinfo
;
size_t
size
;
size_t
size
;
switch
(
ctx
->
family
)
{
switch
(
ctx
->
h
->
family
)
{
case
NFPROTO_IPV4
:
case
NFPROTO_IPV4
:
case
NFPROTO_IPV6
:
case
NFPROTO_IPV6
:
case
NFPROTO_BRIDGE
:
case
NFPROTO_BRIDGE
:
matches
=
&
ctx
->
cs
->
matches
;
matches
=
&
ctx
->
cs
->
matches
;
break
;
break
;
default:
default:
fprintf
(
stderr
,
"BUG: nft_parse_
match
() unknown family %d
\n
"
,
fprintf
(
stderr
,
"BUG: nft_parse_
limit
() unknown family %d
\n
"
,
ctx
->
family
);
ctx
->
h
->
family
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
@@ -586,20 +584,27 @@ static void nft_parse_limit(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
...
@@ -586,20 +584,27 @@ static void nft_parse_limit(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
rinfo
->
avg
=
XT_LIMIT_SCALE
*
unit
/
rate
;
rinfo
->
avg
=
XT_LIMIT_SCALE
*
unit
/
rate
;
rinfo
->
burst
=
burst
;
rinfo
->
burst
=
burst
;
ops
=
nft_family_ops_lookup
(
ctx
->
family
);
if
(
ctx
->
h
->
ops
->
parse_match
!=
NULL
)
if
(
ops
->
parse_match
!=
NULL
)
ctx
->
h
->
ops
->
parse_match
(
match
,
ctx
->
cs
);
ops
->
parse_match
(
match
,
ctx
->
cs
);
}
static
void
nft_parse_lookup
(
struct
nft_xt_ctx
*
ctx
,
struct
nft_handle
*
h
,
struct
nftnl_expr
*
e
)
{
if
(
ctx
->
h
->
ops
->
parse_lookup
)
ctx
->
h
->
ops
->
parse_lookup
(
ctx
,
e
,
NULL
);
}
}
void
nft_rule_to_iptables_command_state
(
const
struct
nftnl_rule
*
r
,
void
nft_rule_to_iptables_command_state
(
struct
nft_handle
*
h
,
const
struct
nftnl_rule
*
r
,
struct
iptables_command_state
*
cs
)
struct
iptables_command_state
*
cs
)
{
{
struct
nftnl_expr_iter
*
iter
;
struct
nftnl_expr_iter
*
iter
;
struct
nftnl_expr
*
expr
;
struct
nftnl_expr
*
expr
;
int
family
=
nftnl_rule_get_u32
(
r
,
NFTNL_RULE_FAMILY
);
struct
nft_xt_ctx
ctx
=
{
struct
nft_xt_ctx
ctx
=
{
.
cs
=
cs
,
.
cs
=
cs
,
.
family
=
family
,
.
h
=
h
,
.
table
=
nftnl_rule_get_str
(
r
,
NFTNL_RULE_TABLE
),
};
};
iter
=
nftnl_expr_iter_create
(
r
);
iter
=
nftnl_expr_iter_create
(
r
);
...
@@ -630,6 +635,8 @@ void nft_rule_to_iptables_command_state(const struct nftnl_rule *r,
...
@@ -630,6 +635,8 @@ void nft_rule_to_iptables_command_state(const struct nftnl_rule *r,
nft_parse_target
(
&
ctx
,
expr
);
nft_parse_target
(
&
ctx
,
expr
);
else
if
(
strcmp
(
name
,
"limit"
)
==
0
)
else
if
(
strcmp
(
name
,
"limit"
)
==
0
)
nft_parse_limit
(
&
ctx
,
expr
);
nft_parse_limit
(
&
ctx
,
expr
);
else
if
(
strcmp
(
name
,
"lookup"
)
==
0
)
nft_parse_lookup
(
&
ctx
,
h
,
expr
);
expr
=
nftnl_expr_iter_next
(
iter
);
expr
=
nftnl_expr_iter_next
(
iter
);
}
}
...
@@ -982,19 +989,18 @@ void nft_ipv46_parse_target(struct xtables_target *t, void *data)
...
@@ -982,19 +989,18 @@ void nft_ipv46_parse_target(struct xtables_target *t, void *data)
cs
->
target
=
t
;
cs
->
target
=
t
;
}
}
bool
nft_ipv46_rule_find
(
struct
nft_family_ops
*
ops
,
bool
nft_ipv46_rule_find
(
struct
nft_handle
*
h
,
struct
nftnl_rule
*
r
,
void
*
data
)
struct
nftnl_rule
*
r
,
void
*
data
)
{
{
struct
iptables_command_state
*
cs
=
data
,
this
=
{};
struct
iptables_command_state
*
cs
=
data
,
this
=
{};
bool
ret
=
false
;
bool
ret
=
false
;
nft_rule_to_iptables_command_state
(
r
,
&
this
);
nft_rule_to_iptables_command_state
(
h
,
r
,
&
this
);
DEBUGP
(
"comparing with... "
);
DEBUGP
(
"comparing with... "
);
#ifdef DEBUG_DEL
#ifdef DEBUG_DEL
nft_rule_print_save
(
r
,
NFT_RULE_APPEND
,
0
);
nft_rule_print_save
(
r
,
NFT_RULE_APPEND
,
0
);
#endif
#endif
if
(
!
ops
->
is_same
(
cs
,
&
this
))
if
(
!
h
->
ops
->
is_same
(
cs
,
&
this
))
goto
out
;
goto
out
;
if
(
!
compare_matches
(
cs
->
matches
,
this
.
matches
))
{
if
(
!
compare_matches
(
cs
->
matches
,
this
.
matches
))
{
...
@@ -1014,7 +1020,7 @@ bool nft_ipv46_rule_find(struct nft_family_ops *ops,
...
@@ -1014,7 +1020,7 @@ bool nft_ipv46_rule_find(struct nft_family_ops *ops,
ret
=
true
;
ret
=
true
;
out:
out:
ops
->
clear_cs
(
&
this
);
h
->
ops
->
clear_cs
(
&
this
);
return
ret
;
return
ret
;
}
}
...
...
iptables/nft-shared.h
View file @
290749d4
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#define FMT(tab,notab) ((format) & FMT_NOTABLE ? (notab) : (tab))
#define FMT(tab,notab) ((format) & FMT_NOTABLE ? (notab) : (tab))
struct
xtables_args
;
struct
xtables_args
;
struct
nft_handle
;
struct
xt_xlate
;
struct
xt_xlate
;
enum
{
enum
{
...
@@ -42,19 +43,22 @@ enum {
...
@@ -42,19 +43,22 @@ enum {
NFT_XT_CTX_META
=
(
1
<<
1
),
NFT_XT_CTX_META
=
(
1
<<
1
),
NFT_XT_CTX_BITWISE
=
(
1
<<
2
),
NFT_XT_CTX_BITWISE
=
(
1
<<
2
),
NFT_XT_CTX_IMMEDIATE
=
(
1
<<
3
),
NFT_XT_CTX_IMMEDIATE
=
(
1
<<
3
),
NFT_XT_CTX_PREV_PAYLOAD
=
(
1
<<
4
),
};
};
struct
nft_xt_ctx
{
struct
nft_xt_ctx
{
struct
iptables_command_state
*
cs
;
struct
iptables_command_state
*
cs
;
struct
nftnl_expr_iter
*
iter
;
struct
nftnl_expr_iter
*
iter
;
int
family
;
struct
nft_handle
*
h
;
uint32_t
flags
;
uint32_t
flags
;
const
char
*
table
;
uint32_t
reg
;
uint32_t
reg
;
struct
{
struct
{
uint32_t
base
;
uint32_t
offset
;
uint32_t
offset
;
uint32_t
len
;
uint32_t
len
;
}
payload
;
}
payload
,
prev_
payload
;
struct
{
struct
{
uint32_t
key
;
uint32_t
key
;
}
meta
;
}
meta
;
...
@@ -69,7 +73,7 @@ struct nft_xt_ctx {
...
@@ -69,7 +73,7 @@ struct nft_xt_ctx {
};
};
struct
nft_family_ops
{
struct
nft_family_ops
{
int
(
*
add
)(
struct
nftnl_rule
*
r
,
void
*
data
);
int
(
*
add
)(
struct
nft_handle
*
h
,
struct
nftnl_rule
*
r
,
void
*
data
);
bool
(
*
is_same
)(
const
void
*
data_a
,
bool
(
*
is_same
)(
const
void
*
data_a
,
const
void
*
data_b
);
const
void
*
data_b
);
void
(
*
print_payload
)(
struct
nftnl_expr
*
e
,
void
(
*
print_payload
)(
struct
nftnl_expr
*
e
,
...
@@ -82,6 +86,8 @@ struct nft_family_ops {
...
@@ -82,6 +86,8 @@ struct nft_family_ops {
void
*
data
);
void
*
data
);
void
(
*
parse_cmp
)(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
,
void
(
*
parse_cmp
)(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
,
void
*
data
);
void
*
data
);
void
(
*
parse_lookup
)(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
,
void
*
data
);
void
(
*
parse_immediate
)(
const
char
*
jumpto
,
bool
nft_goto
,
void
*
data
);
void
(
*
parse_immediate
)(
const
char
*
jumpto
,
bool
nft_goto
,
void
*
data
);
void
(
*
print_table_header
)(
const
char
*
tablename
);
void
(
*
print_table_header
)(
const
char
*
tablename
);
...
@@ -89,8 +95,8 @@ struct nft_family_ops {
...
@@ -89,8 +95,8 @@ struct nft_family_ops {
const
char
*
pol
,
const
char
*
pol
,
const
struct
xt_counters
*
counters
,
bool
basechain
,
const
struct
xt_counters
*
counters
,
bool
basechain
,
uint32_t
refs
,
uint32_t
entries
);
uint32_t
refs
,
uint32_t
entries
);
void
(
*
print_rule
)(
struct
nft
nl_ru
le
*
r
,
unsigned
int
num
,
void
(
*
print_rule
)(
struct
nft
_hand
le
*
h
,
struct
nftnl_rule
*
r
,
unsigned
int
format
);
unsigned
int
num
,
unsigned
int
format
);
void
(
*
save_rule
)(
const
void
*
data
,
unsigned
int
format
);
void
(
*
save_rule
)(
const
void
*
data
,
unsigned
int
format
);
void
(
*
save_counters
)(
const
void
*
data
);
void
(
*
save_counters
)(
const
void
*
data
);
void
(
*
save_chain
)(
const
struct
nftnl_chain
*
c
,
const
char
*
policy
);
void
(
*
save_chain
)(
const
struct
nftnl_chain
*
c
,
const
char
*
policy
);
...
@@ -100,10 +106,10 @@ struct nft_family_ops {
...
@@ -100,10 +106,10 @@ struct nft_family_ops {
struct
xtables_args
*
args
);
struct
xtables_args
*
args
);
void
(
*
parse_match
)(
struct
xtables_match
*
m
,
void
*
data
);
void
(
*
parse_match
)(
struct
xtables_match
*
m
,
void
*
data
);
void
(
*
parse_target
)(
struct
xtables_target
*
t
,
void
*
data
);
void
(
*
parse_target
)(
struct
xtables_target
*
t
,
void
*
data
);
void
(
*
rule_to_cs
)(
const
struct
nftnl_rule
*
r
,
void
(
*
rule_to_cs
)(
struct
nft_handle
*
h
,
const
struct
nftnl_rule
*
r
,
struct
iptables_command_state
*
cs
);
struct
iptables_command_state
*
cs
);
void
(
*
clear_cs
)(
struct
iptables_command_state
*
cs
);
void
(
*
clear_cs
)(
struct
iptables_command_state
*
cs
);
bool
(
*
rule_find
)(
struct
nft_
family_ops
*
ops
,
struct
nftnl_rule
*
r
,
bool
(
*
rule_find
)(
struct
nft_
handle
*
h
,
struct
nftnl_rule
*
r
,
void
*
data
);
void
*
data
);
int
(
*
xlate
)(
const
void
*
data
,
struct
xt_xlate
*
xl
);
int
(
*
xlate
)(
const
void
*
data
,
struct
xt_xlate
*
xl
);
};
};
...
@@ -111,7 +117,7 @@ struct nft_family_ops {
...
@@ -111,7 +117,7 @@ struct nft_family_ops {
void
add_meta
(
struct
nftnl_rule
*
r
,
uint32_t
key
);
void
add_meta
(
struct
nftnl_rule
*
r
,
uint32_t
key
);
void
add_payload
(
struct
nftnl_rule
*
r
,
int
offset
,
int
len
,
uint32_t
base
);
void
add_payload
(
struct
nftnl_rule
*
r
,
int
offset
,
int
len
,
uint32_t
base
);
void
add_bitwise
(
struct
nftnl_rule
*
r
,
uint8_t
*
mask
,
size_t
len
);
void
add_bitwise
(
struct
nftnl_rule
*
r
,
uint8_t
*
mask
,
size_t
len
);
void
add_bitwise_u16
(
struct
nftnl_rule
*
r
,
int
mask
,
int
xor
);
void
add_bitwise_u16
(
struct
nftnl_rule
*
r
,
u
int
16_t
mask
,
u
int
16_t
xor
);
void
add_cmp_ptr
(
struct
nftnl_rule
*
r
,
uint32_t
op
,
void
*
data
,
size_t
len
);
void
add_cmp_ptr
(
struct
nftnl_rule
*
r
,
uint32_t
op
,
void
*
data
,
size_t
len
);
void
add_cmp_u8
(
struct
nftnl_rule
*
r
,
uint8_t
val
,
uint32_t
op
);
void
add_cmp_u8
(
struct
nftnl_rule
*
r
,
uint8_t
val
,
uint32_t
op
);
void
add_cmp_u16
(
struct
nftnl_rule
*
r
,
uint16_t
val
,
uint32_t
op
);
void
add_cmp_u16
(
struct
nftnl_rule
*
r
,
uint16_t
val
,
uint32_t
op
);
...
@@ -137,7 +143,8 @@ int parse_meta(struct nftnl_expr *e, uint8_t key, char *iniface,
...
@@ -137,7 +143,8 @@ int parse_meta(struct nftnl_expr *e, uint8_t key, char *iniface,
unsigned
char
*
outiface_mask
,
uint8_t
*
invflags
);
unsigned
char
*
outiface_mask
,
uint8_t
*
invflags
);
void
print_proto
(
uint16_t
proto
,
int
invert
);
void
print_proto
(
uint16_t
proto
,
int
invert
);
void
get_cmp_data
(
struct
nftnl_expr
*
e
,
void
*
data
,
size_t
dlen
,
bool
*
inv
);
void
get_cmp_data
(
struct
nftnl_expr
*
e
,
void
*
data
,
size_t
dlen
,
bool
*
inv
);
void
nft_rule_to_iptables_command_state
(
const
struct
nftnl_rule
*
r
,
void
nft_rule_to_iptables_command_state
(
struct
nft_handle
*
h
,
const
struct
nftnl_rule
*
r
,
struct
iptables_command_state
*
cs
);
struct
iptables_command_state
*
cs
);
void
nft_clear_iptables_command_state
(
struct
iptables_command_state
*
cs
);
void
nft_clear_iptables_command_state
(
struct
iptables_command_state
*
cs
);
void
print_header
(
unsigned
int
format
,
const
char
*
chain
,
const
char
*
pol
,
void
print_header
(
unsigned
int
format
,
const
char
*
chain
,
const
char
*
pol
,
...
@@ -163,9 +170,8 @@ void save_matches_and_target(const struct iptables_command_state *cs,
...
@@ -163,9 +170,8 @@ void save_matches_and_target(const struct iptables_command_state *cs,
struct
nft_family_ops
*
nft_family_ops_lookup
(
int
family
);
struct
nft_family_ops
*
nft_family_ops_lookup
(
int
family
);
struct
nft_handle
;
void
nft_ipv46_parse_target
(
struct
xtables_target
*
t
,
void
*
data
);
void
nft_ipv46_parse_target
(
struct
xtables_target
*
t
,
void
*
data
);
bool
nft_ipv46_rule_find
(
struct
nft_
family_ops
*
ops
,
struct
nftnl_rule
*
r
,
bool
nft_ipv46_rule_find
(
struct
nft_
handle
*
h
,
struct
nftnl_rule
*
r
,
void
*
data
);
void
*
data
);
bool
compare_matches
(
struct
xtables_rule_match
*
mt1
,
struct
xtables_rule_match
*
mt2
);
bool
compare_matches
(
struct
xtables_rule_match
*
mt1
,
struct
xtables_rule_match
*
mt2
);
...
@@ -199,23 +205,6 @@ struct xtables_args {
...
@@ -199,23 +205,6 @@ struct xtables_args {
unsigned
long
long
pcnt_cnt
,
bcnt_cnt
;
unsigned
long
long
pcnt_cnt
,
bcnt_cnt
;
};
};
#define CMD_NONE 0x0000U
#define CMD_INSERT 0x0001U
#define CMD_DELETE 0x0002U
#define CMD_DELETE_NUM 0x0004U
#define CMD_REPLACE 0x0008U
#define CMD_APPEND 0x0010U
#define CMD_LIST 0x0020U
#define CMD_FLUSH 0x0040U
#define CMD_ZERO 0x0080U
#define CMD_NEW_CHAIN 0x0100U
#define CMD_DELETE_CHAIN 0x0200U
#define CMD_SET_POLICY 0x0400U
#define CMD_RENAME_CHAIN 0x0800U
#define CMD_LIST_RULES 0x1000U
#define CMD_ZERO_NUM 0x2000U
#define CMD_CHECK 0x4000U
struct
nft_xt_cmd_parse
{
struct
nft_xt_cmd_parse
{
unsigned
int
command
;
unsigned
int
command
;
unsigned
int
rulenum
;
unsigned
int
rulenum
;
...
@@ -232,19 +221,10 @@ void do_parse(struct nft_handle *h, int argc, char *argv[],
...
@@ -232,19 +221,10 @@ void do_parse(struct nft_handle *h, int argc, char *argv[],
struct
nft_xt_cmd_parse
*
p
,
struct
iptables_command_state
*
cs
,
struct
nft_xt_cmd_parse
*
p
,
struct
iptables_command_state
*
cs
,
struct
xtables_args
*
args
);
struct
xtables_args
*
args
);
struct
nft_xt_restore_parse
{
FILE
*
in
;
int
testing
;
const
char
*
tablename
;
bool
commit
;
};
struct
nftnl_chain_list
;
struct
nftnl_chain_list
;
struct
nft_xt_restore_cb
{
struct
nft_xt_restore_cb
{
void
(
*
table_new
)(
struct
nft_handle
*
h
,
const
char
*
table
);
void
(
*
table_new
)(
struct
nft_handle
*
h
,
const
char
*
table
);
struct
nftnl_chain_list
*
(
*
chain_list
)(
struct
nft_handle
*
h
,
const
char
*
table
);
int
(
*
chain_set
)(
struct
nft_handle
*
h
,
const
char
*
table
,
int
(
*
chain_set
)(
struct
nft_handle
*
h
,
const
char
*
table
,
const
char
*
chain
,
const
char
*
policy
,
const
char
*
chain
,
const
char
*
policy
,
const
struct
xt_counters
*
counters
);
const
struct
xt_counters
*
counters
);
...
@@ -260,10 +240,16 @@ struct nft_xt_restore_cb {
...
@@ -260,10 +240,16 @@ struct nft_xt_restore_cb {
int
(
*
abort
)(
struct
nft_handle
*
h
);
int
(
*
abort
)(
struct
nft_handle
*
h
);
};
};
struct
nft_xt_restore_parse
{
FILE
*
in
;
int
testing
;
const
char
*
tablename
;
bool
commit
;
const
struct
nft_xt_restore_cb
*
cb
;
};
void
xtables_restore_parse
(
struct
nft_handle
*
h
,
void
xtables_restore_parse
(
struct
nft_handle
*
h
,
struct
nft_xt_restore_parse
*
p
,
const
struct
nft_xt_restore_parse
*
p
);
struct
nft_xt_restore_cb
*
cb
,
int
argc
,
char
*
argv
[]);
void
nft_check_xt_legacy
(
int
family
,
bool
is_ipt_save
);
void
nft_check_xt_legacy
(
int
family
,
bool
is_ipt_save
);
#endif
#endif
iptables/nft.c
View file @
290749d4
This diff is collapsed.
Click to expand it.
iptables/nft.h
View file @
290749d4
...
@@ -27,10 +27,19 @@ struct builtin_table {
...
@@ -27,10 +27,19 @@ struct builtin_table {
struct
builtin_chain
chains
[
NF_INET_NUMHOOKS
];
struct
builtin_chain
chains
[
NF_INET_NUMHOOKS
];
};
};
enum
nft_cache_level
{
NFT_CL_NONE
,
NFT_CL_TABLES
,
NFT_CL_CHAINS
,
NFT_CL_SETS
,
NFT_CL_RULES
};
struct
nft_cache
{
struct
nft_cache
{
struct
nftnl_table_list
*
tables
;
struct
nftnl_table_list
*
tables
;
struct
{
struct
{
struct
nftnl_chain_list
*
chains
;
struct
nftnl_chain_list
*
chains
;
struct
nftnl_set_list
*
sets
;
bool
initialized
;
bool
initialized
;
}
table
[
NFT_TABLE_MAX
];
}
table
[
NFT_TABLE_MAX
];
};
};
...
@@ -38,6 +47,8 @@ struct nft_cache {
...
@@ -38,6 +47,8 @@ struct nft_cache {
struct
nft_handle
{
struct
nft_handle
{
int
family
;
int
family
;
struct
mnl_socket
*
nl
;
struct
mnl_socket
*
nl
;
int
nlsndbuffsiz
;
int
nlrcvbuffsiz
;
uint32_t
portid
;
uint32_t
portid
;
uint32_t
seq
;
uint32_t
seq
;
uint32_t
nft_genid
;
uint32_t
nft_genid
;
...
@@ -51,7 +62,7 @@ struct nft_handle {
...
@@ -51,7 +62,7 @@ struct nft_handle {
unsigned
int
cache_index
;
unsigned
int
cache_index
;
struct
nft_cache
__cache
[
2
];
struct
nft_cache
__cache
[
2
];
struct
nft_cache
*
cache
;
struct
nft_cache
*
cache
;
bool
have_cache
;
enum
nft_cache_level
cache_level
;
bool
restore
;
bool
restore
;
bool
noflush
;
bool
noflush
;
int8_t
config_done
;
int8_t
config_done
;
...
@@ -71,7 +82,7 @@ int mnl_talk(struct nft_handle *h, struct nlmsghdr *nlh,
...
@@ -71,7 +82,7 @@ int mnl_talk(struct nft_handle *h, struct nlmsghdr *nlh,
void
*
data
);
void
*
data
);
int
nft_init
(
struct
nft_handle
*
h
,
const
struct
builtin_table
*
t
);
int
nft_init
(
struct
nft_handle
*
h
,
const
struct
builtin_table
*
t
);
void
nft_fini
(
struct
nft_handle
*
h
);
void
nft_fini
(
struct
nft_handle
*
h
);
void
nft_
build_cache
(
struct
nft_handle
*
h
);
int
nft_
restart
(
struct
nft_handle
*
h
);
/*
/*
* Operations with tables.
* Operations with tables.
...
@@ -79,7 +90,7 @@ void nft_build_cache(struct nft_handle *h);
...
@@ -79,7 +90,7 @@ void nft_build_cache(struct nft_handle *h);
struct
nftnl_table
;
struct
nftnl_table
;
struct
nftnl_chain_list
;
struct
nftnl_chain_list
;
int
nft_for_each_table
(
struct
nft_handle
*
h
,
int
(
*
func
)(
struct
nft_handle
*
h
,
const
char
*
tablename
,
bool
counters
),
bool
counters
);
int
nft_for_each_table
(
struct
nft_handle
*
h
,
int
(
*
func
)(
struct
nft_handle
*
h
,
const
char
*
tablename
,
void
*
data
),
void
*
data
);
bool
nft_table_find
(
struct
nft_handle
*
h
,
const
char
*
tablename
);
bool
nft_table_find
(
struct
nft_handle
*
h
,
const
char
*
tablename
);
int
nft_table_purge_chains
(
struct
nft_handle
*
h
,
const
char
*
table
,
struct
nftnl_chain_list
*
list
);
int
nft_table_purge_chains
(
struct
nft_handle
*
h
,
const
char
*
table
,
struct
nftnl_chain_list
*
list
);
int
nft_table_flush
(
struct
nft_handle
*
h
,
const
char
*
table
);
int
nft_table_flush
(
struct
nft_handle
*
h
,
const
char
*
table
);
...
@@ -92,8 +103,6 @@ const struct builtin_table *nft_table_builtin_find(struct nft_handle *h, const c
...
@@ -92,8 +103,6 @@ const struct builtin_table *nft_table_builtin_find(struct nft_handle *h, const c
struct
nftnl_chain
;
struct
nftnl_chain
;
int
nft_chain_set
(
struct
nft_handle
*
h
,
const
char
*
table
,
const
char
*
chain
,
const
char
*
policy
,
const
struct
xt_counters
*
counters
);
int
nft_chain_set
(
struct
nft_handle
*
h
,
const
char
*
table
,
const
char
*
chain
,
const
char
*
policy
,
const
struct
xt_counters
*
counters
);
struct
nftnl_chain_list
*
nft_chain_list_get
(
struct
nft_handle
*
h
,
const
char
*
table
);
int
nft_chain_save
(
struct
nft_handle
*
h
,
struct
nftnl_chain_list
*
list
);
int
nft_chain_save
(
struct
nft_handle
*
h
,
struct
nftnl_chain_list
*
list
);
int
nft_chain_user_add
(
struct
nft_handle
*
h
,
const
char
*
chain
,
const
char
*
table
);
int
nft_chain_user_add
(
struct
nft_handle
*
h
,
const
char
*
chain
,
const
char
*
table
);
int
nft_chain_user_del
(
struct
nft_handle
*
h
,
const
char
*
chain
,
const
char
*
table
,
bool
verbose
);
int
nft_chain_user_del
(
struct
nft_handle
*
h
,
const
char
*
chain
,
const
char
*
table
,
bool
verbose
);
...
@@ -102,6 +111,9 @@ int nft_chain_user_rename(struct nft_handle *h, const char *chain, const char *t
...
@@ -102,6 +111,9 @@ int nft_chain_user_rename(struct nft_handle *h, const char *chain, const char *t
int
nft_chain_zero_counters
(
struct
nft_handle
*
h
,
const
char
*
chain
,
const
char
*
table
,
bool
verbose
);
int
nft_chain_zero_counters
(
struct
nft_handle
*
h
,
const
char
*
chain
,
const
char
*
table
,
bool
verbose
);
const
struct
builtin_chain
*
nft_chain_builtin_find
(
const
struct
builtin_table
*
t
,
const
char
*
chain
);
const
struct
builtin_chain
*
nft_chain_builtin_find
(
const
struct
builtin_table
*
t
,
const
char
*
chain
);
bool
nft_chain_exists
(
struct
nft_handle
*
h
,
const
char
*
table
,
const
char
*
chain
);
bool
nft_chain_exists
(
struct
nft_handle
*
h
,
const
char
*
table
,
const
char
*
chain
);
void
nft_bridge_chain_postprocess
(
struct
nft_handle
*
h
,
struct
nftnl_chain
*
c
);
/*
/*
* Operations with rule-set.
* Operations with rule-set.
...
@@ -125,7 +137,7 @@ int nft_rule_zero_counters(struct nft_handle *h, const char *chain, const char *
...
@@ -125,7 +137,7 @@ int nft_rule_zero_counters(struct nft_handle *h, const char *chain, const char *
*/
*/
int
add_counters
(
struct
nftnl_rule
*
r
,
uint64_t
packets
,
uint64_t
bytes
);
int
add_counters
(
struct
nftnl_rule
*
r
,
uint64_t
packets
,
uint64_t
bytes
);
int
add_verdict
(
struct
nftnl_rule
*
r
,
int
verdict
);
int
add_verdict
(
struct
nftnl_rule
*
r
,
int
verdict
);
int
add_match
(
struct
nftnl_rule
*
r
,
struct
xt_entry_match
*
m
);
int
add_match
(
struct
nft_handle
*
h
,
struct
nftnl_rule
*
r
,
struct
xt_entry_match
*
m
);
int
add_target
(
struct
nftnl_rule
*
r
,
struct
xt_entry_target
*
t
);
int
add_target
(
struct
nftnl_rule
*
r
,
struct
xt_entry_target
*
t
);
int
add_jumpto
(
struct
nftnl_rule
*
r
,
const
char
*
name
,
int
verdict
);
int
add_jumpto
(
struct
nftnl_rule
*
r
,
const
char
*
name
,
int
verdict
);
int
add_action
(
struct
nftnl_rule
*
r
,
struct
iptables_command_state
*
cs
,
bool
goto_set
);
int
add_action
(
struct
nftnl_rule
*
r
,
struct
iptables_command_state
*
cs
,
bool
goto_set
);
...
@@ -136,8 +148,8 @@ enum nft_rule_print {
...
@@ -136,8 +148,8 @@ enum nft_rule_print {
NFT_RULE_DEL
,
NFT_RULE_DEL
,
};
};
void
nft_rule_print_save
(
const
struct
nftnl_rule
*
r
,
enum
nft_rule_print
type
,
void
nft_rule_print_save
(
struct
nft_handle
*
h
,
const
struct
nftnl_rule
*
r
,
unsigned
int
format
);
enum
nft_rule_print
type
,
unsigned
int
format
);
uint32_t
nft_invflags2cmp
(
uint32_t
invflags
,
uint32_t
flag
);
uint32_t
nft_invflags2cmp
(
uint32_t
invflags
,
uint32_t
flag
);
...
@@ -145,6 +157,7 @@ uint32_t nft_invflags2cmp(uint32_t invflags, uint32_t flag);
...
@@ -145,6 +157,7 @@ uint32_t nft_invflags2cmp(uint32_t invflags, uint32_t flag);
* global commit and abort
* global commit and abort
*/
*/
int
nft_commit
(
struct
nft_handle
*
h
);
int
nft_commit
(
struct
nft_handle
*
h
);
int
nft_bridge_commit
(
struct
nft_handle
*
h
);
int
nft_abort
(
struct
nft_handle
*
h
);
int
nft_abort
(
struct
nft_handle
*
h
);
int
nft_abort_policy_rule
(
struct
nft_handle
*
h
,
const
char
*
table
);
int
nft_abort_policy_rule
(
struct
nft_handle
*
h
,
const
char
*
table
);
...
@@ -168,22 +181,6 @@ int nft_init_eb(struct nft_handle *h, const char *pname);
...
@@ -168,22 +181,6 @@ int nft_init_eb(struct nft_handle *h, const char *pname);
int
ebt_get_current_chain
(
const
char
*
chain
);
int
ebt_get_current_chain
(
const
char
*
chain
);
int
do_commandeb
(
struct
nft_handle
*
h
,
int
argc
,
char
*
argv
[],
char
**
table
,
bool
restore
);
int
do_commandeb
(
struct
nft_handle
*
h
,
int
argc
,
char
*
argv
[],
char
**
table
,
bool
restore
);
/*
* Parse config for tables and chain helper functions
*/
#define XTABLES_CONFIG_DEFAULT "/etc/xtables.conf"
struct
nftnl_table_list
;
struct
nftnl_chain_list
;
extern
int
xtables_config_parse
(
const
char
*
filename
,
struct
nftnl_table_list
*
table_list
,
struct
nftnl_chain_list
*
chain_list
);
enum
{
NFT_LOAD_VERBOSE
=
(
1
<<
0
),
};
int
nft_xtables_config_load
(
struct
nft_handle
*
h
,
const
char
*
filename
,
uint32_t
flags
);
/*
/*
* Translation from iptables to nft
* Translation from iptables to nft
*/
*/
...
@@ -211,7 +208,10 @@ int nft_arp_rule_insert(struct nft_handle *h, const char *chain,
...
@@ -211,7 +208,10 @@ int nft_arp_rule_insert(struct nft_handle *h, const char *chain,
void
nft_rule_to_arpt_entry
(
struct
nftnl_rule
*
r
,
struct
arpt_entry
*
fw
);
void
nft_rule_to_arpt_entry
(
struct
nftnl_rule
*
r
,
struct
arpt_entry
*
fw
);
bool
nft_is_table_compatible
(
struct
nft_handle
*
h
,
const
char
*
name
);
bool
nft_is_table_compatible
(
struct
nft_handle
*
h
,
const
char
*
table
,
const
char
*
chain
);
void
nft_assert_table_compatible
(
struct
nft_handle
*
h
,
const
char
*
table
,
const
char
*
chain
);
int
ebt_set_user_chain_policy
(
struct
nft_handle
*
h
,
const
char
*
table
,
int
ebt_set_user_chain_policy
(
struct
nft_handle
*
h
,
const
char
*
table
,
const
char
*
chain
,
const
char
*
policy
);
const
char
*
chain
,
const
char
*
policy
);
...
...
iptables/tests/shell/run-tests.sh
View file @
290749d4
...
@@ -38,6 +38,14 @@ while [ -n "$1" ]; do
...
@@ -38,6 +38,14 @@ while [ -n "$1" ]; do
HOST
=
y
HOST
=
y
shift
shift
;;
;;
-l
|
--legacy
)
LEGACY_ONLY
=
y
shift
;;
-n
|
--nft
)
NFT_ONLY
=
y
shift
;;
*${
RETURNCODE_SEPARATOR
}
+
([
0-9]
)
)
*${
RETURNCODE_SEPARATOR
}
+
([
0-9]
)
)
SINGLE+
=
"
$1
"
SINGLE+
=
"
$1
"
VERBOSE
=
y
VERBOSE
=
y
...
@@ -98,19 +106,23 @@ do_test() {
...
@@ -98,19 +106,23 @@ do_test() {
}
}
echo
""
echo
""
for
testfile
in
$(
find_tests
)
;
do
if
[
"
$NFT_ONLY
"
!=
"y"
]
;
then
do_test
"
$testfile
"
"
$XTABLES_LEGACY_MULTI
"
for
testfile
in
$(
find_tests
)
;
do
done
do_test
"
$testfile
"
"
$XTABLES_LEGACY_MULTI
"
msg_info
"legacy results: [OK]
$ok
[FAILED]
$failed
[TOTAL]
$((
ok+failed
))
"
done
msg_info
"legacy results: [OK]
$ok
[FAILED]
$failed
[TOTAL]
$((
ok+failed
))
"
fi
legacy_ok
=
$ok
legacy_ok
=
$ok
legacy_fail
=
$failed
legacy_fail
=
$failed
ok
=
0
ok
=
0
failed
=
0
failed
=
0
for
testfile
in
$(
find_tests
)
;
do
if
[
"
$LEGACY_ONLY
"
!=
"y"
]
;
then
do_test
"
$testfile
"
"
$XTABLES_NFT_MULTI
"
for
testfile
in
$(
find_tests
)
;
do
done
do_test
"
$testfile
"
"
$XTABLES_NFT_MULTI
"
msg_info
"nft results: [OK]
$ok
[FAILED]
$failed
[TOTAL]
$((
ok+failed
))
"
done
msg_info
"nft results: [OK]
$ok
[FAILED]
$failed
[TOTAL]
$((
ok+failed
))
"
fi
ok
=
$((
legacy_ok+ok
))
ok
=
$((
legacy_ok+ok
))
failed
=
$((
legacy_fail+failed
))
failed
=
$((
legacy_fail+failed
))
...
...
iptables/tests/shell/testcases/arptables/0001-arptables-save-restore_0
View file @
290749d4
...
@@ -50,13 +50,12 @@ DUMP='*filter
...
@@ -50,13 +50,12 @@ DUMP='*filter
-A foo -j MARK --set-mark 12345
-A foo -j MARK --set-mark 12345
-A foo -j ACCEPT --opcode 1
-A foo -j ACCEPT --opcode 1
-A foo -j ACCEPT --proto-type 0x800
-A foo -j ACCEPT --proto-type 0x800
-A foo -j ACCEPT -i lo --opcode 1 --proto-type 0x800
-A foo -j ACCEPT -i lo --opcode 1 --proto-type 0x800'
'
diff
-u
<
(
echo
-e
"
$DUMP
"
)
<
(
$XT_MULTI
arptables-save
)
diff
-u
<
(
echo
-e
"
$DUMP
"
)
<
(
$XT_MULTI
arptables-save
|
grep
-v
"^#"
)
# make sure dump can be restored and check it didn't change
# make sure dump can be restored and check it didn't change
$XT_MULTI
arptables
-F
$XT_MULTI
arptables
-F
$XT_MULTI
arptables-restore
<<<
$DUMP
$XT_MULTI
arptables-restore
<<<
$DUMP
diff
-u
<
(
echo
-e
"
$DUMP
"
)
<
(
$XT_MULTI
arptables-save
)
diff
-u
<
(
echo
-e
"
$DUMP
"
)
<
(
$XT_MULTI
arptables-save
|
grep
-v
"^#"
)
iptables/tests/shell/testcases/arptables/0002-arptables-restore-defaults_0
View file @
290749d4
...
@@ -11,8 +11,7 @@ set -e
...
@@ -11,8 +11,7 @@ set -e
DUMP
=
'*filter
DUMP
=
'*filter
:OUTPUT ACCEPT
:OUTPUT ACCEPT
-A OUTPUT -j mangle --mangle-ip-s 10.0.0.1
-A OUTPUT -j mangle --mangle-ip-s 10.0.0.1
-A OUTPUT -j mangle --mangle-ip-d 10.0.0.2
-A OUTPUT -j mangle --mangle-ip-d 10.0.0.2'
'
# note how mangle-ip-s is unset in second rule
# note how mangle-ip-s is unset in second rule
...
@@ -20,8 +19,7 @@ EXPECT='*filter
...
@@ -20,8 +19,7 @@ EXPECT='*filter
:INPUT ACCEPT
:INPUT ACCEPT
:OUTPUT ACCEPT
:OUTPUT ACCEPT
-A OUTPUT -j mangle --mangle-ip-s 10.0.0.1
-A OUTPUT -j mangle --mangle-ip-s 10.0.0.1
-A OUTPUT -j mangle --mangle-ip-d 10.0.0.2
-A OUTPUT -j mangle --mangle-ip-d 10.0.0.2'
'
$XT_MULTI
arptables
-F
$XT_MULTI
arptables
-F
$XT_MULTI
arptables-restore
<<<
$DUMP
$XT_MULTI
arptables-restore
<<<
$DUMP
...
...
iptables/tests/shell/testcases/arptables/0003-arptables-verbose-output_0
View file @
290749d4
...
@@ -58,7 +58,6 @@ EXPECT='*filter
...
@@ -58,7 +58,6 @@ EXPECT='*filter
-A INPUT -j MARK -i eth23 --set-mark 42
-A INPUT -j MARK -i eth23 --set-mark 42
-A OUTPUT -j CLASSIFY -o eth23 --set-class 23:42
-A OUTPUT -j CLASSIFY -o eth23 --set-class 23:42
-A OUTPUT -j foo -o eth23
-A OUTPUT -j foo -o eth23
-A foo -j mangle -o eth23 --mangle-ip-s 10.0.0.1
-A foo -j mangle -o eth23 --mangle-ip-s 10.0.0.1'
'
diff
-u
-Z
<
(
echo
-e
"
$EXPECT
"
)
<
(
$XT_MULTI
arptables-save
)
diff
-u
-Z
<
(
echo
-e
"
$EXPECT
"
)
<
(
$XT_MULTI
arptables-save
|
grep
-v
'^#'
)
iptables/tests/shell/testcases/ebtables/0001-ebtables-basic_0
View file @
290749d4
#!/bin/sh
#!/bin/sh
get_entries_count
()
{
# (chain)
$XT_MULTI
ebtables
-L
$1
|
sed
-n
's/.*entries: \([0-9]*\).*/\1/p'
}
set
-x
set
-x
case
"
$XT_MULTI
"
in
case
"
$XT_MULTI
"
in
*
/xtables-nft-multi
)
*
/xtables-nft-multi
)
...
@@ -28,32 +32,32 @@ case "$XT_MULTI" in
...
@@ -28,32 +32,32 @@ case "$XT_MULTI" in
exit
1
exit
1
fi
fi
$XT_MULTI
ebtables
-L
FOO |
grep
-q
'entries: 0'
entries
=
$(
get_entries_count FOO
)
if
[
$
?
-ne
0
]
;
then
if
[
$
entries
-ne
0
]
;
then
echo
"Unexpected entries count in empty unreferenced chain"
echo
"Unexpected entries count in empty unreferenced chain
(expected 0, have
$entries
)
"
$XT_MULTI
ebtables
-L
$XT_MULTI
ebtables
-L
exit
1
exit
1
fi
fi
$XT_MULTI
ebtables
-A
FORWARD
-j
FOO
$XT_MULTI
ebtables
-A
FORWARD
-j
FOO
$XT_MULTI
ebtables
-L
FORWARD |
grep
-q
'entries: 1'
entries
=
$(
get_entries_count FORWARD
)
if
[
$
?
-ne
0
]
;
then
if
[
$
entries
-ne
1
]
;
then
echo
"Unexpected entries count in FORWARD chain"
echo
"Unexpected entries count in FORWARD chain
(expected 1, have
$entries
)
"
$XT_MULTI
ebtables
-L
$XT_MULTI
ebtables
-L
exit
1
exit
1
fi
fi
$XT_MULTI
ebtables
-L
FOO |
grep
-q
'entries: 0'
entries
=
$(
get_entries_count FOO
)
if
[
$
?
-ne
0
]
;
then
if
[
$
entries
-ne
0
]
;
then
echo
"Unexpected entries count in empty referenced chain"
echo
"Unexpected entries count in empty referenced chain
(expected 0, have
$entries
)
"
$XT_MULTI
ebtables
-L
$XT_MULTI
ebtables
-L
exit
1
exit
1
fi
fi
$XT_MULTI
ebtables
-A
FOO
-j
ACCEPT
$XT_MULTI
ebtables
-A
FOO
-j
ACCEPT
$XT_MULTI
ebtables
-L
FOO |
grep
-q
'entries: 1'
entries
=
$(
get_entries_count FOO
)
if
[
$
?
-ne
0
]
;
then
if
[
$
entries
-ne
1
]
;
then
echo
"Unexpected entries count in non-empty referenced chain"
echo
"Unexpected entries count in non-empty referenced chain
(expected 1, have
$entries
)
"
$XT_MULTI
ebtables
-L
$XT_MULTI
ebtables
-L
exit
1
exit
1
fi
fi
...
...
iptables/tests/shell/testcases/ebtables/0002-ebtables-save-restore_0
View file @
290749d4
...
@@ -99,7 +99,6 @@ DUMP='*filter
...
@@ -99,7 +99,6 @@ DUMP='*filter
-A foo --802_3-sap 0x23 --limit 100/sec --limit-burst 5 -j ACCEPT
-A foo --802_3-sap 0x23 --limit 100/sec --limit-burst 5 -j ACCEPT
-A foo --pkttype-type multicast --log-level notice --log-prefix "" -j CONTINUE
-A foo --pkttype-type multicast --log-level notice --log-prefix "" -j CONTINUE
-A foo --pkttype-type multicast --limit 100/sec --limit-burst 5 -j ACCEPT
-A foo --pkttype-type multicast --limit 100/sec --limit-burst 5 -j ACCEPT
*nat
*nat
:PREROUTING ACCEPT
:PREROUTING ACCEPT
:OUTPUT DROP
:OUTPUT DROP
...
@@ -107,8 +106,7 @@ DUMP='*filter
...
@@ -107,8 +106,7 @@ DUMP='*filter
:nat_foo DROP
:nat_foo DROP
-A PREROUTING -j redirect
-A PREROUTING -j redirect
-A OUTPUT -j ACCEPT
-A OUTPUT -j ACCEPT
-A POSTROUTING -j ACCEPT
-A POSTROUTING -j ACCEPT'
'
diff
-u
<
(
echo
-e
"
$DUMP
"
)
<
(
$XT_MULTI
ebtables-save |
grep
-v
'^#'
)
diff
-u
<
(
echo
-e
"
$DUMP
"
)
<
(
$XT_MULTI
ebtables-save |
grep
-v
'^#'
)
...
...
iptables/tests/shell/testcases/ebtables/0003-ebtables-restore-defaults_0
View file @
290749d4
...
@@ -13,8 +13,7 @@ DUMP='*filter
...
@@ -13,8 +13,7 @@ DUMP='*filter
-A FORWARD --limit 100 --limit-burst 42 -j ACCEPT
-A FORWARD --limit 100 --limit-burst 42 -j ACCEPT
-A FORWARD --limit 1000 -j ACCEPT
-A FORWARD --limit 1000 -j ACCEPT
-A FORWARD --log --log-prefix "foobar"
-A FORWARD --log --log-prefix "foobar"
-A FORWARD --log
-A FORWARD --log'
'
# note how limit-burst is 5 in second rule and log-prefix empty in fourth one
# note how limit-burst is 5 in second rule and log-prefix empty in fourth one
...
@@ -25,8 +24,7 @@ EXPECT='*filter
...
@@ -25,8 +24,7 @@ EXPECT='*filter
-A FORWARD --limit 100/sec --limit-burst 42 -j ACCEPT
-A FORWARD --limit 100/sec --limit-burst 42 -j ACCEPT
-A FORWARD --limit 1000/sec --limit-burst 5 -j ACCEPT
-A FORWARD --limit 1000/sec --limit-burst 5 -j ACCEPT
-A FORWARD --log-level notice --log-prefix "foobar" -j CONTINUE
-A FORWARD --log-level notice --log-prefix "foobar" -j CONTINUE
-A FORWARD --log-level notice --log-prefix "" -j CONTINUE
-A FORWARD --log-level notice --log-prefix "" -j CONTINUE'
'
$XT_MULTI
ebtables
--init-table
$XT_MULTI
ebtables
--init-table
$XT_MULTI
ebtables-restore
<<<
$DUMP
$XT_MULTI
ebtables-restore
<<<
$DUMP
...
...
iptables/tests/shell/testcases/ebtables/0004-save-counters_0
0 → 100755
View file @
290749d4
#!/bin/bash
set
-e
# there is no legacy backend to test
[[
$XT_MULTI
==
*
/xtables-nft-multi
]]
||
{
echo
"skip
$XT_MULTI
"
;
exit
0
;
}
$XT_MULTI
ebtables
--init-table
$XT_MULTI
ebtables
-A
FORWARD
-i
nodev123
-o
nodev432
-j
ACCEPT
$XT_MULTI
ebtables
-A
FORWARD
-i
nodev432
-o
nodev123
-j
ACCEPT
EXPECT
=
'Bridge table: filter
Bridge chain: FORWARD, entries: 2, policy: ACCEPT
-i nodev123 -o nodev432 -j ACCEPT
-i nodev432 -o nodev123 -j ACCEPT'
echo
"ebtables -L FORWARD"
diff
-u
<
(
echo
-e
"
$EXPECT
"
)
<
(
$XT_MULTI
ebtables
-L
FORWARD
)
EXPECT
=
'Bridge table: filter
Bridge chain: FORWARD, entries: 2, policy: ACCEPT
-i nodev123 -o nodev432 -j ACCEPT , pcnt = 0 -- bcnt = 0
-i nodev432 -o nodev123 -j ACCEPT , pcnt = 0 -- bcnt = 0'
echo
"ebtables -L FORWARD --Lc"
diff
-u
<
(
echo
-e
"
$EXPECT
"
)
<
(
$XT_MULTI
ebtables
-L
FORWARD
--Lc
)
EXPECT
=
'*filter
:INPUT ACCEPT
:FORWARD ACCEPT
:OUTPUT ACCEPT
-A FORWARD -i nodev123 -o nodev432 -j ACCEPT
-A FORWARD -i nodev432 -o nodev123 -j ACCEPT'
echo
"ebtables-save"
diff
-u
<
(
echo
-e
"
$EXPECT
"
)
<
(
$XT_MULTI
ebtables-save |
grep
-v
'^#'
)
EXPECT
=
'*filter
:INPUT ACCEPT
:FORWARD ACCEPT
:OUTPUT ACCEPT
[0:0] -A FORWARD -i nodev123 -o nodev432 -j ACCEPT
[0:0] -A FORWARD -i nodev432 -o nodev123 -j ACCEPT'
echo
"ebtables-save -c"
diff
-u
<
(
echo
-e
"
$EXPECT
"
)
<
(
$XT_MULTI
ebtables-save
-c
|
grep
-v
'^#'
)
export
EBTABLES_SAVE_COUNTER
=
yes
# -c flag overrides EBTABLES_SAVE_COUNTER variable
echo
"EBTABLES_SAVE_COUNTER=yes ebtables-save -c"
diff
-u
<
(
echo
-e
"
$EXPECT
"
)
<
(
$XT_MULTI
ebtables-save
-c
|
grep
-v
'^#'
)
EXPECT
=
'*filter
:INPUT ACCEPT
:FORWARD ACCEPT
:OUTPUT ACCEPT
-A FORWARD -i nodev123 -o nodev432 -j ACCEPT -c 0 0
-A FORWARD -i nodev432 -o nodev123 -j ACCEPT -c 0 0'
echo
"EBTABLES_SAVE_COUNTER=yes ebtables-save"
diff
-u
<
(
echo
-e
"
$EXPECT
"
)
<
(
$XT_MULTI
ebtables-save |
grep
-v
'^#'
)
iptables/tests/shell/testcases/ebtables/0005-ifnamechecks_0
0 → 100755
View file @
290749d4
#!/bin/bash
set
-e
# there is no legacy backend to test
[[
$XT_MULTI
==
*
/xtables-nft-multi
]]
||
{
echo
"skip
$XT_MULTI
"
;
exit
0
;
}
EXPECT
=
'*filter
:INPUT ACCEPT
:FORWARD ACCEPT
:OUTPUT ACCEPT
:PVEFW-FORWARD ACCEPT
:PVEFW-FWBR-OUT ACCEPT
-A FORWARD -j PVEFW-FORWARD
-A PVEFW-FORWARD -p IPv4 -j ACCEPT
-A PVEFW-FORWARD -p IPv6 -j ACCEPT
-A PVEFW-FORWARD -i fwln+ -j ACCEPT
-A PVEFW-FORWARD -o fwln+ -j PVEFW-FWBR-OUT'
$XT_MULTI
ebtables-restore
<<<
$EXPECT
exec
diff
-u
<
(
echo
-e
"
$EXPECT
"
)
<
(
$XT_MULTI
ebtables-save |
grep
-v
'^#'
)
iptables/tests/shell/testcases/ipt-restore/0003-restore-ordering_0
View file @
290749d4
...
@@ -14,7 +14,7 @@ ipt_show() {
...
@@ -14,7 +14,7 @@ ipt_show() {
$XT_MULTI
iptables-restore
<<
EOF
$XT_MULTI
iptables-restore
<<
EOF
*filter
*filter
-A FORWARD -m comment --comment "
appended
rule" -j ACCEPT
-A FORWARD -m comment --comment "rule
4
" -j ACCEPT
-I FORWARD 1 -m comment --comment "rule 1" -j ACCEPT
-I FORWARD 1 -m comment --comment "rule 1" -j ACCEPT
-I FORWARD 2 -m comment --comment "rule 2" -j ACCEPT
-I FORWARD 2 -m comment --comment "rule 2" -j ACCEPT
-I FORWARD 3 -m comment --comment "rule 3" -j ACCEPT
-I FORWARD 3 -m comment --comment "rule 3" -j ACCEPT
...
@@ -24,7 +24,7 @@ EOF
...
@@ -24,7 +24,7 @@ EOF
EXPECT
=
'-A FORWARD -m comment --comment "rule 1" -j ACCEPT
EXPECT
=
'-A FORWARD -m comment --comment "rule 1" -j ACCEPT
-A FORWARD -m comment --comment "rule 2" -j ACCEPT
-A FORWARD -m comment --comment "rule 2" -j ACCEPT
-A FORWARD -m comment --comment "rule 3" -j ACCEPT
-A FORWARD -m comment --comment "rule 3" -j ACCEPT
-A FORWARD -m comment --comment "
appended
rule" -j ACCEPT'
-A FORWARD -m comment --comment "rule
4
" -j ACCEPT'
diff
-u
-Z
<
(
echo
-e
"
$EXPECT
"
)
<
(
ipt_show
)
diff
-u
-Z
<
(
echo
-e
"
$EXPECT
"
)
<
(
ipt_show
)
...
@@ -32,11 +32,14 @@ diff -u -Z <(echo -e "$EXPECT") <(ipt_show)
...
@@ -32,11 +32,14 @@ diff -u -Z <(echo -e "$EXPECT") <(ipt_show)
$XT_MULTI
iptables-restore
--noflush
<<
EOF
$XT_MULTI
iptables-restore
--noflush
<<
EOF
*filter
*filter
-A FORWARD -m comment --comment "rule 5" -j ACCEPT
-I FORWARD 1 -m comment --comment "rule 0.5" -j ACCEPT
-I FORWARD 1 -m comment --comment "rule 0.5" -j ACCEPT
-I FORWARD 3 -m comment --comment "rule 1.5" -j ACCEPT
-I FORWARD 3 -m comment --comment "rule 1.5" -j ACCEPT
-I FORWARD 5 -m comment --comment "rule 2.5" -j ACCEPT
-I FORWARD 5 -m comment --comment "rule 2.5" -j ACCEPT
-I FORWARD 7 -m comment --comment "rule 3.5" -j ACCEPT
-I FORWARD 7 -m comment --comment "rule 3.5" -j ACCEPT
-I FORWARD 9 -m comment --comment "appended rule 2" -j ACCEPT
-I FORWARD 9 -m comment --comment "rule 4.5" -j ACCEPT
-I FORWARD 11 -m comment --comment "rule 5.5" -j ACCEPT
-A FORWARD -m comment --comment "rule 6" -j ACCEPT
COMMIT
COMMIT
EOF
EOF
...
@@ -47,8 +50,11 @@ EXPECT='-A FORWARD -m comment --comment "rule 0.5" -j ACCEPT
...
@@ -47,8 +50,11 @@ EXPECT='-A FORWARD -m comment --comment "rule 0.5" -j ACCEPT
-A FORWARD -m comment --comment "rule 2.5" -j ACCEPT
-A FORWARD -m comment --comment "rule 2.5" -j ACCEPT
-A FORWARD -m comment --comment "rule 3" -j ACCEPT
-A FORWARD -m comment --comment "rule 3" -j ACCEPT
-A FORWARD -m comment --comment "rule 3.5" -j ACCEPT
-A FORWARD -m comment --comment "rule 3.5" -j ACCEPT
-A FORWARD -m comment --comment "appended rule" -j ACCEPT
-A FORWARD -m comment --comment "rule 4" -j ACCEPT
-A FORWARD -m comment --comment "appended rule 2" -j ACCEPT'
-A FORWARD -m comment --comment "rule 4.5" -j ACCEPT
-A FORWARD -m comment --comment "rule 5" -j ACCEPT
-A FORWARD -m comment --comment "rule 5.5" -j ACCEPT
-A FORWARD -m comment --comment "rule 6" -j ACCEPT'
diff
-u
-Z
<
(
echo
-e
"
$EXPECT
"
)
<
(
ipt_show
)
diff
-u
-Z
<
(
echo
-e
"
$EXPECT
"
)
<
(
ipt_show
)
...
@@ -78,6 +84,8 @@ diff -u -Z <(echo -e "$EXPECT") <(ipt_show)
...
@@ -78,6 +84,8 @@ diff -u -Z <(echo -e "$EXPECT") <(ipt_show)
$XT_MULTI
iptables-restore
--noflush
<<
EOF
$XT_MULTI
iptables-restore
--noflush
<<
EOF
*filter
*filter
-A FORWARD -m comment --comment "appended rule 4" -j ACCEPT
-D FORWARD 7
-D FORWARD -m comment --comment "appended rule 1" -j ACCEPT
-D FORWARD -m comment --comment "appended rule 1" -j ACCEPT
-D FORWARD 3
-D FORWARD 3
-I FORWARD 3 -m comment --comment "manually replaced rule 2" -j ACCEPT
-I FORWARD 3 -m comment --comment "manually replaced rule 2" -j ACCEPT
...
...
iptables/tests/shell/testcases/ipt-restore/0004-restore-race_0
View file @
290749d4
...
@@ -24,7 +24,7 @@ clean_tempfile()
...
@@ -24,7 +24,7 @@ clean_tempfile()
trap
clean_tempfile EXIT
trap
clean_tempfile EXIT
ENTRY_NUM
=
$((
RANDOM%10
0
))
ENTRY_NUM
=
$((
RANDOM%10
))
UCHAIN_NUM
=
$((
RANDOM%10
))
UCHAIN_NUM
=
$((
RANDOM%10
))
get_target
()
get_target
()
...
@@ -87,7 +87,7 @@ fi
...
@@ -87,7 +87,7 @@ fi
case
"
$XT_MULTI
"
in
case
"
$XT_MULTI
"
in
*
/xtables-nft-multi
)
*
/xtables-nft-multi
)
attempts
=
$((
RANDOM%
20
0
))
attempts
=
$((
RANDOM%
1
0
))
attempts
=
$((
attempts+1
))
attempts
=
$((
attempts+1
))
;;
;;
*
)
*
)
...
...
iptables/tests/shell/testcases/ipt-restore/0005-ipt-6_0
0 → 100755
View file @
290749d4
#!/bin/bash
# Make sure iptables-restore simply ignores
# rules starting with -6
set
-e
# show rules, drop uninteresting policy settings
ipt_show
()
{
$XT_MULTI
iptables
-S
|
grep
-v
'^-P'
}
# issue reproducer for iptables-restore
$XT_MULTI
iptables-restore
<<
EOF
*filter
-A FORWARD -m comment --comment any -j ACCEPT
-4 -A FORWARD -m comment --comment ipv4 -j ACCEPT
-6 -A FORWARD -m comment --comment ipv6 -j ACCEPT
COMMIT
EOF
EXPECT
=
'-A FORWARD -m comment --comment any -j ACCEPT
-A FORWARD -m comment --comment ipv4 -j ACCEPT'
diff
-u
-Z
<
(
echo
-e
"
$EXPECT
"
)
<
(
ipt_show
)
iptables/tests/shell/testcases/ipt-restore/0006-ip6t-4_0
0 → 100755
View file @
290749d4
#!/bin/bash
# Make sure ip6tables-restore simply ignores
# rules starting with -4
set
-e
# show rules, drop uninteresting policy settings
ipt_show
()
{
$XT_MULTI
ip6tables
-S
|
grep
-v
'^-P'
}
# issue reproducer for ip6tables-restore
$XT_MULTI
ip6tables-restore
<<
EOF
*filter
-A FORWARD -m comment --comment any -j ACCEPT
-4 -A FORWARD -m comment --comment ipv4 -j ACCEPT
-6 -A FORWARD -m comment --comment ipv6 -j ACCEPT
COMMIT
EOF
EXPECT
=
'-A FORWARD -m comment --comment any -j ACCEPT
-A FORWARD -m comment --comment ipv6 -j ACCEPT'
diff
-u
-Z
<
(
echo
-e
"
$EXPECT
"
)
<
(
ipt_show
)
Prev
1
2
3
4
5
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment