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
6343d369
Commit
6343d369
authored
Jan 17, 2021
by
Arturo Borrero Gonzalez
Browse files
New upstream version 1.8.7
parent
9caffe92
Changes
44
Hide whitespace changes
Inline
Side-by-side
iptables/xtables-monitor.c
View file @
6343d369
...
@@ -106,6 +106,7 @@ static int rule_cb(const struct nlmsghdr *nlh, void *data)
...
@@ -106,6 +106,7 @@ static int rule_cb(const struct nlmsghdr *nlh, void *data)
printf
(
"-0 "
);
printf
(
"-0 "
);
break
;
break
;
default:
default:
puts
(
""
);
goto
err_free
;
goto
err_free
;
}
}
...
@@ -227,12 +228,12 @@ static void trace_print_rule(const struct nftnl_trace *nlt, struct cb_arg *args)
...
@@ -227,12 +228,12 @@ static void trace_print_rule(const struct nftnl_trace *nlt, struct cb_arg *args)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
nlh
=
nftnl_chain_nlmsg_build_hdr
(
buf
,
NFT_MSG_GETRULE
,
family
,
NLM_F_DUMP
,
0
);
nlh
=
nftnl_chain_nlmsg_build_hdr
(
buf
,
NFT_MSG_GETRULE
,
family
,
0
,
0
);
nftnl_rule_set_u32
(
r
,
NFTNL_RULE_FAMILY
,
family
);
nftnl_rule_set_u32
(
r
,
NFTNL_RULE_FAMILY
,
family
);
nftnl_rule_set_str
(
r
,
NFTNL_RULE_CHAIN
,
chain
);
nftnl_rule_set_str
(
r
,
NFTNL_RULE_CHAIN
,
chain
);
nftnl_rule_set_str
(
r
,
NFTNL_RULE_TABLE
,
table
);
nftnl_rule_set_str
(
r
,
NFTNL_RULE_TABLE
,
table
);
nftnl_rule_set_u64
(
r
,
NFTNL_RULE_
POSITION
,
handle
);
nftnl_rule_set_u64
(
r
,
NFTNL_RULE_
HANDLE
,
handle
);
nftnl_rule_nlmsg_build_payload
(
nlh
,
r
);
nftnl_rule_nlmsg_build_payload
(
nlh
,
r
);
nftnl_rule_free
(
r
);
nftnl_rule_free
(
r
);
...
@@ -248,24 +249,21 @@ static void trace_print_rule(const struct nftnl_trace *nlt, struct cb_arg *args)
...
@@ -248,24 +249,21 @@ static void trace_print_rule(const struct nftnl_trace *nlt, struct cb_arg *args)
}
}
portid
=
mnl_socket_get_portid
(
nl
);
portid
=
mnl_socket_get_portid
(
nl
);
if
(
mnl_socket_sendto
(
nl
,
nlh
,
nlh
->
nlmsg_len
)
<
0
)
{
if
(
mnl_socket_sendto
(
nl
,
nlh
,
nlh
->
nlmsg_len
)
<
0
)
{
perror
(
"mnl_socket_send"
);
perror
(
"mnl_socket_send"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
ret
=
mnl_socket_recvfrom
(
nl
,
buf
,
sizeof
(
buf
));
ret
=
mnl_socket_recvfrom
(
nl
,
buf
,
sizeof
(
buf
));
while
(
ret
>
0
)
{
if
(
ret
>
0
)
{
args
->
is_event
=
false
;
args
->
is_event
=
false
;
ret
=
mnl_cb_run
(
buf
,
ret
,
0
,
portid
,
rule_cb
,
args
);
ret
=
mnl_cb_run
(
buf
,
ret
,
0
,
portid
,
rule_cb
,
args
);
if
(
ret
<=
0
)
}
break
;
if
(
ret
==
-
1
)
{
ret
=
mnl_socket_recvfrom
(
nl
,
buf
,
sizeof
(
buf
));
perror
(
"error"
);
}
exit
(
EXIT_FAILURE
);
if
(
ret
==
-
1
)
{
}
perror
(
"error"
);
mnl_socket_close
(
nl
);
exit
(
EXIT_FAILURE
);
}
mnl_socket_close
(
nl
);
}
}
static
void
trace_print_packet
(
const
struct
nftnl_trace
*
nlt
,
struct
cb_arg
*
args
)
static
void
trace_print_packet
(
const
struct
nftnl_trace
*
nlt
,
struct
cb_arg
*
args
)
...
@@ -276,14 +274,14 @@ static void trace_print_packet(const struct nftnl_trace *nlt, struct cb_arg *arg
...
@@ -276,14 +274,14 @@ static void trace_print_packet(const struct nftnl_trace *nlt, struct cb_arg *arg
uint32_t
mark
;
uint32_t
mark
;
char
name
[
IFNAMSIZ
];
char
name
[
IFNAMSIZ
];
printf
(
"PACKET: %d %08x "
,
args
->
nfproto
,
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_ID
));
family
=
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_FAMILY
);
printf
(
"PACKET: %d %08x "
,
family
,
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_ID
));
if
(
nftnl_trace_is_set
(
nlt
,
NFTNL_TRACE_IIF
))
if
(
nftnl_trace_is_set
(
nlt
,
NFTNL_TRACE_IIF
))
printf
(
"IN=%s "
,
if_indextoname
(
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_IIF
),
name
));
printf
(
"IN=%s "
,
if_indextoname
(
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_IIF
),
name
));
if
(
nftnl_trace_is_set
(
nlt
,
NFTNL_TRACE_OIF
))
if
(
nftnl_trace_is_set
(
nlt
,
NFTNL_TRACE_OIF
))
printf
(
"OUT=%s "
,
if_indextoname
(
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_OIF
),
name
));
printf
(
"OUT=%s "
,
if_indextoname
(
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_OIF
),
name
));
family
=
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_FAMILY
);
nfproto
=
family
;
nfproto
=
family
;
if
(
nftnl_trace_is_set
(
nlt
,
NFTNL_TRACE_NFPROTO
))
{
if
(
nftnl_trace_is_set
(
nlt
,
NFTNL_TRACE_NFPROTO
))
{
nfproto
=
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_NFPROTO
);
nfproto
=
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_NFPROTO
);
...
@@ -308,6 +306,9 @@ static void trace_print_packet(const struct nftnl_trace *nlt, struct cb_arg *arg
...
@@ -308,6 +306,9 @@ static void trace_print_packet(const struct nftnl_trace *nlt, struct cb_arg *arg
printf
(
"MACDST=%s "
,
ether_ntoa
((
const
void
*
)
eh
->
h_dest
));
printf
(
"MACDST=%s "
,
ether_ntoa
((
const
void
*
)
eh
->
h_dest
));
printf
(
"MACPROTO=%04x "
,
ntohs
(
eh
->
h_proto
));
printf
(
"MACPROTO=%04x "
,
ntohs
(
eh
->
h_proto
));
break
;
break
;
case
ARPHRD_LOOPBACK
:
printf
(
"LOOPBACK "
);
break
;
default:
default:
printf
(
"LL=0x%x "
,
type
);
printf
(
"LL=0x%x "
,
type
);
for
(
i
=
0
;
i
<
len
;
i
++
)
for
(
i
=
0
;
i
<
len
;
i
++
)
...
@@ -436,9 +437,18 @@ static void trace_print_packet(const struct nftnl_trace *nlt, struct cb_arg *arg
...
@@ -436,9 +437,18 @@ static void trace_print_packet(const struct nftnl_trace *nlt, struct cb_arg *arg
mark
=
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_MARK
);
mark
=
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_MARK
);
if
(
mark
)
if
(
mark
)
printf
(
"MARK=0x%x "
,
mark
);
printf
(
"MARK=0x%x "
,
mark
);
puts
(
""
);
}
static
void
trace_print_hdr
(
const
struct
nftnl_trace
*
nlt
)
{
printf
(
" TRACE: %d %08x %s:%s"
,
nftnl_trace_get_u32
(
nlt
,
NFTNL_TABLE_FAMILY
),
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_ID
),
nftnl_trace_get_str
(
nlt
,
NFTNL_TRACE_TABLE
),
nftnl_trace_get_str
(
nlt
,
NFTNL_TRACE_CHAIN
));
}
}
static
void
print_verdict
(
struct
nftnl_trace
*
nlt
,
uint32_t
verdict
)
static
void
print_verdict
(
const
struct
nftnl_trace
*
nlt
,
uint32_t
verdict
)
{
{
const
char
*
chain
;
const
char
*
chain
;
...
@@ -499,38 +509,41 @@ static int trace_cb(const struct nlmsghdr *nlh, struct cb_arg *arg)
...
@@ -499,38 +509,41 @@ static int trace_cb(const struct nlmsghdr *nlh, struct cb_arg *arg)
arg
->
nfproto
!=
nftnl_trace_get_u32
(
nlt
,
NFTNL_TABLE_FAMILY
))
arg
->
nfproto
!=
nftnl_trace_get_u32
(
nlt
,
NFTNL_TABLE_FAMILY
))
goto
err_free
;
goto
err_free
;
printf
(
" TRACE: %d %08x %s:%s"
,
nftnl_trace_get_u32
(
nlt
,
NFTNL_TABLE_FAMILY
),
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_ID
),
nftnl_trace_get_str
(
nlt
,
NFTNL_TRACE_TABLE
),
nftnl_trace_get_str
(
nlt
,
NFTNL_TRACE_CHAIN
));
switch
(
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_TYPE
))
{
switch
(
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_TYPE
))
{
case
NFT_TRACETYPE_RULE
:
case
NFT_TRACETYPE_RULE
:
verdict
=
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_VERDICT
);
verdict
=
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_VERDICT
);
printf
(
":rule:0x%llx:"
,
(
unsigned
long
long
)
nftnl_trace_get_u64
(
nlt
,
NFTNL_TRACE_RULE_HANDLE
));
print_verdict
(
nlt
,
verdict
);
if
(
nftnl_trace_is_set
(
nlt
,
NFTNL_TRACE_RULE_HANDLE
))
trace_print_rule
(
nlt
,
arg
);
if
(
nftnl_trace_is_set
(
nlt
,
NFTNL_TRACE_LL_HEADER
)
||
if
(
nftnl_trace_is_set
(
nlt
,
NFTNL_TRACE_LL_HEADER
)
||
nftnl_trace_is_set
(
nlt
,
NFTNL_TRACE_NETWORK_HEADER
))
nftnl_trace_is_set
(
nlt
,
NFTNL_TRACE_NETWORK_HEADER
))
trace_print_packet
(
nlt
,
arg
);
trace_print_packet
(
nlt
,
arg
);
if
(
nftnl_trace_is_set
(
nlt
,
NFTNL_TRACE_RULE_HANDLE
))
{
trace_print_hdr
(
nlt
);
printf
(
":rule:0x%"
PRIx64
":"
,
nftnl_trace_get_u64
(
nlt
,
NFTNL_TRACE_RULE_HANDLE
));
print_verdict
(
nlt
,
verdict
);
printf
(
" "
);
trace_print_rule
(
nlt
,
arg
);
}
break
;
break
;
case
NFT_TRACETYPE_POLICY
:
case
NFT_TRACETYPE_POLICY
:
trace_print_hdr
(
nlt
);
printf
(
":policy:"
);
printf
(
":policy:"
);
verdict
=
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_POLICY
);
verdict
=
nftnl_trace_get_u32
(
nlt
,
NFTNL_TRACE_POLICY
);
print_verdict
(
nlt
,
verdict
);
print_verdict
(
nlt
,
verdict
);
puts
(
""
);
break
;
break
;
case
NFT_TRACETYPE_RETURN
:
case
NFT_TRACETYPE_RETURN
:
trace_print_hdr
(
nlt
);
printf
(
":return:"
);
printf
(
":return:"
);
trace_print_return
(
nlt
);
trace_print_return
(
nlt
);
puts
(
""
);
break
;
break
;
}
}
puts
(
""
);
err_free:
err_free:
nftnl_trace_free
(
nlt
);
nftnl_trace_free
(
nlt
);
err:
err:
fflush
(
stdout
);
return
MNL_CB_OK
;
return
MNL_CB_OK
;
}
}
...
...
iptables/xtables-save.c
View file @
6343d369
...
@@ -68,7 +68,6 @@ struct do_output_data {
...
@@ -68,7 +68,6 @@ struct do_output_data {
static
int
static
int
__do_output
(
struct
nft_handle
*
h
,
const
char
*
tablename
,
void
*
data
)
__do_output
(
struct
nft_handle
*
h
,
const
char
*
tablename
,
void
*
data
)
{
{
struct
nftnl_chain_list
*
chain_list
;
struct
do_output_data
*
d
=
data
;
struct
do_output_data
*
d
=
data
;
time_t
now
;
time_t
now
;
...
@@ -81,10 +80,6 @@ __do_output(struct nft_handle *h, const char *tablename, void *data)
...
@@ -81,10 +80,6 @@ __do_output(struct nft_handle *h, const char *tablename, void *data)
return
0
;
return
0
;
}
}
chain_list
=
nft_chain_list_get
(
h
,
tablename
,
NULL
);
if
(
!
chain_list
)
return
0
;
now
=
time
(
NULL
);
now
=
time
(
NULL
);
printf
(
"# Generated by %s v%s on %s"
,
prog_name
,
printf
(
"# Generated by %s v%s on %s"
,
prog_name
,
prog_vers
,
ctime
(
&
now
));
prog_vers
,
ctime
(
&
now
));
...
@@ -92,7 +87,7 @@ __do_output(struct nft_handle *h, const char *tablename, void *data)
...
@@ -92,7 +87,7 @@ __do_output(struct nft_handle *h, const char *tablename, void *data)
printf
(
"*%s
\n
"
,
tablename
);
printf
(
"*%s
\n
"
,
tablename
);
/* Dump out chain names first,
/* Dump out chain names first,
* thereby preventing dependency conflicts */
* thereby preventing dependency conflicts */
nft
nl
_chain_
list_
foreach
(
chain_list
,
nft_chain_save
,
h
);
nft_chain_foreach
(
h
,
tablename
,
nft_chain_save
,
h
);
nft_rule_save
(
h
,
tablename
,
d
->
format
);
nft_rule_save
(
h
,
tablename
,
d
->
format
);
if
(
d
->
commit
)
if
(
d
->
commit
)
printf
(
"COMMIT
\n
"
);
printf
(
"COMMIT
\n
"
);
...
@@ -241,6 +236,7 @@ xtables_save_main(int family, int argc, char *argv[],
...
@@ -241,6 +236,7 @@ xtables_save_main(int family, int argc, char *argv[],
nft_cache_level_set
(
&
h
,
NFT_CL_RULES
,
NULL
);
nft_cache_level_set
(
&
h
,
NFT_CL_RULES
,
NULL
);
nft_cache_build
(
&
h
);
nft_cache_build
(
&
h
);
nft_xt_fake_builtin_chains
(
&
h
,
tablename
,
NULL
);
ret
=
do_output
(
&
h
,
tablename
,
&
d
);
ret
=
do_output
(
&
h
,
tablename
,
&
d
);
nft_fini
(
&
h
);
nft_fini
(
&
h
);
...
...
iptables/xtables.c
View file @
6343d369
...
@@ -43,11 +43,6 @@
...
@@ -43,11 +43,6 @@
#include "nft-shared.h"
#include "nft-shared.h"
#include "nft.h"
#include "nft.h"
#define OPT_FRAGMENT 0x00800U
#define NUMBER_OF_OPT ARRAY_SIZE(optflags)
static
const
char
optflags
[]
=
{
'n'
,
's'
,
'd'
,
'p'
,
'j'
,
'v'
,
'x'
,
'i'
,
'o'
,
'0'
,
'c'
,
'f'
};
static
struct
option
original_opts
[]
=
{
static
struct
option
original_opts
[]
=
{
{.
name
=
"append"
,
.
has_arg
=
1
,
.
val
=
'A'
},
{.
name
=
"append"
,
.
has_arg
=
1
,
.
val
=
'A'
},
{.
name
=
"delete"
,
.
has_arg
=
1
,
.
val
=
'D'
},
{.
name
=
"delete"
,
.
has_arg
=
1
,
.
val
=
'D'
},
...
@@ -99,36 +94,6 @@ struct xtables_globals xtables_globals = {
...
@@ -99,36 +94,6 @@ struct xtables_globals xtables_globals = {
.
compat_rev
=
nft_compatible_revision
,
.
compat_rev
=
nft_compatible_revision
,
};
};
/* Table of legal combinations of commands and options. If any of the
* given commands make an option legal, that option is legal (applies to
* CMD_LIST and CMD_ZERO only).
* Key:
* + compulsory
* x illegal
* optional
*/
static
const
char
commands_v_options
[
NUMBER_OF_CMD
][
NUMBER_OF_OPT
]
=
/* Well, it's better than "Re: Linux vs FreeBSD" */
{
/* -n -s -d -p -j -v -x -i -o --line -c -f */
/*INSERT*/
{
'x'
,
' '
,
' '
,
' '
,
' '
,
' '
,
'x'
,
' '
,
' '
,
'x'
,
' '
,
' '
},
/*DELETE*/
{
'x'
,
' '
,
' '
,
' '
,
' '
,
' '
,
'x'
,
' '
,
' '
,
'x'
,
'x'
,
' '
},
/*DELETE_NUM*/
{
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
' '
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
},
/*REPLACE*/
{
'x'
,
' '
,
' '
,
' '
,
' '
,
' '
,
'x'
,
' '
,
' '
,
'x'
,
' '
,
' '
},
/*APPEND*/
{
'x'
,
' '
,
' '
,
' '
,
' '
,
' '
,
'x'
,
' '
,
' '
,
'x'
,
' '
,
' '
},
/*LIST*/
{
' '
,
'x'
,
'x'
,
'x'
,
'x'
,
' '
,
' '
,
'x'
,
'x'
,
' '
,
'x'
,
'x'
},
/*FLUSH*/
{
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
' '
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
},
/*ZERO*/
{
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
' '
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
},
/*ZERO_NUM*/
{
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
' '
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
},
/*NEW_CHAIN*/
{
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
' '
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
},
/*DEL_CHAIN*/
{
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
' '
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
},
/*SET_POLICY*/
{
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
' '
,
'x'
,
'x'
,
'x'
,
'x'
,
' '
,
'x'
},
/*RENAME*/
{
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
' '
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
},
/*LIST_RULES*/
{
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
' '
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
,
'x'
},
/*CHECK*/
{
'x'
,
' '
,
' '
,
' '
,
' '
,
' '
,
'x'
,
' '
,
' '
,
'x'
,
'x'
,
' '
},
};
static
const
int
inverse_for_options
[
NUMBER_OF_OPT
]
=
static
const
int
inverse_for_options
[
NUMBER_OF_OPT
]
=
{
{
/* -n */
0
,
/* -n */
0
,
...
@@ -262,51 +227,6 @@ xtables_exit_error(enum xtables_exittype status, const char *msg, ...)
...
@@ -262,51 +227,6 @@ xtables_exit_error(enum xtables_exittype status, const char *msg, ...)
exit
(
status
);
exit
(
status
);
}
}
static
void
generic_opt_check
(
int
command
,
int
options
)
{
int
i
,
j
,
legal
=
0
;
/* Check that commands are valid with options. Complicated by the
* fact that if an option is legal with *any* command given, it is
* legal overall (ie. -z and -l).
*/
for
(
i
=
0
;
i
<
NUMBER_OF_OPT
;
i
++
)
{
legal
=
0
;
/* -1 => illegal, 1 => legal, 0 => undecided. */
for
(
j
=
0
;
j
<
NUMBER_OF_CMD
;
j
++
)
{
if
(
!
(
command
&
(
1
<<
j
)))
continue
;
if
(
!
(
options
&
(
1
<<
i
)))
{
if
(
commands_v_options
[
j
][
i
]
==
'+'
)
xtables_error
(
PARAMETER_PROBLEM
,
"You need to supply the `-%c' "
"option for this command
\n
"
,
optflags
[
i
]);
}
else
{
if
(
commands_v_options
[
j
][
i
]
!=
'x'
)
legal
=
1
;
else
if
(
legal
==
0
)
legal
=
-
1
;
}
}
if
(
legal
==
-
1
)
xtables_error
(
PARAMETER_PROBLEM
,
"Illegal option `-%c' with this command
\n
"
,
optflags
[
i
]);
}
}
static
char
opt2char
(
int
option
)
{
const
char
*
ptr
;
for
(
ptr
=
optflags
;
option
>
1
;
option
>>=
1
,
ptr
++
);
return
*
ptr
;
}
/*
/*
* All functions starting with "parse" should succeed, otherwise
* All functions starting with "parse" should succeed, otherwise
* the program fails.
* the program fails.
...
...
libxtables/xtables.c
View file @
6343d369
...
@@ -2137,6 +2137,79 @@ void xtables_print_num(uint64_t number, unsigned int format)
...
@@ -2137,6 +2137,79 @@ void xtables_print_num(uint64_t number, unsigned int format)
printf
(
FMT
(
"%4lluT "
,
"%lluT "
),
(
unsigned
long
long
)
number
);
printf
(
FMT
(
"%4lluT "
,
"%lluT "
),
(
unsigned
long
long
)
number
);
}
}
#include <netinet/ether.h>
static
const
unsigned
char
mac_type_unicast
[
ETH_ALEN
]
=
{};
static
const
unsigned
char
msk_type_unicast
[
ETH_ALEN
]
=
{
1
};
static
const
unsigned
char
mac_type_multicast
[
ETH_ALEN
]
=
{
1
};
static
const
unsigned
char
msk_type_multicast
[
ETH_ALEN
]
=
{
1
};
#define ALL_ONE_MAC {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
static
const
unsigned
char
mac_type_broadcast
[
ETH_ALEN
]
=
ALL_ONE_MAC
;
static
const
unsigned
char
msk_type_broadcast
[
ETH_ALEN
]
=
ALL_ONE_MAC
;
static
const
unsigned
char
mac_type_bridge_group
[
ETH_ALEN
]
=
{
0x01
,
0x80
,
0xc2
};
static
const
unsigned
char
msk_type_bridge_group
[
ETH_ALEN
]
=
ALL_ONE_MAC
;
#undef ALL_ONE_MAC
int
xtables_parse_mac_and_mask
(
const
char
*
from
,
void
*
to
,
void
*
mask
)
{
char
*
p
;
int
i
;
struct
ether_addr
*
addr
=
NULL
;
if
(
strcasecmp
(
from
,
"Unicast"
)
==
0
)
{
memcpy
(
to
,
mac_type_unicast
,
ETH_ALEN
);
memcpy
(
mask
,
msk_type_unicast
,
ETH_ALEN
);
return
0
;
}
if
(
strcasecmp
(
from
,
"Multicast"
)
==
0
)
{
memcpy
(
to
,
mac_type_multicast
,
ETH_ALEN
);
memcpy
(
mask
,
msk_type_multicast
,
ETH_ALEN
);
return
0
;
}
if
(
strcasecmp
(
from
,
"Broadcast"
)
==
0
)
{
memcpy
(
to
,
mac_type_broadcast
,
ETH_ALEN
);
memcpy
(
mask
,
msk_type_broadcast
,
ETH_ALEN
);
return
0
;
}
if
(
strcasecmp
(
from
,
"BGA"
)
==
0
)
{
memcpy
(
to
,
mac_type_bridge_group
,
ETH_ALEN
);
memcpy
(
mask
,
msk_type_bridge_group
,
ETH_ALEN
);
return
0
;
}
if
(
(
p
=
strrchr
(
from
,
'/'
))
!=
NULL
)
{
*
p
=
'\0'
;
if
(
!
(
addr
=
ether_aton
(
p
+
1
)))
return
-
1
;
memcpy
(
mask
,
addr
,
ETH_ALEN
);
}
else
memset
(
mask
,
0xff
,
ETH_ALEN
);
if
(
!
(
addr
=
ether_aton
(
from
)))
return
-
1
;
memcpy
(
to
,
addr
,
ETH_ALEN
);
for
(
i
=
0
;
i
<
ETH_ALEN
;
i
++
)
((
char
*
)
to
)[
i
]
&=
((
char
*
)
mask
)[
i
];
return
0
;
}
int
xtables_print_well_known_mac_and_mask
(
const
void
*
mac
,
const
void
*
mask
)
{
if
(
!
memcmp
(
mac
,
mac_type_unicast
,
ETH_ALEN
)
&&
!
memcmp
(
mask
,
msk_type_unicast
,
ETH_ALEN
))
printf
(
"Unicast"
);
else
if
(
!
memcmp
(
mac
,
mac_type_multicast
,
ETH_ALEN
)
&&
!
memcmp
(
mask
,
msk_type_multicast
,
ETH_ALEN
))
printf
(
"Multicast"
);
else
if
(
!
memcmp
(
mac
,
mac_type_broadcast
,
ETH_ALEN
)
&&
!
memcmp
(
mask
,
msk_type_broadcast
,
ETH_ALEN
))
printf
(
"Broadcast"
);
else
if
(
!
memcmp
(
mac
,
mac_type_bridge_group
,
ETH_ALEN
)
&&
!
memcmp
(
mask
,
msk_type_bridge_group
,
ETH_ALEN
))
printf
(
"BGA"
);
else
return
-
1
;
return
0
;
}
void
xtables_print_mac
(
const
unsigned
char
*
macaddress
)
void
xtables_print_mac
(
const
unsigned
char
*
macaddress
)
{
{
unsigned
int
i
;
unsigned
int
i
;
...
...
Prev
1
2
3
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