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 @@
#include "nft.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
xtables_rule_match
*
matchp
;
...
...
@@ -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
);
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
)
return
ret
;
}
...
...
@@ -261,12 +261,12 @@ static void print_fragment(unsigned int flags, unsigned int invflags,
fputc
(
' '
,
stdout
);
}
static
void
nft_ipv4_print_rule
(
struct
nft
nl_ru
le
*
r
,
unsigned
int
num
,
unsigned
int
format
)
static
void
nft_ipv4_print_rule
(
struct
nft
_hand
le
*
h
,
struct
nftnl_rule
*
r
,
unsigned
int
num
,
unsigned
int
format
)
{
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
,
cs
.
fw
.
ip
.
invflags
,
cs
.
fw
.
ip
.
proto
,
num
,
format
);
...
...
iptables/nft-ipv6.c
View file @
290749d4
...
...
@@ -25,7 +25,7 @@
#include "nft.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
xtables_rule_match
*
matchp
;
...
...
@@ -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
);
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
)
return
ret
;
}
...
...
@@ -187,12 +187,12 @@ static void nft_ipv6_parse_immediate(const char *jumpto, bool nft_goto,
cs
->
fw6
.
ipv6
.
flags
|=
IP6T_F_GOTO
;
}
static
void
nft_ipv6_print_rule
(
struct
nft
nl_ru
le
*
r
,
unsigned
int
num
,
unsigned
int
format
)
static
void
nft_ipv6_print_rule
(
struct
nft
_hand
le
*
h
,
struct
nftnl_rule
*
r
,
unsigned
int
num
,
unsigned
int
format
)
{
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
,
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)
}
/* 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
;
...
...
@@ -310,7 +310,6 @@ static void nft_parse_target(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
struct
xtables_target
*
target
;
struct
xt_entry_target
*
t
;
size_t
size
;
struct
nft_family_ops
*
ops
;
void
*
data
=
ctx
->
cs
;
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)
target
->
t
=
t
;
ops
=
nft_family_ops_lookup
(
ctx
->
family
);
ops
->
parse_target
(
target
,
data
);
ctx
->
h
->
ops
->
parse_target
(
target
,
data
);
}
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_rule_match
**
matches
;
struct
xt_entry_match
*
m
;
struct
nft_family_ops
*
ops
;
switch
(
ctx
->
family
)
{
switch
(
ctx
->
h
->
family
)
{
case
NFPROTO_IPV4
:
case
NFPROTO_IPV6
:
case
NFPROTO_BRIDGE
:
...
...
@@ -349,7 +346,7 @@ static void nft_parse_match(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
break
;
default:
fprintf
(
stderr
,
"BUG: nft_parse_match() unknown family %d
\n
"
,
ctx
->
family
);
ctx
->
h
->
family
);
exit
(
EXIT_FAILURE
);
}
...
...
@@ -365,9 +362,8 @@ static void nft_parse_match(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
match
->
m
=
m
;
ops
=
nft_family_ops_lookup
(
ctx
->
family
);
if
(
ops
->
parse_match
!=
NULL
)
ops
->
parse_match
(
match
,
ctx
->
cs
);
if
(
ctx
->
h
->
ops
->
parse_match
!=
NULL
)
ctx
->
h
->
ops
->
parse_match
(
match
,
ctx
->
cs
);
}
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)
static
void
nft_meta_set_to_target
(
struct
nft_xt_ctx
*
ctx
)
{
const
struct
nft_family_ops
*
ops
;
struct
xtables_target
*
target
;
struct
xt_entry_target
*
t
;
unsigned
int
size
;
...
...
@@ -429,8 +424,7 @@ static void nft_meta_set_to_target(struct nft_xt_ctx *ctx)
target
->
t
=
t
;
ops
=
nft_family_ops_lookup
(
ctx
->
family
);
ops
->
parse_target
(
target
,
ctx
->
cs
);
ctx
->
h
->
ops
->
parse_target
(
target
,
ctx
->
cs
);
}
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
)
{
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
->
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
.
len
=
nftnl_expr_get_u32
(
e
,
NFTNL_EXPR_PAYLOAD_LEN
);
ctx
->
flags
|=
NFT_XT_CTX_PAYLOAD
;
}
...
...
@@ -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
)
{
struct
nft_family_ops
*
ops
=
nft_family_ops_lookup
(
ctx
->
family
);
void
*
data
=
ctx
->
cs
;
uint32_t
reg
;
...
...
@@ -483,12 +484,12 @@ static void nft_parse_cmp(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
return
;
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
;
}
/* bitwise context is interpreted from 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
;
}
}
...
...
@@ -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
)
{
const
char
*
chain
=
nftnl_expr_get_str
(
e
,
NFTNL_EXPR_IMM_CHAIN
);
struct
nft_family_ops
*
ops
;
const
char
*
jumpto
=
NULL
;
bool
nft_goto
=
false
;
void
*
data
=
ctx
->
cs
;
...
...
@@ -544,8 +544,7 @@ static void nft_parse_immediate(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
break
;
}
ops
=
nft_family_ops_lookup
(
ctx
->
family
);
ops
->
parse_immediate
(
jumpto
,
nft_goto
,
data
);
ctx
->
h
->
ops
->
parse_immediate
(
jumpto
,
nft_goto
,
data
);
}
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
);
struct
xtables_rule_match
**
matches
;
struct
xtables_match
*
match
;
struct
nft_family_ops
*
ops
;
struct
xt_rateinfo
*
rinfo
;
size_t
size
;
switch
(
ctx
->
family
)
{
switch
(
ctx
->
h
->
family
)
{
case
NFPROTO_IPV4
:
case
NFPROTO_IPV6
:
case
NFPROTO_BRIDGE
:
matches
=
&
ctx
->
cs
->
matches
;
break
;
default:
fprintf
(
stderr
,
"BUG: nft_parse_
match
() unknown family %d
\n
"
,
ctx
->
family
);
fprintf
(
stderr
,
"BUG: nft_parse_
limit
() unknown family %d
\n
"
,
ctx
->
h
->
family
);
exit
(
EXIT_FAILURE
);
}
...
...
@@ -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
->
burst
=
burst
;
ops
=
nft_family_ops_lookup
(
ctx
->
family
);
if
(
ops
->
parse_match
!=
NULL
)
ops
->
parse_match
(
match
,
ctx
->
cs
);
if
(
ctx
->
h
->
ops
->
parse_match
!=
NULL
)
ctx
->
h
->
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
nftnl_expr_iter
*
iter
;
struct
nftnl_expr
*
expr
;
int
family
=
nftnl_rule_get_u32
(
r
,
NFTNL_RULE_FAMILY
);
struct
nft_xt_ctx
ctx
=
{
.
cs
=
cs
,
.
family
=
family
,
.
h
=
h
,
.
table
=
nftnl_rule_get_str
(
r
,
NFTNL_RULE_TABLE
),
};
iter
=
nftnl_expr_iter_create
(
r
);
...
...
@@ -630,6 +635,8 @@ void nft_rule_to_iptables_command_state(const struct nftnl_rule *r,
nft_parse_target
(
&
ctx
,
expr
);
else
if
(
strcmp
(
name
,
"limit"
)
==
0
)
nft_parse_limit
(
&
ctx
,
expr
);
else
if
(
strcmp
(
name
,
"lookup"
)
==
0
)
nft_parse_lookup
(
&
ctx
,
h
,
expr
);
expr
=
nftnl_expr_iter_next
(
iter
);
}
...
...
@@ -982,19 +989,18 @@ void nft_ipv46_parse_target(struct xtables_target *t, void *data)
cs
->
target
=
t
;
}
bool
nft_ipv46_rule_find
(
struct
nft_family_ops
*
ops
,
struct
nftnl_rule
*
r
,
void
*
data
)
bool
nft_ipv46_rule_find
(
struct
nft_handle
*
h
,
struct
nftnl_rule
*
r
,
void
*
data
)
{
struct
iptables_command_state
*
cs
=
data
,
this
=
{};
bool
ret
=
false
;
nft_rule_to_iptables_command_state
(
r
,
&
this
);
nft_rule_to_iptables_command_state
(
h
,
r
,
&
this
);
DEBUGP
(
"comparing with... "
);
#ifdef DEBUG_DEL
nft_rule_print_save
(
r
,
NFT_RULE_APPEND
,
0
);
#endif
if
(
!
ops
->
is_same
(
cs
,
&
this
))
if
(
!
h
->
ops
->
is_same
(
cs
,
&
this
))
goto
out
;
if
(
!
compare_matches
(
cs
->
matches
,
this
.
matches
))
{
...
...
@@ -1014,7 +1020,7 @@ bool nft_ipv46_rule_find(struct nft_family_ops *ops,
ret
=
true
;
out:
ops
->
clear_cs
(
&
this
);
h
->
ops
->
clear_cs
(
&
this
);
return
ret
;
}
...
...
iptables/nft-shared.h
View file @
290749d4
...
...
@@ -35,6 +35,7 @@
#define FMT(tab,notab) ((format) & FMT_NOTABLE ? (notab) : (tab))
struct
xtables_args
;
struct
nft_handle
;
struct
xt_xlate
;
enum
{
...
...
@@ -42,19 +43,22 @@ enum {
NFT_XT_CTX_META
=
(
1
<<
1
),
NFT_XT_CTX_BITWISE
=
(
1
<<
2
),
NFT_XT_CTX_IMMEDIATE
=
(
1
<<
3
),
NFT_XT_CTX_PREV_PAYLOAD
=
(
1
<<
4
),
};
struct
nft_xt_ctx
{
struct
iptables_command_state
*
cs
;
struct
nftnl_expr_iter
*
iter
;
int
family
;
struct
nft_handle
*
h
;
uint32_t
flags
;
const
char
*
table
;
uint32_t
reg
;
struct
{
uint32_t
base
;
uint32_t
offset
;
uint32_t
len
;
}
payload
;
}
payload
,
prev_
payload
;
struct
{
uint32_t
key
;
}
meta
;
...
...
@@ -69,7 +73,7 @@ struct nft_xt_ctx {
};
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
,
const
void
*
data_b
);
void
(
*
print_payload
)(
struct
nftnl_expr
*
e
,
...
...
@@ -82,6 +86,8 @@ struct nft_family_ops {
void
*
data
);
void
(
*
parse_cmp
)(
struct
nft_xt_ctx
*
ctx
,
struct
nftnl_expr
*
e
,
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
(
*
print_table_header
)(
const
char
*
tablename
);
...
...
@@ -89,8 +95,8 @@ struct nft_family_ops {
const
char
*
pol
,
const
struct
xt_counters
*
counters
,
bool
basechain
,
uint32_t
refs
,
uint32_t
entries
);
void
(
*
print_rule
)(
struct
nft
nl_ru
le
*
r
,
unsigned
int
num
,
unsigned
int
format
);
void
(
*
print_rule
)(
struct
nft
_hand
le
*
h
,
struct
nftnl_rule
*
r
,
unsigned
int
num
,
unsigned
int
format
);
void
(
*
save_rule
)(
const
void
*
data
,
unsigned
int
format
);
void
(
*
save_counters
)(
const
void
*
data
);
void
(
*
save_chain
)(
const
struct
nftnl_chain
*
c
,
const
char
*
policy
);
...
...
@@ -100,10 +106,10 @@ struct nft_family_ops {
struct
xtables_args
*
args
);
void
(
*
parse_match
)(
struct
xtables_match
*
m
,
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
);
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
);
int
(
*
xlate
)(
const
void
*
data
,
struct
xt_xlate
*
xl
);
};
...
...
@@ -111,7 +117,7 @@ struct nft_family_ops {
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_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_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
);
...
...
@@ -137,7 +143,8 @@ int parse_meta(struct nftnl_expr *e, uint8_t key, char *iniface,
unsigned
char
*
outiface_mask
,
uint8_t
*
invflags
);
void
print_proto
(
uint16_t
proto
,
int
invert
);
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
);
void
nft_clear_iptables_command_state
(
struct
iptables_command_state
*
cs
);
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,
struct
nft_family_ops
*
nft_family_ops_lookup
(
int
family
);
struct
nft_handle
;
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
);
bool
compare_matches
(
struct
xtables_rule_match
*
mt1
,
struct
xtables_rule_match
*
mt2
);
...
...
@@ -199,23 +205,6 @@ struct xtables_args {
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
{
unsigned
int
command
;
unsigned
int
rulenum
;
...
...
@@ -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
xtables_args
*
args
);
struct
nft_xt_restore_parse
{
FILE
*
in
;
int
testing
;
const
char
*
tablename
;
bool
commit
;
};
struct
nftnl_chain_list
;
struct
nft_xt_restore_cb
{
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
,
const
char
*
chain
,
const
char
*
policy
,
const
struct
xt_counters
*
counters
);
...
...
@@ -260,10 +240,16 @@ struct nft_xt_restore_cb {
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
,
struct
nft_xt_restore_parse
*
p
,
struct
nft_xt_restore_cb
*
cb
,
int
argc
,
char
*
argv
[]);
const
struct
nft_xt_restore_parse
*
p
);
void
nft_check_xt_legacy
(
int
family
,
bool
is_ipt_save
);
#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 {
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
nftnl_table_list
*
tables
;
struct
{
struct
nftnl_chain_list
*
chains
;
struct
nftnl_set_list
*
sets
;
bool
initialized
;
}
table
[
NFT_TABLE_MAX
];
};
...
...
@@ -38,6 +47,8 @@ struct nft_cache {
struct
nft_handle
{
int
family
;
struct
mnl_socket
*
nl
;
int
nlsndbuffsiz
;
int
nlrcvbuffsiz
;
uint32_t
portid
;
uint32_t
seq
;
uint32_t
nft_genid
;
...
...
@@ -51,7 +62,7 @@ struct nft_handle {
unsigned
int
cache_index
;
struct
nft_cache
__cache
[
2
];
struct
nft_cache
*
cache
;
bool
have_cache
;
enum
nft_cache_level
cache_level
;
bool
restore
;
bool
noflush
;
int8_t
config_done
;
...
...
@@ -71,7 +82,7 @@ int mnl_talk(struct nft_handle *h, struct nlmsghdr *nlh,
void
*
data
);
int
nft_init
(
struct
nft_handle
*
h
,
const
struct
builtin_table
*
t
);
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.
...
...
@@ -79,7 +90,7 @@ void nft_build_cache(struct nft_handle *h);
struct
nftnl_table
;
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
);
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
);
...
...
@@ -92,8 +103,6 @@ const struct builtin_table *nft_table_builtin_find(struct nft_handle *h, const c
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
);
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_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
);
...
...
@@ -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
);
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
);
void
nft_bridge_chain_postprocess
(
struct
nft_handle
*
h
,
struct
nftnl_chain
*
c
);
/*
* Operations with rule-set.
...
...
@@ -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_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_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
);
...
...
@@ -136,8 +148,8 @@ enum nft_rule_print {
NFT_RULE_DEL
,
};
void
nft_rule_print_save
(
const
struct
nftnl_rule
*
r
,
enum
nft_rule_print
type
,
unsigned
int
format
);
void
nft_rule_print_save
(
struct
nft_handle
*
h
,
const
struct
nftnl_rule
*
r
,
enum
nft_rule_print
type
,
unsigned
int
format
);
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
*/
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_policy_rule
(
struct
nft_handle
*
h
,
const
char
*
table
);
...
...
@@ -168,22 +181,6 @@ int nft_init_eb(struct nft_handle *h, const char *pname);
int
ebt_get_current_chain
(
const
char
*
chain
);
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
*/
...
...
@@ -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
);
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
,
const
char
*
chain
,
const
char
*
policy
);
...
...
iptables/tests/shell/run-tests.sh
View file @
290749d4
...
...
@@ -38,6 +38,14 @@ while [ -n "$1" ]; do
HOST
=
y
shift
;;
-l
|
--legacy
)
LEGACY_ONLY
=
y
shift
;;
-n
|
--nft
)
NFT_ONLY
=
y
shift
;;
*${
RETURNCODE_SEPARATOR
}
+
([
0-9]
)
)
SINGLE+
=
"
$1
"
VERBOSE
=
y
...
...
@@ -98,19 +106,23 @@ do_test() {
}
echo
""
for
testfile
in
$(
find_tests
)
;
do
do_test
"
$testfile
"
"
$XTABLES_LEGACY_MULTI
"
done
msg_info
"legacy results: [OK]
$ok
[FAILED]
$failed
[TOTAL]
$((
ok+failed
))
"
if
[
"
$NFT_ONLY
"
!=
"y"
]
;
then
for
testfile
in
$(
find_tests
)
;
do
do_test
"
$testfile
"
"
$XTABLES_LEGACY_MULTI
"
done
msg_info
"legacy results: [OK]
$ok
[FAILED]
$failed
[TOTAL]
$((
ok+failed
))
"
fi
legacy_ok
=
$ok
legacy_fail
=
$failed
ok
=
0
failed
=
0
for
testfile
in
$(
find_tests
)
;
do
do_test
"
$testfile
"
"
$XTABLES_NFT_MULTI
"
done
msg_info
"nft results: [OK]
$ok
[FAILED]
$failed
[TOTAL]
$((
ok+failed
))
"
if
[
"
$LEGACY_ONLY
"
!=
"y"
]
;
then
for
testfile
in
$(
find_tests
)
;
do
do_test
"
$testfile
"
"
$XTABLES_NFT_MULTI
"
done
msg_info
"nft results: [OK]
$ok
[FAILED]
$failed
[TOTAL]
$((
ok+failed
))
"
fi
ok
=
$((
legacy_ok+ok
))
failed
=
$((
legacy_fail+failed
))
...
...
iptables/tests/shell/testcases/arptables/0001-arptables-save-restore_0
View file @
290749d4
...
...
@@ -50,13 +50,12 @@ DUMP='*filter
-A foo -j MARK --set-mark 12345
-A foo -j ACCEPT --opcode 1
-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
$XT_MULTI
arptables
-F
$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
DUMP
=
'*filter
:OUTPUT ACCEPT
-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
...
...
@@ -20,8 +19,7 @@ EXPECT='*filter
:INPUT ACCEPT
:OUTPUT ACCEPT
-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-restore
<<<
$DUMP
...
...
iptables/tests/shell/testcases/arptables/0003-arptables-verbose-output_0
View file @
290749d4
...
...
@@ -58,7 +58,6 @@ EXPECT='*filter
-A INPUT -j MARK -i eth23 --set-mark 42
-A OUTPUT -j CLASSIFY -o eth23 --set-class 23:42
-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
get_entries_count
()
{
# (chain)
$XT_MULTI
ebtables
-L
$1
|
sed
-n
's/.*entries: \([0-9]*\).*/\1/p'
}
set
-x
case
"
$XT_MULTI
"
in
*
/xtables-nft-multi
)
...
...
@@ -28,32 +32,32 @@ case "$XT_MULTI" in
exit
1
fi
$XT_MULTI
ebtables
-L
FOO |
grep
-q
'entries: 0'
if
[
$
?
-ne
0
]
;
then
echo
"Unexpected entries count in empty unreferenced chain"
entries
=
$(
get_entries_count FOO
)
if
[
$
entries
-ne
0
]
;
then
echo
"Unexpected entries count in empty unreferenced chain
(expected 0, have
$entries
)
"
$XT_MULTI
ebtables
-L
exit
1
fi
$XT_MULTI
ebtables
-A
FORWARD
-j
FOO
$XT_MULTI
ebtables
-L
FORWARD |
grep
-q
'entries: 1'
if
[
$
?
-ne
0
]
;
then
echo
"Unexpected entries count in FORWARD chain"
entries
=
$(
get_entries_count FORWARD
)
if
[
$
entries
-ne
1
]
;
then
echo
"Unexpected entries count in FORWARD chain
(expected 1, have
$entries
)
"
$XT_MULTI
ebtables
-L
exit
1
fi
$XT_MULTI
ebtables
-L
FOO |
grep
-q
'entries: 0'
if
[
$
?
-ne
0
]
;
then
echo
"Unexpected entries count in empty referenced chain"
entries
=
$(
get_entries_count FOO
)
if
[
$
entries
-ne
0
]
;
then
echo
"Unexpected entries count in empty referenced chain
(expected 0, have
$entries
)
"
$XT_MULTI
ebtables
-L
exit
1
fi
$XT_MULTI
ebtables
-A
FOO
-j
ACCEPT
$XT_MULTI
ebtables
-L
FOO |
grep
-q
'entries: 1'
if
[
$
?
-ne
0
]
;
then
echo
"Unexpected entries count in non-empty referenced chain"
entries
=
$(
get_entries_count FOO
)
if
[
$
entries
-ne
1
]
;
then
echo
"Unexpected entries count in non-empty referenced chain
(expected 1, have
$entries
)
"
$XT_MULTI
ebtables
-L
exit
1
fi
...
...
iptables/tests/shell/testcases/ebtables/0002-ebtables-save-restore_0
View file @
290749d4
...
...
@@ -99,7 +99,6 @@ DUMP='*filter
-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 --limit 100/sec --limit-burst 5 -j ACCEPT
*nat
:PREROUTING ACCEPT
:OUTPUT DROP
...
...
@@ -107,8 +106,7 @@ DUMP='*filter
:nat_foo DROP
-A PREROUTING -j redirect
-A OUTPUT -j ACCEPT
-A POSTROUTING -j ACCEPT
'
-A POSTROUTING -j ACCEPT'
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
-A FORWARD --limit 100 --limit-burst 42 -j ACCEPT
-A FORWARD --limit 1000 -j ACCEPT
-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
...
...
@@ -25,8 +24,7 @@ EXPECT='*filter
-A FORWARD --limit 100/sec --limit-burst 42 -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 "" -j CONTINUE
'
-A FORWARD --log-level notice --log-prefix "" -j CONTINUE'
$XT_MULTI
ebtables
--init-table
$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() {
$XT_MULTI
iptables-restore
<<
EOF
*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 2 -m comment --comment "rule 2" -j ACCEPT
-I FORWARD 3 -m comment --comment "rule 3" -j ACCEPT
...
...
@@ -24,7 +24,7 @@ EOF
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 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
)
...
...
@@ -32,11 +32,14 @@ diff -u -Z <(echo -e "$EXPECT") <(ipt_show)
$XT_MULTI
iptables-restore
--noflush
<<
EOF
*filter
-A FORWARD -m comment --comment "rule 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 5 -m comment --comment "rule 2.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
EOF
...
...
@@ -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 3" -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 "appended rule 2" -j ACCEPT'
-A FORWARD -m comment --comment "rule 4" -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
)
...
...
@@ -78,6 +84,8 @@ diff -u -Z <(echo -e "$EXPECT") <(ipt_show)
$XT_MULTI
iptables-restore
--noflush
<<
EOF
*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 3
-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()
trap
clean_tempfile EXIT
ENTRY_NUM
=
$((
RANDOM%10
0
))
ENTRY_NUM
=
$((
RANDOM%10
))
UCHAIN_NUM
=
$((
RANDOM%10
))
get_target
()
...
...
@@ -87,7 +87,7 @@ fi
case
"
$XT_MULTI
"
in
*
/xtables-nft-multi
)
attempts
=
$((
RANDOM%
20
0
))
attempts
=
$((
RANDOM%
1
0
))
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