Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
iproute2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
iproute2
Commits
56f5daac
Commit
56f5daac
authored
Mar 21, 2016
by
Stephen Hemminger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ip: code cleanup
Run all the ip code through checkpatch and have it fix the obvious stuff.
parent
32a121cb
Changes
43
Hide whitespace changes
Inline
Side-by-side
Showing
43 changed files
with
609 additions
and
422 deletions
+609
-422
ip/ip6tunnel.c
ip/ip6tunnel.c
+16
-6
ip/ipaddress.c
ip/ipaddress.c
+67
-49
ip/ipaddrlabel.c
ip/ipaddrlabel.c
+6
-5
ip/ipl2tp.c
ip/ipl2tp.c
+10
-0
ip/iplink.c
ip/iplink.c
+8
-12
ip/iplink_bond.c
ip/iplink_bond.c
+5
-4
ip/iplink_bond_slave.c
ip/iplink_bond_slave.c
+2
-2
ip/iplink_bridge_slave.c
ip/iplink_bridge_slave.c
+1
-1
ip/iplink_can.c
ip/iplink_can.c
+12
-21
ip/iplink_geneve.c
ip/iplink_geneve.c
+4
-1
ip/iplink_ipoib.c
ip/iplink_ipoib.c
+2
-4
ip/iplink_ipvlan.c
ip/iplink_ipvlan.c
+2
-2
ip/iplink_macvlan.c
ip/iplink_macvlan.c
+3
-3
ip/iplink_vlan.c
ip/iplink_vlan.c
+3
-3
ip/iplink_vrf.c
ip/iplink_vrf.c
+4
-4
ip/iplink_vxlan.c
ip/iplink_vxlan.c
+11
-4
ip/ipmaddr.c
ip/ipmaddr.c
+10
-10
ip/ipmonitor.c
ip/ipmonitor.c
+21
-22
ip/ipmroute.c
ip/ipmroute.c
+6
-5
ip/ipneigh.c
ip/ipneigh.c
+23
-15
ip/ipnetconf.c
ip/ipnetconf.c
+2
-2
ip/ipnetns.c
ip/ipnetns.c
+8
-3
ip/ipntable.c
ip/ipntable.c
+22
-3
ip/ipprefix.c
ip/ipprefix.c
+3
-2
ip/iproute.c
ip/iproute.c
+105
-50
ip/iproute_lwtunnel.c
ip/iproute_lwtunnel.c
+9
-1
ip/iprule.c
ip/iprule.c
+19
-5
ip/iptoken.c
ip/iptoken.c
+2
-4
ip/iptuntap.c
ip/iptuntap.c
+9
-7
ip/ipxfrm.c
ip/ipxfrm.c
+23
-9
ip/link_gre.c
ip/link_gre.c
+16
-16
ip/link_gre6.c
ip/link_gre6.c
+22
-15
ip/link_ip6tnl.c
ip/link_ip6tnl.c
+8
-2
ip/link_iptnl.c
ip/link_iptnl.c
+7
-3
ip/link_veth.c
ip/link_veth.c
+1
-1
ip/link_vti.c
ip/link_vti.c
+11
-11
ip/link_vti6.c
ip/link_vti6.c
+9
-7
ip/rtmon.c
ip/rtmon.c
+13
-12
ip/tcp_metrics.c
ip/tcp_metrics.c
+5
-2
ip/tunnel.c
ip/tunnel.c
+6
-6
ip/xfrm_monitor.c
ip/xfrm_monitor.c
+28
-26
ip/xfrm_policy.c
ip/xfrm_policy.c
+36
-34
ip/xfrm_state.c
ip/xfrm_state.c
+29
-28
No files found.
ip/ip6tunnel.c
View file @
56f5daac
...
...
@@ -50,7 +50,7 @@ static void usage(void)
fprintf
(
stderr
,
" [ mode { ip6ip6 | ipip6 | ip6gre | vti6 | any } ]
\n
"
);
fprintf
(
stderr
,
" [ remote ADDR local ADDR ] [ dev PHYS_DEV ]
\n
"
);
fprintf
(
stderr
,
" [ encaplimit ELIM ]
\n
"
);
fprintf
(
stderr
,
" [ hoplimit TTL ] [ tclass TCLASS ] [ flowlabel FLOWLABEL ]
\n
"
);
fprintf
(
stderr
,
" [ hoplimit TTL ] [ tclass TCLASS ] [ flowlabel FLOWLABEL ]
\n
"
);
fprintf
(
stderr
,
" [ dscp inherit ]
\n
"
);
fprintf
(
stderr
,
" [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]
\n
"
);
fprintf
(
stderr
,
"
\n
"
);
...
...
@@ -81,6 +81,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p)
rt_addr_n2a
(
AF_INET6
,
16
,
&
p
->
laddr
,
s2
,
sizeof
(
s2
)));
if
(
p
->
link
)
{
const
char
*
n
=
ll_index_to_name
(
p
->
link
);
if
(
n
)
printf
(
" dev %s"
,
n
);
}
...
...
@@ -96,6 +97,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p)
printf
(
" tclass inherit"
);
else
{
__u32
val
=
ntohl
(
p
->
flowinfo
&
IP6_FLOWINFO_TCLASS
);
printf
(
" tclass 0x%02x"
,
(
__u8
)(
val
>>
20
));
}
...
...
@@ -158,11 +160,12 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
strcmp
(
*
argv
,
"any"
)
==
0
)
p
->
proto
=
0
;
else
{
fprintf
(
stderr
,
"Unknown tunnel mode
\"
%s
\"\n
"
,
*
argv
);
fprintf
(
stderr
,
"Unknown tunnel mode
\"
%s
\"\n
"
,
*
argv
);
exit
(
-
1
);
}
}
else
if
(
strcmp
(
*
argv
,
"remote"
)
==
0
)
{
inet_prefix
raddr
;
NEXT_ARG
();
get_prefix
(
&
raddr
,
*
argv
,
preferred_family
);
if
(
raddr
.
family
==
AF_UNSPEC
)
...
...
@@ -170,6 +173,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
memcpy
(
&
p
->
raddr
,
&
raddr
.
data
,
sizeof
(
p
->
raddr
));
}
else
if
(
strcmp
(
*
argv
,
"local"
)
==
0
)
{
inet_prefix
laddr
;
NEXT_ARG
();
get_prefix
(
&
laddr
,
*
argv
,
preferred_family
);
if
(
laddr
.
family
==
AF_UNSPEC
)
...
...
@@ -184,6 +188,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
p
->
flags
|=
IP6_TNL_F_IGN_ENCAP_LIMIT
;
}
else
{
__u8
uval
;
if
(
get_u8
(
&
uval
,
*
argv
,
0
)
<
-
1
)
invarg
(
"invalid ELIM"
,
*
argv
);
p
->
encap_limit
=
uval
;
...
...
@@ -193,6 +198,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
strcmp
(
*
argv
,
"ttl"
)
==
0
||
strcmp
(
*
argv
,
"hlim"
)
==
0
)
{
__u8
uval
;
NEXT_ARG
();
if
(
get_u8
(
&
uval
,
*
argv
,
0
))
invarg
(
"invalid TTL"
,
*
argv
);
...
...
@@ -202,6 +208,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
strcmp
(
*
argv
,
"tos"
)
==
0
||
matches
(
*
argv
,
"dsfield"
)
==
0
)
{
__u8
uval
;
NEXT_ARG
();
p
->
flowinfo
&=
~
IP6_FLOWINFO_TCLASS
;
if
(
strcmp
(
*
argv
,
"inherit"
)
==
0
)
...
...
@@ -215,6 +222,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
}
else
if
(
strcmp
(
*
argv
,
"flowlabel"
)
==
0
||
strcmp
(
*
argv
,
"fl"
)
==
0
)
{
__u32
uval
;
NEXT_ARG
();
p
->
flowinfo
&=
~
IP6_FLOWINFO_FLOWLABEL
;
if
(
strcmp
(
*
argv
,
"inherit"
)
==
0
)
...
...
@@ -269,6 +277,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
strncpy
(
p
->
name
,
*
argv
,
IFNAMSIZ
-
1
);
if
(
cmd
==
SIOCCHGTUNNEL
&&
count
==
0
)
{
struct
ip6_tnl_parm2
old_p
;
memset
(
&
old_p
,
0
,
sizeof
(
old_p
));
if
(
tnl_get_ioctl
(
*
argv
,
&
old_p
))
return
-
1
;
...
...
@@ -326,6 +335,7 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
char
buf
[
512
];
int
err
=
-
1
;
FILE
*
fp
=
fopen
(
"/proc/net/dev"
,
"r"
);
if
(
fp
==
NULL
)
{
perror
(
"fopen"
);
return
-
1
;
...
...
@@ -387,14 +397,14 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
static
int
do_show
(
int
argc
,
char
**
argv
)
{
struct
ip6_tnl_parm2
p
;
struct
ip6_tnl_parm2
p
;
ll_init_map
(
&
rth
);
ip6_tnl_parm_init
(
&
p
,
0
);
p
.
proto
=
0
;
/* default to any */
if
(
parse_args
(
argc
,
argv
,
SIOCGETTUNNEL
,
&
p
)
<
0
)
return
-
1
;
if
(
parse_args
(
argc
,
argv
,
SIOCGETTUNNEL
,
&
p
)
<
0
)
return
-
1
;
if
(
!
p
.
name
[
0
]
||
show_stats
)
do_tunnels_list
(
&
p
);
...
...
@@ -405,7 +415,7 @@ static int do_show(int argc, char **argv)
printf
(
"
\n
"
);
}
return
0
;
return
0
;
}
static
int
do_add
(
int
cmd
,
int
argc
,
char
**
argv
)
...
...
ip/ipaddress.c
View file @
56f5daac
...
...
@@ -93,7 +93,7 @@ static void usage(void)
exit
(
-
1
);
}
static
void
print_link_flags
(
FILE
*
fp
,
unsigned
flags
,
unsigned
mdown
)
static
void
print_link_flags
(
FILE
*
fp
,
unsigned
int
flags
,
unsigned
int
mdown
)
{
fprintf
(
fp
,
"<"
);
if
(
flags
&
IFF_UP
&&
!
(
flags
&
IFF_RUNNING
))
...
...
@@ -135,7 +135,7 @@ static const char *oper_states[] = {
static
void
print_operstate
(
FILE
*
f
,
__u8
state
)
{
if
(
state
>=
sizeof
(
oper_states
)
/
sizeof
(
oper_states
[
0
]
))
if
(
state
>=
ARRAY_SIZE
(
oper_states
))
fprintf
(
f
,
"state %#x "
,
state
);
else
{
if
(
brief
)
{
...
...
@@ -161,7 +161,7 @@ int get_operstate(const char *name)
{
int
i
;
for
(
i
=
0
;
i
<
sizeof
(
oper_states
)
/
sizeof
(
oper_states
[
0
]
);
i
++
)
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
oper_states
);
i
++
)
if
(
strcasecmp
(
name
,
oper_states
[
i
])
==
0
)
return
i
;
return
-
1
;
...
...
@@ -202,7 +202,7 @@ static void print_linkmode(FILE *f, struct rtattr *tb)
{
unsigned
int
mode
=
rta_getattr_u8
(
tb
);
if
(
mode
>=
sizeof
(
link_modes
)
/
sizeof
(
link_modes
[
0
]
))
if
(
mode
>=
ARRAY_SIZE
(
link_modes
))
fprintf
(
f
,
"mode %d "
,
mode
);
else
fprintf
(
f
,
"mode %s "
,
link_modes
[
mode
]);
...
...
@@ -286,6 +286,7 @@ static void print_af_spec(FILE *fp, struct rtattr *af_spec_attr)
if
(
tb
[
IFLA_INET6_ADDR_GEN_MODE
])
{
__u8
mode
=
rta_getattr_u8
(
tb
[
IFLA_INET6_ADDR_GEN_MODE
]);
switch
(
mode
)
{
case
IN6_ADDR_GEN_MODE_EUI64
:
fprintf
(
fp
,
"addrgenmode eui64 "
);
...
...
@@ -317,6 +318,7 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
struct
ifla_vf_link_state
*
vf_linkstate
;
struct
rtattr
*
vf
[
IFLA_VF_MAX
+
1
]
=
{};
struct
rtattr
*
tmp
;
SPRINT_BUF
(
b1
);
if
(
vfinfo
->
rta_type
!=
IFLA_VF_INFO
)
{
...
...
@@ -392,7 +394,7 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
print_vf_stats64
(
fp
,
vf
[
IFLA_VF_STATS
]);
}
static
void
print_num
(
FILE
*
fp
,
unsigned
width
,
uint64_t
count
)
static
void
print_num
(
FILE
*
fp
,
unsigned
int
width
,
uint64_t
count
)
{
const
char
*
prefix
=
"kMGTPE"
;
const
unsigned
int
base
=
use_iec
?
1024
:
1000
;
...
...
@@ -408,7 +410,7 @@ static void print_num(FILE *fp, unsigned width, uint64_t count)
/* increase value by a factor of 1000/1024 and print
* if result is something a human can read */
for
(;;)
{
for
(;;)
{
powi
*=
base
;
if
(
count
/
base
<
powi
)
break
;
...
...
@@ -462,7 +464,7 @@ static void print_vf_stats64(FILE *fp, struct rtattr *vfstats)
}
static
void
print_link_stats64
(
FILE
*
fp
,
const
struct
rtnl_link_stats64
*
s
,
const
struct
rtattr
*
carrier_changes
)
const
struct
rtattr
*
carrier_changes
)
{
/* RX stats */
fprintf
(
fp
,
" RX: bytes packets errors dropped overrun mcast %s%s"
,
...
...
@@ -514,7 +516,7 @@ static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s,
if
(
show_stats
>
1
)
{
fprintf
(
fp
,
"%s"
,
_SL_
);
fprintf
(
fp
,
" TX errors: aborted fifo window heartbeat"
);
if
(
carrier_changes
)
if
(
carrier_changes
)
fprintf
(
fp
,
" transns"
);
fprintf
(
fp
,
"%s"
,
_SL_
);
...
...
@@ -524,7 +526,7 @@ static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s,
print_num
(
fp
,
7
,
s
->
tx_window_errors
);
print_num
(
fp
,
7
,
s
->
tx_heartbeat_errors
);
if
(
carrier_changes
)
print_num
(
fp
,
7
,
*
(
uint32_t
*
)
RTA_DATA
(
carrier_changes
));
print_num
(
fp
,
7
,
*
(
uint32_t
*
)
RTA_DATA
(
carrier_changes
));
}
}
...
...
@@ -580,7 +582,7 @@ static void print_link_stats32(FILE *fp, const struct rtnl_link_stats *s,
if
(
show_stats
>
1
)
{
fprintf
(
fp
,
"%s"
,
_SL_
);
fprintf
(
fp
,
" TX errors: aborted fifo window heartbeat"
);
if
(
carrier_changes
)
if
(
carrier_changes
)
fprintf
(
fp
,
" transns"
);
fprintf
(
fp
,
"%s"
,
_SL_
);
...
...
@@ -590,7 +592,7 @@ static void print_link_stats32(FILE *fp, const struct rtnl_link_stats *s,
print_num
(
fp
,
7
,
s
->
tx_window_errors
);
print_num
(
fp
,
7
,
s
->
tx_heartbeat_errors
);
if
(
carrier_changes
)
print_num
(
fp
,
7
,
*
(
uint32_t
*
)
RTA_DATA
(
carrier_changes
));
print_num
(
fp
,
7
,
*
(
uint32_t
*
)
RTA_DATA
(
carrier_changes
));
}
}
...
...
@@ -618,7 +620,7 @@ static void __print_link_stats(FILE *fp, struct rtattr **tb)
static
void
print_link_stats
(
FILE
*
fp
,
struct
nlmsghdr
*
n
)
{
struct
ifinfomsg
*
ifi
=
NLMSG_DATA
(
n
);
struct
rtattr
*
tb
[
IFLA_MAX
+
1
];
struct
rtattr
*
tb
[
IFLA_MAX
+
1
];
parse_rtattr
(
tb
,
IFLA_MAX
,
IFLA_RTA
(
ifi
),
n
->
nlmsg_len
-
NLMSG_LENGTH
(
sizeof
(
*
ifi
)));
...
...
@@ -629,13 +631,13 @@ static void print_link_stats(FILE *fp, struct nlmsghdr *n)
int
print_linkinfo_brief
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
ifinfomsg
*
ifi
=
NLMSG_DATA
(
n
);
struct
rtattr
*
tb
[
IFLA_MAX
+
1
];
struct
rtattr
*
tb
[
IFLA_MAX
+
1
];
int
len
=
n
->
nlmsg_len
;
char
*
name
;
char
buf
[
32
]
=
{
0
,
};
unsigned
m_flag
=
0
;
unsigned
int
m_flag
=
0
;
if
(
n
->
nlmsg_type
!=
RTM_NEWLINK
&&
n
->
nlmsg_type
!=
RTM_DELLINK
)
return
-
1
;
...
...
@@ -659,17 +661,18 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
return
-
1
;
if
(
tb
[
IFLA_GROUP
])
{
int
group
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_GROUP
]);
int
group
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_GROUP
]);
if
(
filter
.
group
!=
-
1
&&
group
!=
filter
.
group
)
return
-
1
;
}
if
(
tb
[
IFLA_MASTER
])
{
int
master
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_MASTER
]);
int
master
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_MASTER
]);
if
(
filter
.
master
>
0
&&
master
!=
filter
.
master
)
return
-
1
;
}
else
if
(
filter
.
master
>
0
)
}
else
if
(
filter
.
master
>
0
)
return
-
1
;
if
(
filter
.
kind
)
{
...
...
@@ -690,7 +693,8 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
if
(
tb
[
IFLA_LINK
])
{
SPRINT_BUF
(
b1
);
int
iflink
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_LINK
]);
int
iflink
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_LINK
]);
if
(
iflink
==
0
)
snprintf
(
buf
,
sizeof
(
buf
),
"%s@NONE"
,
name
);
else
{
...
...
@@ -730,11 +734,11 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
int
print_linkinfo
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
ifinfomsg
*
ifi
=
NLMSG_DATA
(
n
);
struct
rtattr
*
tb
[
IFLA_MAX
+
1
];
struct
rtattr
*
tb
[
IFLA_MAX
+
1
];
int
len
=
n
->
nlmsg_len
;
unsigned
m_flag
=
0
;
unsigned
int
m_flag
=
0
;
if
(
n
->
nlmsg_type
!=
RTM_NEWLINK
&&
n
->
nlmsg_type
!=
RTM_DELLINK
)
return
0
;
...
...
@@ -758,17 +762,18 @@ int print_linkinfo(const struct sockaddr_nl *who,
return
0
;
if
(
tb
[
IFLA_GROUP
])
{
int
group
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_GROUP
]);
int
group
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_GROUP
]);
if
(
filter
.
group
!=
-
1
&&
group
!=
filter
.
group
)
return
-
1
;
}
if
(
tb
[
IFLA_MASTER
])
{
int
master
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_MASTER
]);
int
master
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_MASTER
]);
if
(
filter
.
master
>
0
&&
master
!=
filter
.
master
)
return
-
1
;
}
else
if
(
filter
.
master
>
0
)
}
else
if
(
filter
.
master
>
0
)
return
-
1
;
if
(
filter
.
kind
)
{
...
...
@@ -791,7 +796,8 @@ int print_linkinfo(const struct sockaddr_nl *who,
if
(
tb
[
IFLA_LINK
])
{
SPRINT_BUF
(
b1
);
int
iflink
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_LINK
]);
int
iflink
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_LINK
]);
if
(
iflink
==
0
)
fprintf
(
fp
,
"@NONE: "
);
else
{
...
...
@@ -809,12 +815,12 @@ int print_linkinfo(const struct sockaddr_nl *who,
print_link_flags
(
fp
,
ifi
->
ifi_flags
,
m_flag
);
if
(
tb
[
IFLA_MTU
])
fprintf
(
fp
,
"mtu %u "
,
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_MTU
]));
fprintf
(
fp
,
"mtu %u "
,
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_MTU
]));
if
(
tb
[
IFLA_QDISC
])
fprintf
(
fp
,
"qdisc %s "
,
rta_getattr_str
(
tb
[
IFLA_QDISC
]));
if
(
tb
[
IFLA_MASTER
])
{
SPRINT_BUF
(
b1
);
fprintf
(
fp
,
"master %s "
,
ll_idx_n2a
(
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_MASTER
]),
b1
));
fprintf
(
fp
,
"master %s "
,
ll_idx_n2a
(
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_MASTER
]),
b1
));
}
if
(
tb
[
IFLA_PHYS_PORT_ID
])
{
...
...
@@ -841,7 +847,8 @@ int print_linkinfo(const struct sockaddr_nl *who,
if
(
tb
[
IFLA_GROUP
])
{
SPRINT_BUF
(
b1
);
int
group
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_GROUP
]);
int
group
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_GROUP
]);
fprintf
(
fp
,
"group %s "
,
rtnl_group_n2a
(
group
,
b1
,
sizeof
(
b1
)));
}
...
...
@@ -873,7 +880,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
}
if
(
tb
[
IFLA_LINK_NETNSID
])
{
int
id
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_LINK_NETNSID
]);
int
id
=
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_LINK_NETNSID
]);
if
(
id
>=
0
)
fprintf
(
fp
,
" link-netnsid %d"
,
id
);
...
...
@@ -888,7 +895,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
if
(
tb
[
IFLA_PROMISCUITY
]
&&
show_details
)
fprintf
(
fp
,
" promiscuity %u "
,
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_PROMISCUITY
]));
*
(
int
*
)
RTA_DATA
(
tb
[
IFLA_PROMISCUITY
]));
if
(
tb
[
IFLA_LINKINFO
]
&&
show_details
)
print_linktype
(
fp
,
tb
[
IFLA_LINKINFO
]);
...
...
@@ -909,6 +916,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
if
((
do_link
||
show_details
)
&&
tb
[
IFLA_VFINFO_LIST
]
&&
tb
[
IFLA_NUM_VF
])
{
struct
rtattr
*
i
,
*
vflist
=
tb
[
IFLA_VFINFO_LIST
];
int
rem
=
RTA_PAYLOAD
(
vflist
);
for
(
i
=
RTA_DATA
(
vflist
);
RTA_OK
(
i
,
rem
);
i
=
RTA_NEXT
(
i
,
rem
))
print_vfinfo
(
fp
,
i
);
}
...
...
@@ -964,8 +972,9 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
int
deprecated
=
0
;
/* Use local copy of ifa_flags to not interfere with filtering code */
unsigned
int
ifa_flags
;
struct
rtattr
*
rta_tb
[
IFA_MAX
+
1
];
struct
rtattr
*
rta_tb
[
IFA_MAX
+
1
];
char
abuf
[
256
];
SPRINT_BUF
(
b1
);
if
(
n
->
nlmsg_type
!=
RTM_NEWADDR
&&
n
->
nlmsg_type
!=
RTM_DELADDR
)
...
...
@@ -998,6 +1007,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
if
(
filter
.
label
)
{
SPRINT_BUF
(
b1
);
const
char
*
label
;
if
(
rta_tb
[
IFA_LABEL
])
label
=
RTA_DATA
(
rta_tb
[
IFA_LABEL
]);
else
...
...
@@ -1008,6 +1018,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
if
(
filter
.
pfx
.
family
)
{
if
(
rta_tb
[
IFA_LOCAL
])
{
inet_prefix
dst
;
memset
(
&
dst
,
0
,
sizeof
(
dst
));
dst
.
family
=
ifa
->
ifa_family
;
memcpy
(
&
dst
.
data
,
RTA_DATA
(
rta_tb
[
IFA_LOCAL
]),
RTA_PAYLOAD
(
rta_tb
[
IFA_LOCAL
]));
...
...
@@ -1021,16 +1032,17 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
if
(
filter
.
flushb
)
{
struct
nlmsghdr
*
fn
;
if
(
NLMSG_ALIGN
(
filter
.
flushp
)
+
n
->
nlmsg_len
>
filter
.
flushe
)
{
if
(
flush_update
())
return
-
1
;
}
fn
=
(
struct
nlmsghdr
*
)(
filter
.
flushb
+
NLMSG_ALIGN
(
filter
.
flushp
));
fn
=
(
struct
nlmsghdr
*
)(
filter
.
flushb
+
NLMSG_ALIGN
(
filter
.
flushp
));
memcpy
(
fn
,
n
,
n
->
nlmsg_len
);
fn
->
nlmsg_type
=
RTM_DELADDR
;
fn
->
nlmsg_flags
=
NLM_F_REQUEST
;
fn
->
nlmsg_seq
=
++
rth
.
seq
;
filter
.
flushp
=
(((
char
*
)
fn
)
+
n
->
nlmsg_len
)
-
filter
.
flushb
;
filter
.
flushp
=
(((
char
*
)
fn
)
+
n
->
nlmsg_len
)
-
filter
.
flushb
;
filter
.
flushed
++
;
if
(
show_stats
<
2
)
return
0
;
...
...
@@ -1153,6 +1165,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
fprintf
(
fp
,
"%s"
,
rta_getattr_str
(
rta_tb
[
IFA_LABEL
]));
if
(
rta_tb
[
IFA_CACHEINFO
])
{
struct
ifa_cacheinfo
*
ci
=
RTA_DATA
(
rta_tb
[
IFA_CACHEINFO
]);
fprintf
(
fp
,
"%s"
,
_SL_
);
fprintf
(
fp
,
" valid_lft "
);
if
(
ci
->
ifa_valid
==
INFINITY_LIFE_TIME
)
...
...
@@ -1175,14 +1188,12 @@ brief_exit:
return
0
;
}
struct
nlmsg_list
{
struct
nlmsg_list
{
struct
nlmsg_list
*
next
;
struct
nlmsghdr
h
;
};
struct
nlmsg_chain
{
struct
nlmsg_chain
{
struct
nlmsg_list
*
head
;
struct
nlmsg_list
*
tail
;
};
...
...
@@ -1190,7 +1201,7 @@ struct nlmsg_chain
static
int
print_selected_addrinfo
(
struct
ifinfomsg
*
ifi
,
struct
nlmsg_list
*
ainfo
,
FILE
*
fp
)
{
for
(
;
ainfo
;
ainfo
=
ainfo
->
next
)
{
for
(
;
ainfo
;
ainfo
=
ainfo
->
next
)
{
struct
nlmsghdr
*
n
=
&
ainfo
->
h
;
struct
ifaddrmsg
*
ifa
=
NLMSG_DATA
(
n
);
...
...
@@ -1223,7 +1234,7 @@ static int store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n,
struct
nlmsg_chain
*
lchain
=
(
struct
nlmsg_chain
*
)
arg
;
struct
nlmsg_list
*
h
;
h
=
malloc
(
n
->
nlmsg_len
+
sizeof
(
void
*
));
h
=
malloc
(
n
->
nlmsg_len
+
sizeof
(
void
*
));
if
(
h
==
NULL
)
return
-
1
;
...
...
@@ -1352,7 +1363,7 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo)
struct
nlmsg_list
*
l
,
**
lp
;
lp
=
&
linfo
->
head
;
while
(
(
l
=
*
lp
)
!=
NULL
)
{
while
((
l
=
*
lp
)
!=
NULL
)
{
int
ok
=
0
;
int
missing_net_address
=
1
;
struct
ifinfomsg
*
ifi
=
NLMSG_DATA
(
&
l
->
h
);
...
...
@@ -1383,6 +1394,7 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo)
if
(
filter
.
pfx
.
family
&&
tb
[
IFA_LOCAL
])
{
inet_prefix
dst
;
memset
(
&
dst
,
0
,
sizeof
(
dst
));
dst
.
family
=
ifa
->
ifa_family
;
memcpy
(
&
dst
.
data
,
RTA_DATA
(
tb
[
IFA_LOCAL
]),
RTA_PAYLOAD
(
tb
[
IFA_LOCAL
]));
...
...
@@ -1392,6 +1404,7 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo)
if
(
filter
.
label
)
{
SPRINT_BUF
(
b1
);
const
char
*
label
;
if
(
tb
[
IFA_LABEL
])
label
=
RTA_DATA
(
tb
[
IFA_LABEL
]);
else
...
...
@@ -1441,7 +1454,7 @@ static int ipaddr_flush(void)
if
(
round
==
0
)
printf
(
"Nothing to flush.
\n
"
);
else
printf
(
"*** Flush is complete after %d round%s ***
\n
"
,
round
,
round
>
1
?
"s"
:
""
);
printf
(
"*** Flush is complete after %d round%s ***
\n
"
,
round
,
round
>
1
?
"s"
:
""
);
}
fflush
(
stdout
);
return
0
;
...
...
@@ -1500,7 +1513,8 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
if
(
filter
.
family
==
AF_UNSPEC
)
filter
.
family
=
filter
.
pfx
.
family
;
}
else
if
(
strcmp
(
*
argv
,
"scope"
)
==
0
)
{
unsigned
scope
=
0
;
unsigned
int
scope
=
0
;
NEXT_ARG
();
filter
.
scopemask
=
-
1
;
if
(
rtnl_rtscope_a2n
(
&
scope
,
*
argv
))
{
...
...
@@ -1567,6 +1581,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
invarg
(
"Invalid
\"
group
\"
value
\n
"
,
*
argv
);
}
else
if
(
strcmp
(
*
argv
,
"master"
)
==
0
)
{
int
ifindex
;
NEXT_ARG
();
ifindex
=
ll_name_to_index
(
*
argv
);
if
(
!
ifindex
)
...
...
@@ -1578,8 +1593,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
}
else
{
if
(
strcmp
(
*
argv
,
"dev"
)
==
0
)
{
NEXT_ARG
();
}
else
if
(
matches
(
*
argv
,
"help"
)
==
0
)
}
else
if
(
matches
(
*
argv
,
"help"
)
==
0
)
usage
();
if
(
filter_dev
)
duparg2
(
"dev"
,
*
argv
);
...
...
@@ -1757,7 +1771,7 @@ void ipaddr_reset_filter(int oneline, int ifindex)
static
int
default_scope
(
inet_prefix
*
lcl
)
{
if
(
lcl
->
family
==
AF_INET
)
{
if
(
lcl
->
bytelen
>=
1
&&
*
(
__u8
*
)
&
lcl
->
data
==
127
)
if
(
lcl
->
bytelen
>=
1
&&
*
(
__u8
*
)
&
lcl
->
data
==
127
)
return
RT_SCOPE_HOST
;
}
return
0
;
...
...
@@ -1820,6 +1834,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
}
else
if
(
matches
(
*
argv
,
"broadcast"
)
==
0
||
strcmp
(
*
argv
,
"brd"
)
==
0
)
{
inet_prefix
addr
;
NEXT_ARG
();
if
(
brd_len
)
duparg
(
"broadcast"
,
*
argv
);
...
...
@@ -1836,6 +1851,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
}
}
else
if
(
strcmp
(
*
argv
,
"anycast"
)
==
0
)
{
inet_prefix
addr
;
NEXT_ARG
();
if
(
any_len
)
duparg
(
"anycast"
,
*
argv
);
...
...
@@ -1845,7 +1861,8 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
addattr_l
(
&
req
.
n
,
sizeof
(
req
),
IFA_ANYCAST
,
&
addr
.
data
,
addr
.
bytelen
);
any_len
=
addr
.
bytelen
;
}
else
if
(
strcmp
(
*
argv
,
"scope"
)
==
0
)
{
unsigned
scope
=
0
;
unsigned
int
scope
=
0
;
NEXT_ARG
();
if
(
rtnl_rtscope_a2n
(
&
scope
,
*
argv
))
invarg
(
"invalid scope value."
,
*
argv
);
...
...
@@ -1931,6 +1948,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
if
(
brd_len
<
0
&&
cmd
!=
RTM_DELADDR
)
{
inet_prefix
brd
;
int
i
;
if
(
req
.
ifa
.
ifa_family
!=
AF_INET
)
{
fprintf
(
stderr
,
"Broadcast can be set only for IPv4 addresses
\n
"
);
return
-
1
;
...
...
ip/ipaddrlabel.c
View file @
56f5daac
...
...
@@ -40,8 +40,8 @@
#include "utils.h"
#include "ip_common.h"
#define IFAL_RTA(r) ((struct rtattr
*)(((char
*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrlblmsg))))
#define IFAL_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrlblmsg))
#define IFAL_RTA(r) ((struct rtattr
*)(((char
*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrlblmsg))))
#define IFAL_PAYLOAD(n) NLMSG_PAYLOAD(n,
sizeof(struct ifaddrlblmsg))
extern
struct
rtnl_handle
rth
;
...
...
@@ -56,7 +56,7 @@ static void usage(void)
int
print_addrlabel
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
ifaddrlblmsg
*
ifal
=
NLMSG_DATA
(
n
);
int
len
=
n
->
nlmsg_len
;
struct
rtattr
*
tb
[
IFAL_MAX
+
1
];
...
...
@@ -88,6 +88,7 @@ int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg
if
(
tb
[
IFAL_LABEL
]
&&
RTA_PAYLOAD
(
tb
[
IFAL_LABEL
])
==
sizeof
(
uint32_t
))
{
uint32_t
label
;
memcpy
(
&
label
,
RTA_DATA
(
tb
[
IFAL_LABEL
]),
sizeof
(
label
));
fprintf
(
fp
,
"label %u "
,
label
);
}
...
...
@@ -128,7 +129,7 @@ static int ipaddrlabel_modify(int cmd, int argc, char **argv)
struct
{
struct
nlmsghdr
n
;
struct
ifaddrlblmsg
ifal
;
char
buf
[
1024
];
char
buf
[
1024
];
}
req
;
inet_prefix
prefix
;
...
...
@@ -195,7 +196,7 @@ static int flush_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, vo
struct
rtnl_handle
rth2
;
struct
rtmsg
*
r
=
NLMSG_DATA
(
n
);
int
len
=
n
->
nlmsg_len
;
struct
rtattr
*
tb
[
IFAL_MAX
+
1
];
struct
rtattr
*
tb
[
IFAL_MAX
+
1
];
len
-=
NLMSG_LENGTH
(
sizeof
(
*
r
));
if
(
len
<
0
)
...
...
ip/ipl2tp.c
View file @
56f5daac
...
...
@@ -526,6 +526,7 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p)
}
else
if
((
strcmp
(
*
argv
,
"tunnel_id"
)
==
0
)
||
(
strcmp
(
*
argv
,
"tid"
)
==
0
))
{
__u32
uval
;
NEXT_ARG
();
if
(
get_u32
(
&
uval
,
*
argv
,
0
))
invarg
(
"invalid ID
\n
"
,
*
argv
);
...
...
@@ -533,6 +534,7 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p)
}
else
if
((
strcmp
(
*
argv
,
"peer_tunnel_id"
)
==
0
)
||
(
strcmp
(
*
argv
,
"ptid"
)
==
0
))
{
__u32
uval
;
NEXT_ARG
();
if
(
get_u32
(
&
uval
,
*
argv
,
0
))
invarg
(
"invalid ID
\n
"
,
*
argv
);
...
...
@@ -540,6 +542,7 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p)
}
else
if
((
strcmp
(
*
argv
,
"session_id"
)
==
0
)
||
(
strcmp
(
*
argv
,
"sid"
)
==
0
))
{
__u32
uval
;
NEXT_ARG
();
if
(
get_u32
(
&
uval
,
*
argv
,
0
))
invarg
(
"invalid ID
\n
"
,
*
argv
);
...
...
@@ -547,36 +550,42 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p)
}
else
if
((
strcmp
(
*
argv
,
"peer_session_id"
)
==
0
)
||
(
strcmp
(
*
argv
,
"psid"
)
==
0
))
{
__u32
uval
;
NEXT_ARG
();
if
(
get_u32
(
&
uval
,
*
argv
,
0
))
invarg
(
"invalid ID
\n
"
,
*
argv
);
p
->
peer_session_id
=
uval
;
}
else
if
(
strcmp
(
*
argv
,
"udp_sport"
)
==
0
)
{
__u16
uval
;
NEXT_ARG
();
if
(
get_u16
(
&
uval
,
*
argv
,
0
))
invarg
(
"invalid port
\n
"
,
*
argv
);
p
->
local_udp_port
=
uval
;
}
else
if
(
strcmp
(
*
argv
,
"udp_dport"
)
==
0
)
{
__u16
uval
;
NEXT_ARG
();
if
(
get_u16
(
&
uval
,
*
argv
,
0
))
invarg
(
"invalid port
\n
"
,
*
argv
);
p
->
peer_udp_port
=
uval
;
}
else
if
(
strcmp
(
*
argv
,
"offset"
)
==
0
)
{
__u8
uval
;
NEXT_ARG
();
if
(
get_u8
(
&
uval
,
*
argv
,
0
))
invarg
(
"invalid offset
\n
"
,
*
argv
);
p
->
offset
=
uval
;
}
else
if
(
strcmp
(
*
argv
,
"peer_offset"
)
==
0
)
{
__u8
uval
;
NEXT_ARG
();
if
(
get_u8
(
&
uval
,
*
argv
,
0
))
invarg
(
"invalid offset
\n
"
,
*
argv
);
p
->
peer_offset
=
uval
;
}
else
if
(
strcmp
(
*
argv
,
"cookie"
)
==
0
)
{
int
slen
;
NEXT_ARG
();
slen
=
strlen
(
*
argv
);
if
((
slen
!=
8
)
&&
(
slen
!=
16
))
...
...
@@ -587,6 +596,7 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p)
invarg
(
"cookie must be a hex string
\n
"
,
*
argv
);
}
else
if
(
strcmp
(
*
argv
,
"peer_cookie"
)
==
0
)
{
int
slen
;
NEXT_ARG
();
slen
=
strlen
(
*
argv
);
if
((
slen
!=
8
)
&&
(
slen
!=
16
))
...
...
ip/iplink.c
View file @
56f5daac
...
...
@@ -358,6 +358,7 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp,
}
else
if
(
matches
(
*
argv
,
"trust"
)
==
0
)
{
struct
ifla_vf_trust
ivt
;
NEXT_ARG
();
if
(
matches
(
*
argv
,
"on"
)
==
0
)
ivt
.
setting
=
1
;
...
...
@@ -712,14 +713,12 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
&
group
,
sizeof
(
group
));
else
{
if
(
argc
)
{
fprintf
(
stderr
,
"Garbage instead of arguments "
"
\"
%s ...
\"
. Try
\"
ip link "
fprintf
(
stderr
,
"Garbage instead of arguments
\"
%s ...
\"
. Try
\"
ip link "
"help
\"
.
\n
"
,
*
argv
);
return
-
1
;
}
if
(
flags
&
NLM_F_CREATE
)
{
fprintf
(
stderr
,
"group cannot be used when "
"creating devices.
\n
"
);
fprintf
(
stderr
,
"group cannot be used when creating devices.
\n
"
);
return
-
1
;
}
...
...
@@ -733,13 +732,11 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
if
(
!
(
flags
&
NLM_F_CREATE
))
{
if
(
!
dev
)
{
fprintf
(
stderr
,
"Not enough information:
\"
dev
\"
"
"argument is required.
\n
"
);
fprintf
(
stderr
,
"Not enough information:
\"
dev
\"
argument is required.
\n
"
);
exit
(
-
1
);
}
if
(
cmd
==
RTM_NEWLINK
&&
index
!=
-
1
)
{
fprintf
(
stderr
,
"index can be used only when "
"creating devices.
\n
"
);
fprintf
(
stderr
,
"index can be used only when creating devices.
\n
"
);
exit
(
-
1
);
}
...
...
@@ -813,14 +810,13 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
}
else
if
(
argc
)
{
if
(
matches
(
*
argv
,
"help"
)
==
0
)
usage
();
fprintf
(
stderr
,
"Garbage instead of arguments
\"
%s ...
\"
.
"
"Try
\"
ip link help
\"
.
\n
"
,
*
argv
);
fprintf
(
stderr
,
"Garbage instead of arguments
\"
%s ...
\"
.
Try
\"
ip link help
\"
.
\n
"
,
*
argv
);
return
-
1
;
}
addattr_nest_end
(
&
req
.
n
,
linkinfo
);
}
else
if
(
flags
&
NLM_F_CREATE
)
{
fprintf
(
stderr
,
"Not enough information:
\"
type
\"
argument "
"is required
\n
"
);
fprintf
(
stderr
,
"Not enough information:
\"
type
\"
argument is required
\n
"
);
return
-
1
;
}
...
...
ip/iplink_bond.c
View file @
56f5daac
...
...
@@ -166,7 +166,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
__u32
miimon
,
updelay
,
downdelay
,
arp_interval
,
arp_validate
;
__u32
arp_all_targets
,
resend_igmp
,
min_links
,
lp_interval
;
__u32
packets_per_slave
;
unsigned
ifindex
;
unsigned
i
nt
i
findex
;
while
(
argc
>
0
)
{
if
(
matches
(
*
argv
,
"mode"
)
==
0
)
{
...
...
@@ -209,7 +209,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
invarg
(
"invalid arp_interval"
,
*
argv
);
addattr32
(
n
,
1024
,
IFLA_BOND_ARP_INTERVAL
,
arp_interval
);
}
else
if
(
matches
(
*
argv
,
"arp_ip_target"
)
==
0
)
{
struct
rtattr
*
nest
=
addattr_nest
(
n
,
1024
,
struct
rtattr
*
nest
=
addattr_nest
(
n
,
1024
,
IFLA_BOND_ARP_IP_TARGET
);
if
(
NEXT_ARG_OK
())
{
NEXT_ARG
();
...
...
@@ -217,8 +217,9 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
char
*
target
=
strtok
(
targets
,
","
);
int
i
;
for
(
i
=
0
;
target
&&
i
<
BOND_MAX_ARP_TARGETS
;
i
++
)
{
for
(
i
=
0
;
target
&&
i
<
BOND_MAX_ARP_TARGETS
;
i
++
)
{
__u32
addr
=
get_addr32
(
target
);
addattr32
(
n
,
1024
,
i
,
addr
);
target
=
strtok
(
NULL
,
","
);
}
...
...
@@ -368,7 +369,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
static
void
bond_print_opt
(
struct
link_util
*
lu
,
FILE
*
f
,
struct
rtattr
*
tb
[])
{
unsigned
ifindex
;
unsigned
i
nt
i
findex
;
if
(
!
tb
)
return
;
...
...
ip/iplink_bond_slave.c
View file @
56f5daac
...
...
@@ -26,7 +26,7 @@ static void print_slave_state(FILE *f, struct rtattr *tb)
{
unsigned
int
state
=
rta_getattr_u8
(
tb
);
if
(
state
>=
sizeof
(
slave_states
)
/
sizeof
(
slave_states
[
0
]
))
if
(
state
>=
ARRAY_SIZE
(
slave_states
))
fprintf
(
f
,
"state %d "
,
state
);
else
fprintf
(
f
,
"state %s "
,
slave_states
[
state
]);
...
...
@@ -43,7 +43,7 @@ static void print_slave_mii_status(FILE *f, struct rtattr *tb)
{
unsigned
int
status
=
rta_getattr_u8
(
tb
);
if
(
status
>=
sizeof
(
slave_mii_status
)
/
sizeof
(
slave_mii_status
[
0
]
))
if
(
status
>=
ARRAY_SIZE
(
slave_mii_status
))
fprintf
(
f
,
"mii_status %d "
,
status
);
else
fprintf
(
f
,
"mii_status %s "
,
slave_mii_status
[
status
]);
...
...
ip/iplink_bridge_slave.c
View file @
56f5daac
...
...
@@ -24,7 +24,7 @@ static void print_explain(FILE *f)
fprintf
(
f
,
"Usage: ... bridge_slave [ state STATE ] [ priority PRIO ] [cost COST ]
\n
"
" [ guard {on | off} ]
\n
"
" [ hairpin {on | off} ]
\n
"
" [ hairpin {on | off} ]
\n
"
" [ fastleave {on | off} ]
\n
"
" [ root_block {on | off} ]
\n
"
" [ learning {on | off} ]
\n
"
...
...
ip/iplink_can.c
View file @
56f5daac
...
...
@@ -23,13 +23,11 @@ static void print_usage(FILE *f)
{
fprintf
(
f
,
"Usage: ip link set DEVICE type can
\n
"
"
\t
[ bitrate BITRATE [ sample-point SAMPLE-POINT] ] |
\n
"
"
\t
[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1
\n
"
"
\t
phase-seg2 PHASE-SEG2 [ sjw SJW ] ]
\n
"
"
\t
[ bitrate BITRATE [ sample-point SAMPLE-POINT] ] |
\n
"
"
\t
[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1
\n
\t
phase-seg2 PHASE-SEG2 [ sjw SJW ] ]
\n
"
"
\n
"
"
\t
[ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] |
\n
"
"
\t
[ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1
\n
"
"
\t
dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]
\n
"
"
\t
[ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] |
\n
"
"
\t
[ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1
\n
\t
dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]
\n
"
"
\n
"
"
\t
[ loopback { on | off } ]
\n
"
"
\t
[ listen-only { on | off } ]
\n
"
...
...
@@ -73,7 +71,7 @@ static int get_float(float *val, const char *arg)
return
0
;
}
static
void
set_ctrlmode
(
char
*
name
,
char
*
arg
,
static
void
set_ctrlmode
(
char
*
name
,
char
*
arg
,
struct
can_ctrlmode
*
cm
,
__u32
flags
)
{
if
(
strcmp
(
arg
,
"on"
)
==
0
)
{
...
...
@@ -289,11 +287,9 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if
(
tb
[
IFLA_CAN_BITTIMING
])
{
struct
can_bittiming
*
bt
=
RTA_DATA
(
tb
[
IFLA_CAN_BITTIMING
]);
fprintf
(
f
,
"
\n
"
"bitrate %d sample-point %.3f "
,
fprintf
(
f
,
"
\n
bitrate %d sample-point %.3f "
,
bt
->
bitrate
,
(
float
)
bt
->
sample_point
/
1000
.);
fprintf
(
f
,
"
\n
"
"tq %d prop-seg %d phase-seg1 %d phase-seg2 %d sjw %d"
,
fprintf
(
f
,
"
\n
tq %d prop-seg %d phase-seg1 %d phase-seg2 %d sjw %d"
,
bt
->
tq
,
bt
->
prop_seg
,
bt
->
phase_seg1
,
bt
->
phase_seg2
,
bt
->
sjw
);
}
...
...
@@ -302,8 +298,7 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
struct
can_bittiming_const
*
btc
=
RTA_DATA
(
tb
[
IFLA_CAN_BITTIMING_CONST
]);
fprintf
(
f
,
"
\n
"
"%s: tseg1 %d..%d tseg2 %d..%d "
fprintf
(
f
,
"
\n
%s: tseg1 %d..%d tseg2 %d..%d "
"sjw 1..%d brp %d..%d brp-inc %d"
,
btc
->
name
,
btc
->
tseg1_min
,
btc
->
tseg1_max
,
btc
->
tseg2_min
,
btc
->
tseg2_max
,
btc
->
sjw_max
,
...
...
@@ -314,11 +309,9 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
struct
can_bittiming
*
dbt
=
RTA_DATA
(
tb
[
IFLA_CAN_DATA_BITTIMING
]);
fprintf
(
f
,
"
\n
"
"dbitrate %d dsample-point %.3f "
,
fprintf
(
f
,
"
\n
dbitrate %d dsample-point %.3f "
,
dbt
->
bitrate
,
(
float
)
dbt
->
sample_point
/
1000
.);
fprintf
(
f
,
"
\n
"
"dtq %d dprop-seg %d dphase-seg1 %d "
fprintf
(
f
,
"
\n
dtq %d dprop-seg %d dphase-seg1 %d "
"dphase-seg2 %d dsjw %d"
,
dbt
->
tq
,
dbt
->
prop_seg
,
dbt
->
phase_seg1
,
dbt
->
phase_seg2
,
dbt
->
sjw
);
...
...
@@ -328,8 +321,7 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
struct
can_bittiming_const
*
dbtc
=
RTA_DATA
(
tb
[
IFLA_CAN_DATA_BITTIMING_CONST
]);
fprintf
(
f
,
"
\n
"
"%s: dtseg1 %d..%d dtseg2 %d..%d "
fprintf
(
f
,
"
\n
%s: dtseg1 %d..%d dtseg2 %d..%d "
"dsjw 1..%d dbrp %d..%d dbrp-inc %d"
,
dbtc
->
name
,
dbtc
->
tseg1_min
,
dbtc
->
tseg1_max
,
dbtc
->
tseg2_min
,
dbtc
->
tseg2_max
,
dbtc
->
sjw_max
,
...
...
@@ -351,8 +343,7 @@ static void can_print_xstats(struct link_util *lu,
if
(
xstats
&&
RTA_PAYLOAD
(
xstats
)
==
sizeof
(
*
stats
))
{
stats
=
RTA_DATA
(
xstats
);
fprintf
(
f
,
"
\n
"
"re-started bus-errors arbit-lost "
fprintf
(
f
,
"
\n
re-started bus-errors arbit-lost "
"error-warn error-pass bus-off"
);
fprintf
(
f
,
"
\n
%-10d %-10d %-10d %-10d %-10d %-10d"
,
stats
->
restarts
,
stats
->
bus_error
,
...
...
ip/iplink_geneve.c
View file @
56f5daac
...
...
@@ -62,7 +62,7 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
invarg
(
"invalid remote address"
,
*
argv
);
}
else
if
(
!
matches
(
*
argv
,
"ttl"
)
||
!
matches
(
*
argv
,
"hoplimit"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"inherit"
)
!=
0
)
{
...
...
@@ -153,11 +153,13 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if
(
tb
[
IFLA_GENEVE_REMOTE
])
{
__be32
addr
=
rta_getattr_u32
(
tb
[
IFLA_GENEVE_REMOTE
]);
if
(
addr
)
fprintf
(
f
,
"remote %s "
,
format_host
(
AF_INET
,
4
,
&
addr
,
s1
,
sizeof
(
s1
)));
}
else
if
(
tb
[
IFLA_GENEVE_REMOTE6
])
{
struct
in6_addr
addr
;
memcpy
(
&
addr
,
RTA_DATA
(
tb
[
IFLA_GENEVE_REMOTE6
]),
sizeof
(
struct
in6_addr
));
if
(
memcmp
(
&
addr
,
&
in6addr_any
,
sizeof
(
addr
))
!=
0
)
{
if
(
IN6_IS_ADDR_MULTICAST
(
&
addr
))
...
...
@@ -168,6 +170,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if
(
tb
[
IFLA_GENEVE_TTL
])
{
__u8
ttl
=
rta_getattr_u8
(
tb
[
IFLA_GENEVE_TTL
]);
if
(
ttl
)
fprintf
(
f
,
"ttl %d "
,
ttl
);
}
...
...
ip/iplink_ipoib.c
View file @
56f5daac
...
...
@@ -22,8 +22,7 @@
static
void
print_explain
(
FILE
*
f
)
{
fprintf
(
f
,
"Usage: ... ipoib [pkey PKEY] [mode {datagram | connected}]"
"[umcast {0|1}]
\n
"
"Usage: ... ipoib [pkey PKEY] [mode {datagram | connected}][umcast {0|1}]
\n
"
"
\n
"
"PKEY := 0x8001-0xffff
\n
"
);
...
...
@@ -36,8 +35,7 @@ static void explain(void)
static
int
mode_arg
(
void
)
{
fprintf
(
stderr
,
"Error: argument of
\"
mode
\"
must be
\"
datagram
\"
"
"or
\"
connected
\"\n
"
);
fprintf
(
stderr
,
"Error: argument of
\"
mode
\"
must be
\"
datagram
\"
or
\"
connected
\"\n
"
);
return
-
1
;
}
...
...
ip/iplink_ipvlan.c
View file @
56f5daac
...
...
@@ -30,8 +30,7 @@ static void explain(void)
static
int
mode_arg
(
void
)
{
fprintf
(
stderr
,
"Error: argument of
\"
mode
\"
must be either
\"
l2
\"
, "
"or
\"
l3
\"\n
"
);
fprintf
(
stderr
,
"Error: argument of
\"
mode
\"
must be either
\"
l2
\"
, or
\"
l3
\"\n
"
);
return
-
1
;
}
...
...
@@ -41,6 +40,7 @@ static int ipvlan_parse_opt(struct link_util *lu, int argc, char **argv,
while
(
argc
>
0
)
{
if
(
matches
(
*
argv
,
"mode"
)
==
0
)
{
__u16
mode
=
0
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"l2"
)
==
0
)
...
...
ip/iplink_macvlan.c
View file @
56f5daac
...
...
@@ -41,9 +41,9 @@ static void explain(struct link_util *lu)
static
int
mode_arg
(
const
char
*
arg
)
{
fprintf
(
stderr
,
"Error: argument of
\"
mode
\"
must be
\"
private
\"
,
"
"
\"
vepa
\"
,
\"
bridge
\"
or
\"
passthru
\"
, not
\"
%s
\"\n
"
,
arg
);
return
-
1
;
fprintf
(
stderr
,
"Error: argument of
\"
mode
\"
must be
\"
private
\"
,
\"
vepa
\"
,
\"
bridge
\"
or
\"
passthru
\"
, not
\"
%s
\"\n
"
,
arg
);
return
-
1
;
}
static
int
macvlan_parse_opt
(
struct
link_util
*
lu
,
int
argc
,
char
**
argv
,
...
...
ip/iplink_vlan.c
View file @
56f5daac
...
...
@@ -21,8 +21,7 @@
static
void
print_explain
(
FILE
*
f
)
{
fprintf
(
f
,
"Usage: ... vlan [ protocol VLANPROTO ] id VLANID"
" [ FLAG-LIST ]
\n
"
"Usage: ... vlan [ protocol VLANPROTO ] id VLANID [ FLAG-LIST ]
\n
"
" [ ingress-qos-map QOS-MAP ] [ egress-qos-map QOS-MAP ]
\n
"
"
\n
"
"VLANPROTO: [ 802.1Q / 802.1ad ]
\n
"
...
...
@@ -182,7 +181,7 @@ static void vlan_print_flags(FILE *fp, __u32 flags)
{
fprintf
(
fp
,
"<"
);
#define _PF(f) if (flags & VLAN_FLAG_##f) { \
flags &= ~
VLAN_FLAG_##f; \
flags &= ~VLAN_FLAG_##f; \
fprintf(fp, #f "%s", flags ? "," : ""); \
}
_PF
(
REORDER_HDR
);
...
...
@@ -198,6 +197,7 @@ static void vlan_print_flags(FILE *fp, __u32 flags)
static
void
vlan_print_opt
(
struct
link_util
*
lu
,
FILE
*
f
,
struct
rtattr
*
tb
[])
{
struct
ifla_vlan_flags
*
flags
;
SPRINT_BUF
(
b1
);
if
(
!
tb
)
...
...
ip/iplink_vrf.c
View file @
56f5daac
...
...
@@ -20,7 +20,7 @@
static
void
vrf_explain
(
FILE
*
f
)
{
fprintf
(
f
,
"Usage: ... vrf table TABLEID
\n
"
);
fprintf
(
f
,
"Usage: ... vrf table TABLEID
\n
"
);
}
static
void
explain
(
void
)
...
...
@@ -91,8 +91,8 @@ struct link_util vrf_link_util = {
};
struct
link_util
vrf_slave_link_util
=
{
.
id
=
"vrf"
,
.
maxattr
=
IFLA_VRF_PORT_MAX
,
.
id
=
"vrf"
,
.
maxattr
=
IFLA_VRF_PORT_MAX
,
.
print_opt
=
vrf_slave_print_opt
,
.
slave
=
true
,
.
slave
=
true
,
};
ip/iplink_vxlan.c
View file @
56f5daac
...
...
@@ -55,7 +55,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
struct
in6_addr
saddr6
=
IN6ADDR_ANY_INIT
;
struct
in6_addr
gaddr6
=
IN6ADDR_ANY_INIT
;
struct
in6_addr
daddr6
=
IN6ADDR_ANY_INIT
;
unsigned
link
=
0
;
unsigned
int
link
=
0
;
__u8
tos
=
0
;
__u8
ttl
=
0
;
__u8
learning
=
1
;
...
...
@@ -122,7 +122,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
}
}
else
if
(
!
matches
(
*
argv
,
"ttl"
)
||
!
matches
(
*
argv
,
"hoplimit"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"inherit"
)
!=
0
)
{
...
...
@@ -158,6 +158,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
}
else
if
(
!
matches
(
*
argv
,
"port"
)
||
!
matches
(
*
argv
,
"srcport"
))
{
__u16
minport
,
maxport
;
NEXT_ARG
();
if
(
get_u16
(
&
minport
,
*
argv
,
0
))
invarg
(
"min port"
,
*
argv
);
...
...
@@ -166,7 +167,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
invarg
(
"max port"
,
*
argv
);
range
.
low
=
htons
(
minport
);
range
.
high
=
htons
(
maxport
);
}
else
if
(
!
matches
(
*
argv
,
"dstport"
)){
}
else
if
(
!
matches
(
*
argv
,
"dstport"
))
{
NEXT_ARG
();
if
(
get_u16
(
&
dstport
,
*
argv
,
0
))
invarg
(
"dst port"
,
*
argv
);
...
...
@@ -306,7 +307,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
static
void
vxlan_print_opt
(
struct
link_util
*
lu
,
FILE
*
f
,
struct
rtattr
*
tb
[])
{
__u32
vni
;
unsigned
link
;
unsigned
int
link
;
__u8
tos
;
__u32
maxaddr
;
char
s1
[
1024
];
...
...
@@ -324,6 +325,7 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if
(
tb
[
IFLA_VXLAN_GROUP
])
{
__be32
addr
=
rta_getattr_u32
(
tb
[
IFLA_VXLAN_GROUP
]);
if
(
addr
)
{
if
(
IN_MULTICAST
(
ntohl
(
addr
)))
fprintf
(
f
,
"group %s "
,
...
...
@@ -334,6 +336,7 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
}
}
else
if
(
tb
[
IFLA_VXLAN_GROUP6
])
{
struct
in6_addr
addr
;
memcpy
(
&
addr
,
RTA_DATA
(
tb
[
IFLA_VXLAN_GROUP6
]),
sizeof
(
struct
in6_addr
));
if
(
memcmp
(
&
addr
,
&
in6addr_any
,
sizeof
(
addr
))
!=
0
)
{
if
(
IN6_IS_ADDR_MULTICAST
(
&
addr
))
...
...
@@ -347,11 +350,13 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if
(
tb
[
IFLA_VXLAN_LOCAL
])
{
__be32
addr
=
rta_getattr_u32
(
tb
[
IFLA_VXLAN_LOCAL
]);
if
(
addr
)
fprintf
(
f
,
"local %s "
,
format_host
(
AF_INET
,
4
,
&
addr
,
s1
,
sizeof
(
s1
)));
}
else
if
(
tb
[
IFLA_VXLAN_LOCAL6
])
{
struct
in6_addr
addr
;
memcpy
(
&
addr
,
RTA_DATA
(
tb
[
IFLA_VXLAN_LOCAL6
]),
sizeof
(
struct
in6_addr
));
if
(
memcmp
(
&
addr
,
&
in6addr_any
,
sizeof
(
addr
))
!=
0
)
fprintf
(
f
,
"local %s "
,
...
...
@@ -404,12 +409,14 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if
(
tb
[
IFLA_VXLAN_TTL
])
{
__u8
ttl
=
rta_getattr_u8
(
tb
[
IFLA_VXLAN_TTL
]);
if
(
ttl
)
fprintf
(
f
,
"ttl %d "
,
ttl
);
}
if
(
tb
[
IFLA_VXLAN_AGEING
])
{
__u32
age
=
rta_getattr_u32
(
tb
[
IFLA_VXLAN_AGEING
]);
if
(
age
==
0
)
fprintf
(
f
,
"ageing none "
);
else
...
...
ip/ipmaddr.c
View file @
56f5daac
...
...
@@ -50,6 +50,7 @@ static int parse_hex(char *str, unsigned char *addr, size_t size)
while
(
*
str
&&
(
len
<
2
*
size
))
{
int
tmp
;
if
(
str
[
1
]
==
0
)
return
-
1
;
if
(
sscanf
(
str
,
"%02x"
,
&
tmp
)
!=
1
)
...
...
@@ -61,8 +62,7 @@ static int parse_hex(char *str, unsigned char *addr, size_t size)
return
len
;
}
struct
ma_info
{
struct
ma_info
{
struct
ma_info
*
next
;
int
index
;
int
users
;
...
...
@@ -105,7 +105,7 @@ static void read_dev_mcast(struct ma_info **result_p)
m
.
addr
.
family
=
AF_PACKET
;
len
=
parse_hex
(
hexa
,
(
unsigned
char
*
)
&
m
.
addr
.
data
,
sizeof
(
m
.
addr
.
data
));
len
=
parse_hex
(
hexa
,
(
unsigned
char
*
)
&
m
.
addr
.
data
,
sizeof
(
m
.
addr
.
data
));
if
(
len
>=
0
)
{
struct
ma_info
*
ma
=
malloc
(
sizeof
(
m
));
...
...
@@ -149,7 +149,7 @@ static void read_igmp(struct ma_info **result_p)
if
(
filter
.
dev
&&
strcmp
(
filter
.
dev
,
m
.
name
))
continue
;
sscanf
(
buf
,
"%08x%d"
,
(
__u32
*
)
&
m
.
addr
.
data
,
&
m
.
users
);
sscanf
(
buf
,
"%08x%d"
,
(
__u32
*
)
&
m
.
addr
.
data
,
&
m
.
users
);
ma
=
malloc
(
sizeof
(
m
));
memcpy
(
ma
,
&
m
,
sizeof
(
m
));
...
...
@@ -180,7 +180,7 @@ static void read_igmp6(struct ma_info **result_p)
m
.
addr
.
family
=
AF_INET6
;
len
=
parse_hex
(
hexa
,
(
unsigned
char
*
)
&
m
.
addr
.
data
,
sizeof
(
m
.
addr
.
data
));
len
=
parse_hex
(
hexa
,
(
unsigned
char
*
)
&
m
.
addr
.
data
,
sizeof
(
m
.
addr
.
data
));
if
(
len
>=
0
)
{
struct
ma_info
*
ma
=
malloc
(
sizeof
(
m
));
...
...
@@ -200,12 +200,13 @@ static void print_maddr(FILE *fp, struct ma_info *list)
if
(
list
->
addr
.
family
==
AF_PACKET
)
{
SPRINT_BUF
(
b1
);
fprintf
(
fp
,
"link %s"
,
ll_addr_n2a
((
unsigned
char
*
)
list
->
addr
.
data
,
fprintf
(
fp
,
"link %s"
,
ll_addr_n2a
((
unsigned
char
*
)
list
->
addr
.
data
,
list
->
addr
.
bytelen
,
0
,
b1
,
sizeof
(
b1
)));
}
else
{
char
abuf
[
256
];
switch
(
list
->
addr
.
family
)
{
switch
(
list
->
addr
.
family
)
{
case
AF_INET
:
fprintf
(
fp
,
"inet "
);
break
;
...
...
@@ -256,8 +257,7 @@ static int multiaddr_list(int argc, char **argv)
if
(
1
)
{
if
(
strcmp
(
*
argv
,
"dev"
)
==
0
)
{
NEXT_ARG
();
}
else
if
(
matches
(
*
argv
,
"help"
)
==
0
)
}
else
if
(
matches
(
*
argv
,
"help"
)
==
0
)
usage
();
if
(
filter
.
dev
)
duparg2
(
"dev"
,
*
argv
);
...
...
@@ -320,7 +320,7 @@ static int multiaddr_modify(int cmd, int argc, char **argv)
perror
(
"Cannot create socket"
);
exit
(
1
);
}
if
(
ioctl
(
fd
,
cmd
,
(
char
*
)
&
ifr
)
!=
0
)
{
if
(
ioctl
(
fd
,
cmd
,
(
char
*
)
&
ifr
)
!=
0
)
{
perror
(
"ioctl"
);
exit
(
1
);
}
...
...
ip/ipmonitor.c
View file @
56f5daac
...
...
@@ -30,8 +30,7 @@ int listen_all_nsid;
static
void
usage
(
void
)
{
fprintf
(
stderr
,
"Usage: ip monitor [ all | LISTofOBJECTS ] [ FILE ] "
"[ label ] [all-nsid] [dev DEVICE]
\n
"
);
fprintf
(
stderr
,
"Usage: ip monitor [ all | LISTofOBJECTS ] [ FILE ] [ label ] [all-nsid] [dev DEVICE]
\n
"
);
fprintf
(
stderr
,
"LISTofOBJECTS := link | address | route | mroute | prefix |
\n
"
);
fprintf
(
stderr
,
" neigh | netconf | rule | nsid
\n
"
);
fprintf
(
stderr
,
"FILE := file FILENAME
\n
"
);
...
...
@@ -58,7 +57,7 @@ static int accept_msg(const struct sockaddr_nl *who,
struct
rtnl_ctrl_data
*
ctrl
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
if
(
n
->
nlmsg_type
==
RTM_NEWROUTE
||
n
->
nlmsg_type
==
RTM_DELROUTE
)
{
struct
rtmsg
*
r
=
NLMSG_DATA
(
n
);
...
...
@@ -139,8 +138,8 @@ static int accept_msg(const struct sockaddr_nl *who,
}
if
(
n
->
nlmsg_type
!=
NLMSG_ERROR
&&
n
->
nlmsg_type
!=
NLMSG_NOOP
&&
n
->
nlmsg_type
!=
NLMSG_DONE
)
{
fprintf
(
fp
,
"Unknown message: type=0x%08x(%d) flags=0x%08x(%d)
"
"len=0x%08x(%d)
\n
"
,
n
->
nlmsg_type
,
n
->
nlmsg_type
,
fprintf
(
fp
,
"Unknown message: type=0x%08x(%d) flags=0x%08x(%d)
len=0x%08x(%d)
\n
"
,
n
->
nlmsg_type
,
n
->
nlmsg_type
,
n
->
nlmsg_flags
,
n
->
nlmsg_flags
,
n
->
nlmsg_len
,
n
->
nlmsg_len
);
}
...
...
@@ -150,17 +149,17 @@ static int accept_msg(const struct sockaddr_nl *who,
int
do_ipmonitor
(
int
argc
,
char
**
argv
)
{
char
*
file
=
NULL
;
unsigned
groups
=
0
;
int
llink
=
0
;
int
laddr
=
0
;
int
lroute
=
0
;
int
lmroute
=
0
;
int
lprefix
=
0
;
int
lneigh
=
0
;
int
lnetconf
=
0
;
int
lrule
=
0
;
int
lnsid
=
0
;
int
ifindex
=
0
;
unsigned
int
groups
=
0
;
int
llink
=
0
;
int
laddr
=
0
;
int
lroute
=
0
;
int
lmroute
=
0
;
int
lprefix
=
0
;
int
lneigh
=
0
;
int
lnetconf
=
0
;
int
lrule
=
0
;
int
lnsid
=
0
;
int
ifindex
=
0
;
groups
|=
nl_mgrp
(
RTNLGRP_LINK
);
groups
|=
nl_mgrp
(
RTNLGRP_IPV4_IFADDR
);
...
...
@@ -187,19 +186,19 @@ int do_ipmonitor(int argc, char **argv)
}
else
if
(
matches
(
*
argv
,
"label"
)
==
0
)
{
prefix_banner
=
1
;
}
else
if
(
matches
(
*
argv
,
"link"
)
==
0
)
{
llink
=
1
;
llink
=
1
;
groups
=
0
;
}
else
if
(
matches
(
*
argv
,
"address"
)
==
0
)
{
laddr
=
1
;
laddr
=
1
;
groups
=
0
;
}
else
if
(
matches
(
*
argv
,
"route"
)
==
0
)
{
lroute
=
1
;
lroute
=
1
;
groups
=
0
;
}
else
if
(
matches
(
*
argv
,
"mroute"
)
==
0
)
{
lmroute
=
1
;
lmroute
=
1
;
groups
=
0
;
}
else
if
(
matches
(
*
argv
,
"prefix"
)
==
0
)
{
lprefix
=
1
;
lprefix
=
1
;
groups
=
0
;
}
else
if
(
matches
(
*
argv
,
"neigh"
)
==
0
)
{
lneigh
=
1
;
...
...
@@ -214,7 +213,7 @@ int do_ipmonitor(int argc, char **argv)
lnsid
=
1
;
groups
=
0
;
}
else
if
(
strcmp
(
*
argv
,
"all"
)
==
0
)
{
prefix_banner
=
1
;
prefix_banner
=
1
;
}
else
if
(
matches
(
*
argv
,
"all-nsid"
)
==
0
)
{
listen_all_nsid
=
1
;
}
else
if
(
matches
(
*
argv
,
"help"
)
==
0
)
{
...
...
ip/ipmroute.c
View file @
56f5daac
...
...
@@ -44,8 +44,7 @@ static void usage(void)
exit
(
-
1
);
}
struct
rtfilter
{
struct
rtfilter
{
int
tb
;
int
af
;
int
iif
;
...
...
@@ -55,12 +54,13 @@ struct rtfilter
int
print_mroute
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
rtmsg
*
r
=
NLMSG_DATA
(
n
);
int
len
=
n
->
nlmsg_len
;
struct
rtattr
*
tb
[
RTA_MAX
+
1
];
struct
rtattr
*
tb
[
RTA_MAX
+
1
];
char
abuf
[
256
];
char
obuf
[
256
];
SPRINT_BUF
(
b1
);
__u32
table
;
int
iif
=
0
;
...
...
@@ -90,7 +90,7 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
return
0
;
if
(
tb
[
RTA_IIF
])
iif
=
*
(
int
*
)
RTA_DATA
(
tb
[
RTA_IIF
]);
iif
=
*
(
int
*
)
RTA_DATA
(
tb
[
RTA_IIF
]);
if
(
filter
.
iif
&&
filter
.
iif
!=
iif
)
return
0
;
...
...
@@ -212,6 +212,7 @@ static int mroute_list(int argc, char **argv)
while
(
argc
>
0
)
{
if
(
matches
(
*
argv
,
"table"
)
==
0
)
{
__u32
tid
;
NEXT_ARG
();
if
(
rtnl_rttable_a2n
(
&
tid
,
*
argv
))
{
if
(
strcmp
(
*
argv
,
"all"
)
==
0
)
{
...
...
ip/ipneigh.c
View file @
56f5daac
...
...
@@ -31,7 +31,7 @@
static
struct
{
int
family
;
int
index
;
int
index
;
int
state
;
int
unused_only
;
inet_prefix
pfx
;
...
...
@@ -50,11 +50,11 @@ static void usage(void)
" { ADDR [ lladdr LLADDR ] [ nud STATE ] | proxy ADDR } [ dev DEV ]
\n
"
);
fprintf
(
stderr
,
" ip neigh { show | flush } [ proxy ] [ to PREFIX ] [ dev DEV ] [ nud STATE ]
\n\n
"
);
fprintf
(
stderr
,
"STATE := { permanent | noarp | stale | reachable | none |
\n
"
" incomplete | delay | probe | failed }
\n
"
);
" incomplete | delay | probe | failed }
\n
"
);
exit
(
-
1
);
}
static
int
nud_state_a2n
(
unsigned
*
state
,
const
char
*
arg
)
static
int
nud_state_a2n
(
unsigned
int
*
state
,
const
char
*
arg
)
{
if
(
matches
(
arg
,
"permanent"
)
==
0
)
*
state
=
NUD_PERMANENT
;
...
...
@@ -77,7 +77,7 @@ static int nud_state_a2n(unsigned *state, const char *arg)
else
{
if
(
get_unsigned
(
state
,
arg
,
0
))
return
-
1
;
if
(
*
state
>=
0x100
||
(
*
state
&
((
*
state
)
-
1
)))
if
(
*
state
>=
0x100
||
(
*
state
&
((
*
state
)
-
1
)))
return
-
1
;
}
return
0
;
...
...
@@ -99,13 +99,13 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
struct
{
struct
nlmsghdr
n
;
struct
ndmsg
ndm
;
char
buf
[
256
];
char
buf
[
256
];
}
req
;
char
*
dev
=
NULL
;
int
dst_ok
=
0
;
int
dev_ok
=
0
;
int
lladdr_ok
=
0
;
char
*
lla
=
NULL
;
char
*
lla
=
NULL
;
inet_prefix
dst
;
memset
(
&
req
,
0
,
sizeof
(
req
));
...
...
@@ -124,7 +124,8 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
lla
=
*
argv
;
lladdr_ok
=
1
;
}
else
if
(
strcmp
(
*
argv
,
"nud"
)
==
0
)
{
unsigned
state
;
unsigned
int
state
;
NEXT_ARG
();
if
(
nud_state_a2n
(
&
state
,
*
argv
))
invarg
(
"nud state is bad"
,
*
argv
);
...
...
@@ -193,10 +194,10 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
int
print_neigh
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
ndmsg
*
r
=
NLMSG_DATA
(
n
);
int
len
=
n
->
nlmsg_len
;
struct
rtattr
*
tb
[
NDA_MAX
+
1
];
struct
rtattr
*
tb
[
NDA_MAX
+
1
];
char
abuf
[
256
];
static
int
logit
=
1
;
...
...
@@ -223,7 +224,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if
(
!
(
filter
.
state
&
r
->
ndm_state
)
&&
!
(
r
->
ndm_flags
&
NTF_PROXY
)
&&
(
r
->
ndm_state
||
!
(
filter
.
state
&
0x100
))
&&
(
r
->
ndm_family
!=
AF_DECnet
))
(
r
->
ndm_family
!=
AF_DECnet
))
return
0
;
if
(
filter
.
master
&&
!
(
n
->
nlmsg_flags
&
NLM_F_DUMP_FILTERED
))
{
...
...
@@ -239,6 +240,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if
(
tb
[
NDA_DST
])
{
if
(
filter
.
pfx
.
family
)
{
inet_prefix
dst
;
memset
(
&
dst
,
0
,
sizeof
(
dst
));
dst
.
family
=
r
->
ndm_family
;
memcpy
(
&
dst
.
data
,
RTA_DATA
(
tb
[
NDA_DST
]),
RTA_PAYLOAD
(
tb
[
NDA_DST
]));
...
...
@@ -248,22 +250,24 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
if
(
filter
.
unused_only
&&
tb
[
NDA_CACHEINFO
])
{
struct
nda_cacheinfo
*
ci
=
RTA_DATA
(
tb
[
NDA_CACHEINFO
]);
if
(
ci
->
ndm_refcnt
)
return
0
;
}
if
(
filter
.
flushb
)
{
struct
nlmsghdr
*
fn
;
if
(
NLMSG_ALIGN
(
filter
.
flushp
)
+
n
->
nlmsg_len
>
filter
.
flushe
)
{
if
(
flush_update
())
return
-
1
;
}
fn
=
(
struct
nlmsghdr
*
)(
filter
.
flushb
+
NLMSG_ALIGN
(
filter
.
flushp
));
fn
=
(
struct
nlmsghdr
*
)(
filter
.
flushb
+
NLMSG_ALIGN
(
filter
.
flushp
));
memcpy
(
fn
,
n
,
n
->
nlmsg_len
);
fn
->
nlmsg_type
=
RTM_DELNEIGH
;
fn
->
nlmsg_flags
=
NLM_F_REQUEST
;
fn
->
nlmsg_seq
=
++
rth
.
seq
;
filter
.
flushp
=
(((
char
*
)
fn
)
+
n
->
nlmsg_len
)
-
filter
.
flushb
;
filter
.
flushp
=
(((
char
*
)
fn
)
+
n
->
nlmsg_len
)
-
filter
.
flushb
;
filter
.
flushed
++
;
if
(
show_stats
<
2
)
return
0
;
...
...
@@ -307,11 +311,13 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if
(
tb
[
NDA_PROBES
]
&&
show_stats
)
{
__u32
p
=
rta_getattr_u32
(
tb
[
NDA_PROBES
]);
fprintf
(
fp
,
" probes %u"
,
p
);
}
if
(
r
->
ndm_state
)
{
int
nud
=
r
->
ndm_state
;
fprintf
(
fp
,
" "
);
#define PRINT_FLAG(f) if (nud & NUD_##f) { \
...
...
@@ -344,7 +350,7 @@ static int do_show_or_flush(int argc, char **argv, int flush)
struct
{
struct
nlmsghdr
n
;
struct
ndmsg
ndm
;
char
buf
[
256
];
char
buf
[
256
];
}
req
;
char
*
filter_dev
=
NULL
;
int
state_given
=
0
;
...
...
@@ -376,6 +382,7 @@ static int do_show_or_flush(int argc, char **argv, int flush)
filter_dev
=
*
argv
;
}
else
if
(
strcmp
(
*
argv
,
"master"
)
==
0
)
{
int
ifindex
;
NEXT_ARG
();
ifindex
=
ll_name_to_index
(
*
argv
);
if
(
!
ifindex
)
...
...
@@ -385,7 +392,8 @@ static int do_show_or_flush(int argc, char **argv, int flush)
}
else
if
(
strcmp
(
*
argv
,
"unused"
)
==
0
)
{
filter
.
unused_only
=
1
;
}
else
if
(
strcmp
(
*
argv
,
"nud"
)
==
0
)
{
unsigned
state
;
unsigned
int
state
;
NEXT_ARG
();
if
(
!
state_given
)
{
state_given
=
1
;
...
...
@@ -450,7 +458,7 @@ static int do_show_or_flush(int argc, char **argv, int flush)
if
(
round
==
0
)
printf
(
"Nothing to flush.
\n
"
);
else
printf
(
"*** Flush is complete after %d round%s ***
\n
"
,
round
,
round
>
1
?
"s"
:
""
);
printf
(
"*** Flush is complete after %d round%s ***
\n
"
,
round
,
round
>
1
?
"s"
:
""
);
}
fflush
(
stdout
);
return
0
;
...
...
ip/ipnetconf.c
View file @
56f5daac
...
...
@@ -38,12 +38,12 @@ static void usage(void)
exit
(
-
1
);
}
#define NETCONF_RTA(r) ((struct rtattr
*)(((char
*)(r)) + NLMSG_ALIGN(sizeof(struct netconfmsg))))
#define NETCONF_RTA(r) ((struct rtattr
*)(((char
*)(r)) + NLMSG_ALIGN(sizeof(struct netconfmsg))))
int
print_netconf
(
const
struct
sockaddr_nl
*
who
,
struct
rtnl_ctrl_data
*
ctrl
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
netconfmsg
*
ncm
=
NLMSG_DATA
(
n
);
int
len
=
n
->
nlmsg_len
;
struct
rtattr
*
tb
[
NETCONFA_MAX
+
1
];
...
...
ip/ipnetns.c
View file @
56f5daac
...
...
@@ -389,6 +389,7 @@ static int cmd_exec(const char *cmd, char **argv, bool do_fork)
static
int
on_netns_exec
(
char
*
nsname
,
void
*
arg
)
{
char
**
argv
=
arg
;
cmd_exec
(
argv
[
1
],
argv
+
1
,
true
);
return
0
;
}
...
...
@@ -426,6 +427,7 @@ static int netns_exec(int argc, char **argv)
static
int
is_pid
(
const
char
*
str
)
{
int
ch
;
for
(;
(
ch
=
*
str
);
str
++
)
{
if
(
!
isdigit
(
ch
))
return
0
;
...
...
@@ -470,9 +472,10 @@ static int netns_pids(int argc, char **argv)
strerror
(
errno
));
return
-
1
;
}
while
((
entry
=
readdir
(
dir
)))
{
while
((
entry
=
readdir
(
dir
)))
{
char
pid_net_path
[
PATH_MAX
];
struct
stat
st
;
if
(
!
is_pid
(
entry
->
d_name
))
continue
;
snprintf
(
pid_net_path
,
sizeof
(
pid_net_path
),
"/proc/%s/ns/net"
,
...
...
@@ -535,7 +538,7 @@ static int netns_identify(int argc, char **argv)
return
-
1
;
}
while
((
entry
=
readdir
(
dir
)))
{
while
((
entry
=
readdir
(
dir
)))
{
char
name_path
[
PATH_MAX
];
struct
stat
st
;
...
...
@@ -737,6 +740,7 @@ static int netns_monitor(int argc, char **argv)
char
buf
[
4096
];
struct
inotify_event
*
event
;
int
fd
;
fd
=
inotify_init
();
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"inotify_init failed: %s
\n
"
,
...
...
@@ -752,8 +756,9 @@ static int netns_monitor(int argc, char **argv)
strerror
(
errno
));
return
-
1
;
}
for
(;;)
{
for
(;;)
{
ssize_t
len
=
read
(
fd
,
buf
,
sizeof
(
buf
));
if
(
len
<
0
)
{
fprintf
(
stderr
,
"read failed: %s
\n
"
,
strerror
(
errno
));
...
...
ip/ipntable.c
View file @
56f5daac
...
...
@@ -35,7 +35,7 @@
static
struct
{
int
family
;
int
index
;
int
index
;
#define NONE_DEV (-1)
char
name
[
1024
];
}
filter
;
...
...
@@ -65,7 +65,7 @@ static int ipntable_modify(int cmd, int flags, int argc, char **argv)
struct
{
struct
nlmsghdr
n
;
struct
ndtmsg
ndtm
;
char
buf
[
1024
];
char
buf
[
1024
];
}
req
;
char
*
namep
=
NULL
;
char
*
threshsp
=
NULL
;
...
...
@@ -351,7 +351,7 @@ static const char *ntable_strtime_delta(__u32 msec)
static
int
print_ntable
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
ndtmsg
*
ndtm
=
NLMSG_DATA
(
n
);
int
len
=
n
->
nlmsg_len
;
struct
rtattr
*
tb
[
NDTA_MAX
+
1
];
...
...
@@ -407,6 +407,7 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if
(
tb
[
NDTA_NAME
])
{
const
char
*
name
=
rta_getattr_str
(
tb
[
NDTA_NAME
]);
fprintf
(
fp
,
"%s "
,
name
);
}
...
...
@@ -419,18 +420,22 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if
(
tb
[
NDTA_THRESH1
])
{
__u32
thresh1
=
rta_getattr_u32
(
tb
[
NDTA_THRESH1
]);
fprintf
(
fp
,
"thresh1 %u "
,
thresh1
);
}
if
(
tb
[
NDTA_THRESH2
])
{
__u32
thresh2
=
rta_getattr_u32
(
tb
[
NDTA_THRESH2
]);
fprintf
(
fp
,
"thresh2 %u "
,
thresh2
);
}
if
(
tb
[
NDTA_THRESH3
])
{
__u32
thresh3
=
rta_getattr_u32
(
tb
[
NDTA_THRESH3
]);
fprintf
(
fp
,
"thresh3 %u "
,
thresh3
);
}
if
(
tb
[
NDTA_GC_INTERVAL
])
{
unsigned
long
long
gc_int
=
rta_getattr_u64
(
tb
[
NDTA_GC_INTERVAL
]);
fprintf
(
fp
,
"gc_int %llu "
,
gc_int
);
}
...
...
@@ -480,18 +485,22 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if
(
tpb
[
NDTPA_REFCNT
])
{
__u32
refcnt
=
rta_getattr_u32
(
tpb
[
NDTPA_REFCNT
]);
fprintf
(
fp
,
"refcnt %u "
,
refcnt
);
}
if
(
tpb
[
NDTPA_REACHABLE_TIME
])
{
unsigned
long
long
reachable
=
rta_getattr_u64
(
tpb
[
NDTPA_REACHABLE_TIME
]);
fprintf
(
fp
,
"reachable %llu "
,
reachable
);
}
if
(
tpb
[
NDTPA_BASE_REACHABLE_TIME
])
{
unsigned
long
long
breachable
=
rta_getattr_u64
(
tpb
[
NDTPA_BASE_REACHABLE_TIME
]);
fprintf
(
fp
,
"base_reachable %llu "
,
breachable
);
}
if
(
tpb
[
NDTPA_RETRANS_TIME
])
{
unsigned
long
long
retrans
=
rta_getattr_u64
(
tpb
[
NDTPA_RETRANS_TIME
]);
fprintf
(
fp
,
"retrans %llu "
,
retrans
);
}
...
...
@@ -501,14 +510,17 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if
(
tpb
[
NDTPA_GC_STALETIME
])
{
unsigned
long
long
gc_stale
=
rta_getattr_u64
(
tpb
[
NDTPA_GC_STALETIME
]);
fprintf
(
fp
,
"gc_stale %llu "
,
gc_stale
);
}
if
(
tpb
[
NDTPA_DELAY_PROBE_TIME
])
{
unsigned
long
long
delay_probe
=
rta_getattr_u64
(
tpb
[
NDTPA_DELAY_PROBE_TIME
]);
fprintf
(
fp
,
"delay_probe %llu "
,
delay_probe
);
}
if
(
tpb
[
NDTPA_QUEUE_LEN
])
{
__u32
queue
=
rta_getattr_u32
(
tpb
[
NDTPA_QUEUE_LEN
]);
fprintf
(
fp
,
"queue %u "
,
queue
);
}
...
...
@@ -518,14 +530,17 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if
(
tpb
[
NDTPA_APP_PROBES
])
{
__u32
aprobe
=
rta_getattr_u32
(
tpb
[
NDTPA_APP_PROBES
]);
fprintf
(
fp
,
"app_probes %u "
,
aprobe
);
}
if
(
tpb
[
NDTPA_UCAST_PROBES
])
{
__u32
uprobe
=
rta_getattr_u32
(
tpb
[
NDTPA_UCAST_PROBES
]);
fprintf
(
fp
,
"ucast_probes %u "
,
uprobe
);
}
if
(
tpb
[
NDTPA_MCAST_PROBES
])
{
__u32
mprobe
=
rta_getattr_u32
(
tpb
[
NDTPA_MCAST_PROBES
]);
fprintf
(
fp
,
"mcast_probes %u "
,
mprobe
);
}
...
...
@@ -535,18 +550,22 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
if
(
tpb
[
NDTPA_ANYCAST_DELAY
])
{
unsigned
long
long
anycast_delay
=
rta_getattr_u64
(
tpb
[
NDTPA_ANYCAST_DELAY
]);
fprintf
(
fp
,
"anycast_delay %llu "
,
anycast_delay
);
}
if
(
tpb
[
NDTPA_PROXY_DELAY
])
{
unsigned
long
long
proxy_delay
=
rta_getattr_u64
(
tpb
[
NDTPA_PROXY_DELAY
]);
fprintf
(
fp
,
"proxy_delay %llu "
,
proxy_delay
);
}
if
(
tpb
[
NDTPA_PROXY_QLEN
])
{
__u32
pqueue
=
rta_getattr_u32
(
tpb
[
NDTPA_PROXY_QLEN
]);
fprintf
(
fp
,
"proxy_queue %u "
,
pqueue
);
}
if
(
tpb
[
NDTPA_LOCKTIME
])
{
unsigned
long
long
locktime
=
rta_getattr_u64
(
tpb
[
NDTPA_LOCKTIME
]);
fprintf
(
fp
,
"locktime %llu "
,
locktime
);
}
...
...
ip/ipprefix.c
View file @
56f5daac
...
...
@@ -37,10 +37,10 @@
int
print_prefix
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
prefixmsg
*
prefix
=
NLMSG_DATA
(
n
);
int
len
=
n
->
nlmsg_len
;
struct
rtattr
*
tb
[
RTA_MAX
+
1
];
struct
rtattr
*
tb
[
RTA_MAX
+
1
];
int
family
=
preferred_family
;
if
(
n
->
nlmsg_type
!=
RTM_NEWPREFIX
)
{
...
...
@@ -96,6 +96,7 @@ int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if
(
tb
[
PREFIX_CACHEINFO
])
{
struct
prefix_cacheinfo
*
pc
;
pc
=
(
struct
prefix_cacheinfo
*
)
RTA_DATA
(
tb
[
PREFIX_CACHEINFO
]);
fprintf
(
fp
,
"valid %u "
,
pc
->
valid_time
);
...
...
ip/iproute.c
View file @
56f5daac
...
...
@@ -48,7 +48,7 @@ static const char *mx_names[RTAX_MAX+1] = {
[
RTAX_SSTHRESH
]
=
"ssthresh"
,
[
RTAX_CWND
]
=
"cwnd"
,
[
RTAX_ADVMSS
]
=
"advmss"
,
[
RTAX_REORDERING
]
=
"reordering"
,
[
RTAX_REORDERING
]
=
"reordering"
,
[
RTAX_HOPLIMIT
]
=
"hoplimit"
,
[
RTAX_INITCWND
]
=
"initcwnd"
,
[
RTAX_FEATURES
]
=
"features"
,
...
...
@@ -198,8 +198,10 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
return
0
;
if
(
filter
.
rvia
.
family
)
{
int
family
=
r
->
rtm_family
;
if
(
tb
[
RTA_VIA
])
{
struct
rtvia
*
via
=
RTA_DATA
(
tb
[
RTA_VIA
]);
family
=
via
->
rtvia_family
;
}
if
(
family
!=
filter
.
rvia
.
family
)
...
...
@@ -218,7 +220,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
if
(
tb
[
RTA_SRC
])
memcpy
(
&
src
.
data
,
RTA_DATA
(
tb
[
RTA_SRC
]),
(
r
->
rtm_src_len
+
7
)
/
8
);
}
if
(
filter
.
rvia
.
bitlen
>
0
)
{
if
(
filter
.
rvia
.
bitlen
>
0
)
{
memset
(
&
via
,
0
,
sizeof
(
via
));
via
.
family
=
r
->
rtm_family
;
if
(
tb
[
RTA_GATEWAY
])
...
...
@@ -226,11 +228,12 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
if
(
tb
[
RTA_VIA
])
{
size_t
len
=
RTA_PAYLOAD
(
tb
[
RTA_VIA
])
-
2
;
struct
rtvia
*
rtvia
=
RTA_DATA
(
tb
[
RTA_VIA
]);
via
.
family
=
rtvia
->
rtvia_family
;
memcpy
(
&
via
.
data
,
rtvia
->
rtvia_addr
,
len
);
}
}
if
(
filter
.
rprefsrc
.
bitlen
>
0
)
{
if
(
filter
.
rprefsrc
.
bitlen
>
0
)
{
memset
(
&
prefsrc
,
0
,
sizeof
(
prefsrc
));
prefsrc
.
family
=
r
->
rtm_family
;
if
(
tb
[
RTA_PREFSRC
])
...
...
@@ -255,6 +258,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
return
0
;
if
(
filter
.
realmmask
)
{
__u32
realms
=
0
;
if
(
tb
[
RTA_FLOW
])
realms
=
rta_getattr_u32
(
tb
[
RTA_FLOW
]);
if
((
realms
^
filter
.
realm
)
&
filter
.
realmmask
)
...
...
@@ -262,20 +266,23 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
}
if
(
filter
.
iifmask
)
{
int
iif
=
0
;
if
(
tb
[
RTA_IIF
])
iif
=
*
(
int
*
)
RTA_DATA
(
tb
[
RTA_IIF
]);
iif
=
*
(
int
*
)
RTA_DATA
(
tb
[
RTA_IIF
]);
if
((
iif
^
filter
.
iif
)
&
filter
.
iifmask
)
return
0
;
}
if
(
filter
.
oifmask
)
{
int
oif
=
0
;
if
(
tb
[
RTA_OIF
])
oif
=
*
(
int
*
)
RTA_DATA
(
tb
[
RTA_OIF
]);
oif
=
*
(
int
*
)
RTA_DATA
(
tb
[
RTA_OIF
]);
if
((
oif
^
filter
.
oif
)
&
filter
.
oifmask
)
return
0
;
}
if
(
filter
.
markmask
)
{
int
mark
=
0
;
if
(
tb
[
RTA_MARK
])
mark
=
*
(
int
*
)
RTA_DATA
(
tb
[
RTA_MARK
]);
if
((
mark
^
filter
.
mark
)
&
filter
.
markmask
)
...
...
@@ -286,7 +293,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
r
->
rtm_dst_len
==
0
&&
r
->
rtm_type
==
RTN_UNREACHABLE
&&
tb
[
RTA_PRIORITY
]
&&
*
(
int
*
)
RTA_DATA
(
tb
[
RTA_PRIORITY
])
==
-
1
)
*
(
int
*
)
RTA_DATA
(
tb
[
RTA_PRIORITY
])
==
-
1
)
return
0
;
return
1
;
...
...
@@ -307,13 +314,14 @@ static void print_rtax_features(FILE *fp, unsigned int features)
int
print_route
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
rtmsg
*
r
=
NLMSG_DATA
(
n
);
int
len
=
n
->
nlmsg_len
;
struct
rtattr
*
tb
[
RTA_MAX
+
1
];
struct
rtattr
*
tb
[
RTA_MAX
+
1
];
char
abuf
[
256
];
int
host_len
;
__u32
table
;
SPRINT_BUF
(
b1
);
static
int
hz
;
...
...
@@ -340,16 +348,17 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if
(
filter
.
flushb
)
{
struct
nlmsghdr
*
fn
;
if
(
NLMSG_ALIGN
(
filter
.
flushp
)
+
n
->
nlmsg_len
>
filter
.
flushe
)
{
if
(
flush_update
())
return
-
1
;
}
fn
=
(
struct
nlmsghdr
*
)(
filter
.
flushb
+
NLMSG_ALIGN
(
filter
.
flushp
));
fn
=
(
struct
nlmsghdr
*
)(
filter
.
flushb
+
NLMSG_ALIGN
(
filter
.
flushp
));
memcpy
(
fn
,
n
,
n
->
nlmsg_len
);
fn
->
nlmsg_type
=
RTM_DELROUTE
;
fn
->
nlmsg_flags
=
NLM_F_REQUEST
;
fn
->
nlmsg_seq
=
++
rth
.
seq
;
filter
.
flushp
=
(((
char
*
)
fn
)
+
n
->
nlmsg_len
)
-
filter
.
flushb
;
filter
.
flushp
=
(((
char
*
)
fn
)
+
n
->
nlmsg_len
)
-
filter
.
flushb
;
filter
.
flushed
++
;
if
(
show_stats
<
2
)
return
0
;
...
...
@@ -424,13 +433,14 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if
(
tb
[
RTA_VIA
])
{
size_t
len
=
RTA_PAYLOAD
(
tb
[
RTA_VIA
])
-
2
;
struct
rtvia
*
via
=
RTA_DATA
(
tb
[
RTA_VIA
]);
fprintf
(
fp
,
"via %s %s "
,
family_name
(
via
->
rtvia_family
),
format_host
(
via
->
rtvia_family
,
len
,
via
->
rtvia_addr
,
abuf
,
sizeof
(
abuf
)));
}
if
(
tb
[
RTA_OIF
]
&&
filter
.
oifmask
!=
-
1
)
fprintf
(
fp
,
"dev %s "
,
ll_index_to_name
(
*
(
int
*
)
RTA_DATA
(
tb
[
RTA_OIF
])));
fprintf
(
fp
,
"dev %s "
,
ll_index_to_name
(
*
(
int
*
)
RTA_DATA
(
tb
[
RTA_OIF
])));
if
(
table
&&
(
table
!=
RT_TABLE_MAIN
||
show_details
>
0
)
&&
!
filter
.
tb
)
fprintf
(
fp
,
" table %s "
,
rtnl_rttable_n2a
(
table
,
b1
,
sizeof
(
b1
)));
...
...
@@ -465,7 +475,8 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if
(
r
->
rtm_flags
&
RTNH_F_LINKDOWN
)
fprintf
(
fp
,
"linkdown "
);
if
(
tb
[
RTA_MARK
])
{
unsigned
int
mark
=
*
(
unsigned
int
*
)
RTA_DATA
(
tb
[
RTA_MARK
]);
unsigned
int
mark
=
*
(
unsigned
int
*
)
RTA_DATA
(
tb
[
RTA_MARK
]);
if
(
mark
)
{
if
(
mark
>=
16
)
fprintf
(
fp
,
" mark 0x%x"
,
mark
);
...
...
@@ -477,6 +488,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if
(
tb
[
RTA_FLOW
]
&&
filter
.
realmmask
!=
~
0U
)
{
__u32
to
=
rta_getattr_u32
(
tb
[
RTA_FLOW
]);
__u32
from
=
to
>>
16
;
to
&=
0xFFFF
;
fprintf
(
fp
,
"realm%s "
,
from
?
"s"
:
""
);
if
(
from
)
{
...
...
@@ -492,7 +504,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf
(
fp
,
"%s cache "
,
_SL_
);
#define PRTFL(fl,flname) if (flags&RTCF_##fl) { \
#define PRTFL(fl,
flname) if (flags&RTCF_##fl) { \
flags &= ~RTCF_##fl; \
fprintf(fp, "%s" flname "%s", first ? "<" : "", flags ? "," : "> "); \
first = 0; }
...
...
@@ -515,6 +527,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf
(
fp
,
"%s%x> "
,
first
?
"<"
:
""
,
flags
);
if
(
tb
[
RTA_CACHEINFO
])
{
struct
rta_cacheinfo
*
ci
=
RTA_DATA
(
tb
[
RTA_CACHEINFO
]);
if
(
!
hz
)
hz
=
get_user_hz
();
if
(
ci
->
rta_expires
!=
0
)
...
...
@@ -537,6 +550,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
}
else
if
(
r
->
rtm_family
==
AF_INET6
)
{
struct
rta_cacheinfo
*
ci
=
NULL
;
if
(
tb
[
RTA_CACHEINFO
])
ci
=
RTA_DATA
(
tb
[
RTA_CACHEINFO
]);
if
((
r
->
rtm_flags
&
RTM_F_CLONED
)
||
(
ci
&&
ci
->
rta_expires
))
{
...
...
@@ -563,15 +577,15 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
if
(
tb
[
RTA_METRICS
])
{
int
i
;
unsigned
mxlock
=
0
;
unsigned
int
mxlock
=
0
;
struct
rtattr
*
mxrta
[
RTAX_MAX
+
1
];
parse_rtattr
(
mxrta
,
RTAX_MAX
,
RTA_DATA
(
tb
[
RTA_METRICS
]),
RTA_PAYLOAD
(
tb
[
RTA_METRICS
]));
if
(
mxrta
[
RTAX_LOCK
])
mxlock
=
*
(
unsigned
*
)
RTA_DATA
(
mxrta
[
RTAX_LOCK
]);
mxlock
=
*
(
unsigned
*
)
RTA_DATA
(
mxrta
[
RTAX_LOCK
]);
for
(
i
=
2
;
i
<=
RTAX_MAX
;
i
++
)
{
for
(
i
=
2
;
i
<=
RTAX_MAX
;
i
++
)
{
__u32
val
=
0U
;
if
(
mxrta
[
i
]
==
NULL
)
...
...
@@ -583,7 +597,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if
(
i
==
RTAX_HOPLIMIT
&&
(
int
)
val
==
-
1
)
continue
;
if
(
i
<
sizeof
(
mx_names
)
/
sizeof
(
char
*
)
&&
mx_names
[
i
])
if
(
i
<
sizeof
(
mx_names
)
/
sizeof
(
char
*
)
&&
mx_names
[
i
])
fprintf
(
fp
,
" %s"
,
mx_names
[
i
]);
else
fprintf
(
fp
,
" metric %d"
,
i
);
...
...
@@ -619,7 +633,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
}
if
(
tb
[
RTA_IIF
]
&&
filter
.
iifmask
!=
-
1
)
{
fprintf
(
fp
,
" iif %s"
,
ll_index_to_name
(
*
(
int
*
)
RTA_DATA
(
tb
[
RTA_IIF
])));
fprintf
(
fp
,
" iif %s"
,
ll_index_to_name
(
*
(
int
*
)
RTA_DATA
(
tb
[
RTA_IIF
])));
}
if
(
tb
[
RTA_MULTIPATH
])
{
struct
rtnexthop
*
nh
=
RTA_DATA
(
tb
[
RTA_MULTIPATH
]);
...
...
@@ -663,6 +677,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if
(
tb
[
RTA_VIA
])
{
size_t
len
=
RTA_PAYLOAD
(
tb
[
RTA_VIA
])
-
2
;
struct
rtvia
*
via
=
RTA_DATA
(
tb
[
RTA_VIA
]);
fprintf
(
fp
,
"via %s %s "
,
family_name
(
via
->
rtvia_family
),
format_host
(
via
->
rtvia_family
,
len
,
via
->
rtvia_addr
,
...
...
@@ -671,6 +686,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if
(
tb
[
RTA_FLOW
])
{
__u32
to
=
rta_getattr_u32
(
tb
[
RTA_FLOW
]);
__u32
from
=
to
>>
16
;
to
&=
0xFFFF
;
fprintf
(
fp
,
" realm%s "
,
from
?
"s"
:
""
);
if
(
from
)
{
...
...
@@ -705,6 +721,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
if
(
tb
[
RTA_PREF
])
{
unsigned
int
pref
=
rta_getattr_u8
(
tb
[
RTA_PREF
]);
fprintf
(
fp
,
" pref "
);
switch
(
pref
)
{
...
...
@@ -737,6 +754,7 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
if
(
strcmp
(
*
argv
,
"via"
)
==
0
)
{
inet_prefix
addr
;
int
family
;
NEXT_ARG
();
family
=
read_family
(
*
argv
);
if
(
family
==
AF_UNSPEC
)
...
...
@@ -760,7 +778,8 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
exit
(
1
);
}
}
else
if
(
strcmp
(
*
argv
,
"weight"
)
==
0
)
{
unsigned
w
;
unsigned
int
w
;
NEXT_ARG
();
if
(
get_unsigned
(
&
w
,
*
argv
,
0
)
||
w
==
0
||
w
>
256
)
invarg
(
"
\"
weight
\"
is invalid
\n
"
,
*
argv
);
...
...
@@ -769,6 +788,7 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
rtnh
->
rtnh_flags
|=
RTNH_F_ONLINK
;
}
else
if
(
matches
(
*
argv
,
"realms"
)
==
0
)
{
__u32
realm
;
NEXT_ARG
();
if
(
get_rt_realms_or_raw
(
&
realm
,
*
argv
))
invarg
(
"
\"
realm
\"
value is invalid
\n
"
,
*
argv
);
...
...
@@ -801,7 +821,7 @@ static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r,
int
argc
,
char
**
argv
)
{
char
buf
[
1024
];
struct
rtattr
*
rta
=
(
void
*
)
buf
;
struct
rtattr
*
rta
=
(
void
*
)
buf
;
struct
rtnexthop
*
rtnh
;
rta
->
rta_type
=
RTA_MULTIPATH
;
...
...
@@ -829,16 +849,16 @@ static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r,
return
0
;
}
static
int
iproute_modify
(
int
cmd
,
unsigned
flags
,
int
argc
,
char
**
argv
)
static
int
iproute_modify
(
int
cmd
,
unsigned
int
flags
,
int
argc
,
char
**
argv
)
{
struct
{
struct
nlmsghdr
n
;
struct
rtmsg
r
;
char
buf
[
1024
];
char
buf
[
1024
];
}
req
;
char
mxbuf
[
256
];
struct
rtattr
*
mxrta
=
(
void
*
)
mxbuf
;
unsigned
mxlock
=
0
;
struct
rtattr
*
mxrta
=
(
void
*
)
mxbuf
;
unsigned
int
mxlock
=
0
;
char
*
d
=
NULL
;
int
gw_ok
=
0
;
int
dst_ok
=
0
;
...
...
@@ -870,6 +890,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
while
(
argc
>
0
)
{
if
(
strcmp
(
*
argv
,
"src"
)
==
0
)
{
inet_prefix
addr
;
NEXT_ARG
();
get_addr
(
&
addr
,
*
argv
,
req
.
r
.
rtm_family
);
if
(
req
.
r
.
rtm_family
==
AF_UNSPEC
)
...
...
@@ -877,6 +898,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
addattr_l
(
&
req
.
n
,
sizeof
(
req
),
RTA_PREFSRC
,
&
addr
.
data
,
addr
.
bytelen
);
}
else
if
(
strcmp
(
*
argv
,
"as"
)
==
0
)
{
inet_prefix
addr
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"to"
)
==
0
)
{
NEXT_ARG
();
...
...
@@ -888,6 +910,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
}
else
if
(
strcmp
(
*
argv
,
"via"
)
==
0
)
{
inet_prefix
addr
;
int
family
;
gw_ok
=
1
;
NEXT_ARG
();
family
=
read_family
(
*
argv
);
...
...
@@ -906,6 +929,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
&
addr
.
family
,
addr
.
bytelen
+
2
);
}
else
if
(
strcmp
(
*
argv
,
"from"
)
==
0
)
{
inet_prefix
addr
;
NEXT_ARG
();
get_prefix
(
&
addr
,
*
argv
,
req
.
r
.
rtm_family
);
if
(
req
.
r
.
rtm_family
==
AF_UNSPEC
)
...
...
@@ -916,12 +940,14 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
}
else
if
(
strcmp
(
*
argv
,
"tos"
)
==
0
||
matches
(
*
argv
,
"dsfield"
)
==
0
)
{
__u32
tos
;
NEXT_ARG
();
if
(
rtnl_dsfield_a2n
(
&
tos
,
*
argv
))
invarg
(
"
\"
tos
\"
value is invalid
\n
"
,
*
argv
);
req
.
r
.
rtm_tos
=
tos
;
}
else
if
(
strcmp
(
*
argv
,
"expires"
)
==
0
)
{
}
else
if
(
strcmp
(
*
argv
,
"expires"
)
==
0
)
{
__u32
expires
;
NEXT_ARG
();
if
(
get_u32
(
&
expires
,
*
argv
,
0
))
invarg
(
"
\"
expires
\"
value is invalid
\n
"
,
*
argv
);
...
...
@@ -932,19 +958,22 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
matches
(
*
argv
,
"priority"
)
==
0
||
strcmp
(
*
argv
,
"preference"
)
==
0
)
{
__u32
metric
;
NEXT_ARG
();
if
(
get_u32
(
&
metric
,
*
argv
,
0
))
invarg
(
"
\"
metric
\"
value is invalid
\n
"
,
*
argv
);
addattr32
(
&
req
.
n
,
sizeof
(
req
),
RTA_PRIORITY
,
metric
);
}
else
if
(
strcmp
(
*
argv
,
"scope"
)
==
0
)
{
__u32
scope
=
0
;
NEXT_ARG
();
if
(
rtnl_rtscope_a2n
(
&
scope
,
*
argv
))
invarg
(
"invalid
\"
scope
\"
value
\n
"
,
*
argv
);
req
.
r
.
rtm_scope
=
scope
;
scope_ok
=
1
;
}
else
if
(
strcmp
(
*
argv
,
"mtu"
)
==
0
)
{
unsigned
mtu
;
unsigned
int
mtu
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"lock"
)
==
0
)
{
mxlock
|=
(
1
<<
RTAX_MTU
);
...
...
@@ -954,7 +983,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg
(
"
\"
mtu
\"
value is invalid
\n
"
,
*
argv
);
rta_addattr32
(
mxrta
,
sizeof
(
mxbuf
),
RTAX_MTU
,
mtu
);
}
else
if
(
strcmp
(
*
argv
,
"hoplimit"
)
==
0
)
{
unsigned
hoplimit
;
unsigned
int
hoplimit
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"lock"
)
==
0
)
{
mxlock
|=
(
1
<<
RTAX_HOPLIMIT
);
...
...
@@ -964,7 +994,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg
(
"
\"
hoplimit
\"
value is invalid
\n
"
,
*
argv
);
rta_addattr32
(
mxrta
,
sizeof
(
mxbuf
),
RTAX_HOPLIMIT
,
hoplimit
);
}
else
if
(
strcmp
(
*
argv
,
"advmss"
)
==
0
)
{
unsigned
mss
;
unsigned
int
mss
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"lock"
)
==
0
)
{
mxlock
|=
(
1
<<
RTAX_ADVMSS
);
...
...
@@ -974,7 +1005,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg
(
"
\"
mss
\"
value is invalid
\n
"
,
*
argv
);
rta_addattr32
(
mxrta
,
sizeof
(
mxbuf
),
RTAX_ADVMSS
,
mss
);
}
else
if
(
matches
(
*
argv
,
"reordering"
)
==
0
)
{
unsigned
reord
;
unsigned
int
reord
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"lock"
)
==
0
)
{
mxlock
|=
(
1
<<
RTAX_REORDERING
);
...
...
@@ -984,7 +1016,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg
(
"
\"
reordering
\"
value is invalid
\n
"
,
*
argv
);
rta_addattr32
(
mxrta
,
sizeof
(
mxbuf
),
RTAX_REORDERING
,
reord
);
}
else
if
(
strcmp
(
*
argv
,
"rtt"
)
==
0
)
{
unsigned
rtt
;
unsigned
int
rtt
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"lock"
)
==
0
)
{
mxlock
|=
(
1
<<
RTAX_RTT
);
...
...
@@ -995,7 +1028,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32
(
mxrta
,
sizeof
(
mxbuf
),
RTAX_RTT
,
(
raw
)
?
rtt
:
rtt
*
8
);
}
else
if
(
strcmp
(
*
argv
,
"rto_min"
)
==
0
)
{
unsigned
rto_min
;
unsigned
int
rto_min
;
NEXT_ARG
();
mxlock
|=
(
1
<<
RTAX_RTO_MIN
);
if
(
get_time_rtt
(
&
rto_min
,
*
argv
,
&
raw
))
...
...
@@ -1004,7 +1038,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32
(
mxrta
,
sizeof
(
mxbuf
),
RTAX_RTO_MIN
,
rto_min
);
}
else
if
(
matches
(
*
argv
,
"window"
)
==
0
)
{
unsigned
win
;
unsigned
int
win
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"lock"
)
==
0
)
{
mxlock
|=
(
1
<<
RTAX_WINDOW
);
...
...
@@ -1014,7 +1049,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg
(
"
\"
window
\"
value is invalid
\n
"
,
*
argv
);
rta_addattr32
(
mxrta
,
sizeof
(
mxbuf
),
RTAX_WINDOW
,
win
);
}
else
if
(
matches
(
*
argv
,
"cwnd"
)
==
0
)
{
unsigned
win
;
unsigned
int
win
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"lock"
)
==
0
)
{
mxlock
|=
(
1
<<
RTAX_CWND
);
...
...
@@ -1024,7 +1060,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg
(
"
\"
cwnd
\"
value is invalid
\n
"
,
*
argv
);
rta_addattr32
(
mxrta
,
sizeof
(
mxbuf
),
RTAX_CWND
,
win
);
}
else
if
(
matches
(
*
argv
,
"initcwnd"
)
==
0
)
{
unsigned
win
;
unsigned
int
win
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"lock"
)
==
0
)
{
mxlock
|=
(
1
<<
RTAX_INITCWND
);
...
...
@@ -1034,7 +1071,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
invarg
(
"
\"
initcwnd
\"
value is invalid
\n
"
,
*
argv
);
rta_addattr32
(
mxrta
,
sizeof
(
mxbuf
),
RTAX_INITCWND
,
win
);
}
else
if
(
matches
(
*
argv
,
"initrwnd"
)
==
0
)
{
unsigned
win
;
unsigned
int
win
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"lock"
)
==
0
)
{
mxlock
|=
(
1
<<
RTAX_INITRWND
);
...
...
@@ -1058,7 +1096,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32
(
mxrta
,
sizeof
(
mxbuf
),
RTAX_FEATURES
,
features
);
}
else
if
(
matches
(
*
argv
,
"quickack"
)
==
0
)
{
unsigned
quickack
;
unsigned
int
quickack
;
NEXT_ARG
();
if
(
get_unsigned
(
&
quickack
,
*
argv
,
0
))
invarg
(
"
\"
quickack
\"
value is invalid
\n
"
,
*
argv
);
...
...
@@ -1074,7 +1113,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr_l
(
mxrta
,
sizeof
(
mxbuf
),
RTAX_CC_ALGO
,
*
argv
,
strlen
(
*
argv
));
}
else
if
(
matches
(
*
argv
,
"rttvar"
)
==
0
)
{
unsigned
win
;
unsigned
int
win
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"lock"
)
==
0
)
{
mxlock
|=
(
1
<<
RTAX_RTTVAR
);
...
...
@@ -1085,7 +1125,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32
(
mxrta
,
sizeof
(
mxbuf
),
RTAX_RTTVAR
,
(
raw
)
?
win
:
win
*
4
);
}
else
if
(
matches
(
*
argv
,
"ssthresh"
)
==
0
)
{
unsigned
win
;
unsigned
int
win
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"lock"
)
==
0
)
{
mxlock
|=
(
1
<<
RTAX_SSTHRESH
);
...
...
@@ -1096,6 +1137,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
rta_addattr32
(
mxrta
,
sizeof
(
mxbuf
),
RTAX_SSTHRESH
,
win
);
}
else
if
(
matches
(
*
argv
,
"realms"
)
==
0
)
{
__u32
realm
;
NEXT_ARG
();
if
(
get_rt_realms_or_raw
(
&
realm
,
*
argv
))
invarg
(
"
\"
realm
\"
value is invalid
\n
"
,
*
argv
);
...
...
@@ -1107,12 +1149,14 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
break
;
}
else
if
(
matches
(
*
argv
,
"protocol"
)
==
0
)
{
__u32
prot
;
NEXT_ARG
();
if
(
rtnl_rtprot_a2n
(
&
prot
,
*
argv
))
invarg
(
"
\"
protocol
\"
value is invalid
\n
"
,
*
argv
);
req
.
r
.
rtm_protocol
=
prot
;
}
else
if
(
matches
(
*
argv
,
"table"
)
==
0
)
{
__u32
tid
;
NEXT_ARG
();
if
(
rtnl_rttable_a2n
(
&
tid
,
*
argv
))
invarg
(
"
\"
table
\"
value is invalid
\n
"
,
*
argv
);
...
...
@@ -1129,6 +1173,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
d
=
*
argv
;
}
else
if
(
matches
(
*
argv
,
"pref"
)
==
0
)
{
__u8
pref
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"low"
)
==
0
)
pref
=
ICMPV6_ROUTER_PREF_LOW
;
...
...
@@ -1141,7 +1186,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
addattr8
(
&
req
.
n
,
sizeof
(
req
),
RTA_PREF
,
pref
);
}
else
if
(
strcmp
(
*
argv
,
"encap"
)
==
0
)
{
char
buf
[
1024
];
struct
rtattr
*
rta
=
(
void
*
)
buf
;
struct
rtattr
*
rta
=
(
void
*
)
buf
;
rta
->
rta_type
=
RTA_ENCAP
;
rta
->
rta_len
=
RTA_LENGTH
(
0
);
...
...
@@ -1262,7 +1307,7 @@ static int rtnl_rtcache_request(struct rtnl_handle *rth, int family)
req
.
rtm
.
rtm_family
=
family
;
req
.
rtm
.
rtm_flags
|=
RTM_F_CLONED
;
return
sendto
(
rth
->
fd
,
(
void
*
)
&
req
,
sizeof
(
req
),
0
,
(
struct
sockaddr
*
)
&
nladdr
,
sizeof
(
nladdr
));
return
sendto
(
rth
->
fd
,
(
void
*
)
&
req
,
sizeof
(
req
),
0
,
(
struct
sockaddr
*
)
&
nladdr
,
sizeof
(
nladdr
));
}
static
int
iproute_flush_cache
(
void
)
...
...
@@ -1270,19 +1315,19 @@ static int iproute_flush_cache(void)
#define ROUTE_FLUSH_PATH "/proc/sys/net/ipv4/route/flush"
int
len
;
int
flush_fd
=
open
(
ROUTE_FLUSH_PATH
,
O_WRONLY
);
int
flush_fd
=
open
(
ROUTE_FLUSH_PATH
,
O_WRONLY
);
char
*
buffer
=
"-1"
;
if
(
flush_fd
<
0
)
{
fprintf
(
stderr
,
"Cannot open
\"
%s
\"
: %s
\n
"
,
fprintf
(
stderr
,
"Cannot open
\"
%s
\"
: %s
\n
"
,
ROUTE_FLUSH_PATH
,
strerror
(
errno
));
return
-
1
;
}
len
=
strlen
(
buffer
);
len
=
strlen
(
buffer
);
if
((
write
(
flush_fd
,
(
void
*
)
buffer
,
len
))
<
len
)
{
fprintf
(
stderr
,
"Cannot flush routing cache
\n
"
);
if
((
write
(
flush_fd
,
(
void
*
)
buffer
,
len
))
<
len
)
{
fprintf
(
stderr
,
"Cannot flush routing cache
\n
"
);
close
(
flush_fd
);
return
-
1
;
}
...
...
@@ -1362,6 +1407,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
while
(
argc
>
0
)
{
if
(
matches
(
*
argv
,
"table"
)
==
0
)
{
__u32
tid
;
NEXT_ARG
();
if
(
rtnl_rttable_a2n
(
&
tid
,
*
argv
))
{
if
(
strcmp
(
*
argv
,
"all"
)
==
0
)
{
...
...
@@ -1381,6 +1427,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
}
else
if
(
strcmp
(
*
argv
,
"tos"
)
==
0
||
matches
(
*
argv
,
"dsfield"
)
==
0
)
{
__u32
tos
;
NEXT_ARG
();
if
(
rtnl_dsfield_a2n
(
&
tos
,
*
argv
))
invarg
(
"TOS value is invalid
\n
"
,
*
argv
);
...
...
@@ -1388,6 +1435,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
filter
.
tosmask
=
-
1
;
}
else
if
(
matches
(
*
argv
,
"protocol"
)
==
0
)
{
__u32
prot
=
0
;
NEXT_ARG
();
filter
.
protocolmask
=
-
1
;
if
(
rtnl_rtprot_a2n
(
&
prot
,
*
argv
))
{
...
...
@@ -1399,6 +1447,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
filter
.
protocol
=
prot
;
}
else
if
(
matches
(
*
argv
,
"scope"
)
==
0
)
{
__u32
scope
=
0
;
NEXT_ARG
();
filter
.
scopemask
=
-
1
;
if
(
rtnl_rtscope_a2n
(
&
scope
,
*
argv
))
{
...
...
@@ -1410,6 +1459,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
filter
.
scope
=
scope
;
}
else
if
(
matches
(
*
argv
,
"type"
)
==
0
)
{
int
type
;
NEXT_ARG
();
filter
.
typemask
=
-
1
;
if
(
rtnl_rtntype_a2n
(
&
type
,
*
argv
))
...
...
@@ -1428,6 +1478,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
filter
.
markmask
=
-
1
;
}
else
if
(
strcmp
(
*
argv
,
"via"
)
==
0
)
{
int
family
;
NEXT_ARG
();
family
=
read_family
(
*
argv
);
if
(
family
==
AF_UNSPEC
)
...
...
@@ -1440,6 +1491,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
get_prefix
(
&
filter
.
rprefsrc
,
*
argv
,
do_ipv6
);
}
else
if
(
matches
(
*
argv
,
"realms"
)
==
0
)
{
__u32
realm
;
NEXT_ARG
();
if
(
get_rt_realms_or_raw
(
&
realm
,
*
argv
))
invarg
(
"invalid realms
\n
"
,
*
argv
);
...
...
@@ -1547,7 +1599,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
if
(
round
==
0
&&
(
!
filter
.
cloned
||
do_ipv6
==
AF_INET6
))
printf
(
"Nothing to flush.
\n
"
);
else
printf
(
"*** Flush is complete after %d round%s ***
\n
"
,
round
,
round
>
1
?
"s"
:
""
);
printf
(
"*** Flush is complete after %d round%s ***
\n
"
,
round
,
round
>
1
?
"s"
:
""
);
}
fflush
(
stdout
);
return
0
;
...
...
@@ -1595,7 +1647,7 @@ static int iproute_get(int argc, char **argv)
struct
{
struct
nlmsghdr
n
;
struct
rtmsg
r
;
char
buf
[
1024
];
char
buf
[
1024
];
}
req
;
char
*
idev
=
NULL
;
char
*
odev
=
NULL
;
...
...
@@ -1624,12 +1676,14 @@ static int iproute_get(int argc, char **argv)
if
(
strcmp
(
*
argv
,
"tos"
)
==
0
||
matches
(
*
argv
,
"dsfield"
)
==
0
)
{
__u32
tos
;
NEXT_ARG
();
if
(
rtnl_dsfield_a2n
(
&
tos
,
*
argv
))
invarg
(
"TOS value is invalid
\n
"
,
*
argv
);
req
.
r
.
rtm_tos
=
tos
;
}
else
if
(
matches
(
*
argv
,
"from"
)
==
0
)
{
inet_prefix
addr
;
NEXT_ARG
();
if
(
matches
(
*
argv
,
"help"
)
==
0
)
usage
();
...
...
@@ -1656,6 +1710,7 @@ static int iproute_get(int argc, char **argv)
connected
=
1
;
}
else
{
inet_prefix
addr
;
if
(
strcmp
(
*
argv
,
"to"
)
==
0
)
{
NEXT_ARG
();
}
...
...
@@ -1708,9 +1763,9 @@ static int iproute_get(int argc, char **argv)
if
(
connected
&&
!
from_ok
)
{
struct
rtmsg
*
r
=
NLMSG_DATA
(
&
req
.
n
);
int
len
=
req
.
n
.
nlmsg_len
;
struct
rtattr
*
tb
[
RTA_MAX
+
1
];
struct
rtattr
*
tb
[
RTA_MAX
+
1
];
if
(
print_route
(
NULL
,
&
req
.
n
,
(
void
*
)
stdout
)
<
0
)
{
if
(
print_route
(
NULL
,
&
req
.
n
,
(
void
*
)
stdout
)
<
0
)
{
fprintf
(
stderr
,
"An error :-)
\n
"
);
exit
(
1
);
}
...
...
@@ -1749,7 +1804,7 @@ static int iproute_get(int argc, char **argv)
return
-
2
;
}
if
(
print_route
(
NULL
,
&
req
.
n
,
(
void
*
)
stdout
)
<
0
)
{
if
(
print_route
(
NULL
,
&
req
.
n
,
(
void
*
)
stdout
)
<
0
)
{
fprintf
(
stderr
,
"An error :-)
\n
"
);
return
-
1
;
}
...
...
ip/iproute_lwtunnel.c
View file @
56f5daac
...
...
@@ -7,7 +7,7 @@
* 2 of the License, or (at your option) any later version.
*
* Authors: Roopa Prabhu, <roopa@cumulusnetworks.com>
*
Thomas Graf <tgraf@suug.ch>
* Thomas Graf <tgraf@suug.ch>
*
*/
...
...
@@ -203,6 +203,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***ar
while
(
argc
>
0
)
{
if
(
strcmp
(
*
argv
,
"id"
)
==
0
)
{
__u64
id
;
NEXT_ARG
();
if
(
id_ok
++
)
duparg2
(
"id"
,
*
argv
);
...
...
@@ -211,6 +212,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***ar
rta_addattr64
(
rta
,
len
,
LWTUNNEL_IP_ID
,
htonll
(
id
));
}
else
if
(
strcmp
(
*
argv
,
"dst"
)
==
0
)
{
inet_prefix
addr
;
NEXT_ARG
();
if
(
dst_ok
++
)
duparg2
(
"dst"
,
*
argv
);
...
...
@@ -218,6 +220,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***ar
rta_addattr_l
(
rta
,
len
,
LWTUNNEL_IP_DST
,
&
addr
.
data
,
addr
.
bytelen
);
}
else
if
(
strcmp
(
*
argv
,
"tos"
)
==
0
)
{
__u32
tos
;
NEXT_ARG
();
if
(
tos_ok
++
)
duparg2
(
"tos"
,
*
argv
);
...
...
@@ -226,6 +229,7 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, int *argcp, char ***ar
rta_addattr8
(
rta
,
len
,
LWTUNNEL_IP_TOS
,
tos
);
}
else
if
(
strcmp
(
*
argv
,
"ttl"
)
==
0
)
{
__u8
ttl
;
NEXT_ARG
();
if
(
ttl_ok
++
)
duparg2
(
"ttl"
,
*
argv
);
...
...
@@ -276,6 +280,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***a
while
(
argc
>
0
)
{
if
(
strcmp
(
*
argv
,
"id"
)
==
0
)
{
__u64
id
;
NEXT_ARG
();
if
(
id_ok
++
)
duparg2
(
"id"
,
*
argv
);
...
...
@@ -284,6 +289,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***a
rta_addattr64
(
rta
,
len
,
LWTUNNEL_IP6_ID
,
htonll
(
id
));
}
else
if
(
strcmp
(
*
argv
,
"dst"
)
==
0
)
{
inet_prefix
addr
;
NEXT_ARG
();
if
(
dst_ok
++
)
duparg2
(
"dst"
,
*
argv
);
...
...
@@ -291,6 +297,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***a
rta_addattr_l
(
rta
,
len
,
LWTUNNEL_IP6_DST
,
&
addr
.
data
,
addr
.
bytelen
);
}
else
if
(
strcmp
(
*
argv
,
"tc"
)
==
0
)
{
__u32
tc
;
NEXT_ARG
();
if
(
tos_ok
++
)
duparg2
(
"tc"
,
*
argv
);
...
...
@@ -299,6 +306,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***a
rta_addattr8
(
rta
,
len
,
LWTUNNEL_IP6_TC
,
tc
);
}
else
if
(
strcmp
(
*
argv
,
"hoplimit"
)
==
0
)
{
__u8
hoplimit
;
NEXT_ARG
();
if
(
ttl_ok
++
)
duparg2
(
"hoplimit"
,
*
argv
);
...
...
ip/iprule.c
View file @
56f5daac
...
...
@@ -51,13 +51,14 @@ static void usage(void)
int
print_rule
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
rtmsg
*
r
=
NLMSG_DATA
(
n
);
int
len
=
n
->
nlmsg_len
;
int
host_len
=
-
1
;
__u32
table
;
struct
rtattr
*
tb
[
FRA_MAX
+
1
];
struct
rtattr
*
tb
[
FRA_MAX
+
1
];
char
abuf
[
256
];
SPRINT_BUF
(
b1
);
if
(
n
->
nlmsg_type
!=
RTM_NEWRULE
&&
n
->
nlmsg_type
!=
RTM_DELRULE
)
...
...
@@ -75,7 +76,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf
(
fp
,
"Deleted "
);
if
(
tb
[
FRA_PRIORITY
])
fprintf
(
fp
,
"%u:
\t
"
,
*
(
unsigned
*
)
RTA_DATA
(
tb
[
FRA_PRIORITY
]));
fprintf
(
fp
,
"%u:
\t
"
,
*
(
unsigned
*
)
RTA_DATA
(
tb
[
FRA_PRIORITY
]));
else
fprintf
(
fp
,
"0:
\t
"
);
...
...
@@ -157,12 +158,14 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if
(
tb
[
FRA_SUPPRESS_PREFIXLEN
])
{
int
pl
=
rta_getattr_u32
(
tb
[
FRA_SUPPRESS_PREFIXLEN
]);
if
(
pl
!=
-
1
)
{
fprintf
(
fp
,
"suppress_prefixlength %d "
,
pl
);
}
}
if
(
tb
[
FRA_SUPPRESS_IFGROUP
])
{
int
group
=
rta_getattr_u32
(
tb
[
FRA_SUPPRESS_IFGROUP
]);
if
(
group
!=
-
1
)
{
SPRINT_BUF
(
b1
);
fprintf
(
fp
,
"suppress_ifgroup %s "
,
rtnl_group_n2a
(
group
,
b1
,
sizeof
(
b1
)));
...
...
@@ -173,6 +176,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if
(
tb
[
FRA_FLOW
])
{
__u32
to
=
rta_getattr_u32
(
tb
[
FRA_FLOW
]);
__u32
from
=
to
>>
16
;
to
&=
0xFFFF
;
if
(
from
)
{
fprintf
(
fp
,
"realms %s/"
,
...
...
@@ -326,7 +330,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
struct
{
struct
nlmsghdr
n
;
struct
rtmsg
r
;
char
buf
[
1024
];
char
buf
[
1024
];
}
req
;
memset
(
&
req
,
0
,
sizeof
(
req
));
...
...
@@ -351,12 +355,14 @@ static int iprule_modify(int cmd, int argc, char **argv)
req
.
r
.
rtm_flags
|=
FIB_RULE_INVERT
;
}
else
if
(
strcmp
(
*
argv
,
"from"
)
==
0
)
{
inet_prefix
dst
;
NEXT_ARG
();
get_prefix
(
&
dst
,
*
argv
,
req
.
r
.
rtm_family
);
req
.
r
.
rtm_src_len
=
dst
.
bitlen
;
addattr_l
(
&
req
.
n
,
sizeof
(
req
),
FRA_SRC
,
&
dst
.
data
,
dst
.
bytelen
);
}
else
if
(
strcmp
(
*
argv
,
"to"
)
==
0
)
{
inet_prefix
dst
;
NEXT_ARG
();
get_prefix
(
&
dst
,
*
argv
,
req
.
r
.
rtm_family
);
req
.
r
.
rtm_dst_len
=
dst
.
bitlen
;
...
...
@@ -365,6 +371,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
matches
(
*
argv
,
"order"
)
==
0
||
matches
(
*
argv
,
"priority"
)
==
0
)
{
__u32
pref
;
NEXT_ARG
();
if
(
get_u32
(
&
pref
,
*
argv
,
0
))
invarg
(
"preference value is invalid
\n
"
,
*
argv
);
...
...
@@ -372,6 +379,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
}
else
if
(
strcmp
(
*
argv
,
"tos"
)
==
0
||
matches
(
*
argv
,
"dsfield"
)
==
0
)
{
__u32
tos
;
NEXT_ARG
();
if
(
rtnl_dsfield_a2n
(
&
tos
,
*
argv
))
invarg
(
"TOS value is invalid
\n
"
,
*
argv
);
...
...
@@ -379,6 +387,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
}
else
if
(
strcmp
(
*
argv
,
"fwmark"
)
==
0
)
{
char
*
slash
;
__u32
fwmark
,
fwmask
;
NEXT_ARG
();
if
((
slash
=
strchr
(
*
argv
,
'/'
))
!=
NULL
)
*
slash
=
'\0'
;
...
...
@@ -392,6 +401,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
}
}
else
if
(
matches
(
*
argv
,
"realms"
)
==
0
)
{
__u32
realm
;
NEXT_ARG
();
if
(
get_rt_realms_or_raw
(
&
realm
,
*
argv
))
invarg
(
"invalid realms
\n
"
,
*
argv
);
...
...
@@ -399,6 +409,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
}
else
if
(
matches
(
*
argv
,
"table"
)
==
0
||
strcmp
(
*
argv
,
"lookup"
)
==
0
)
{
__u32
tid
;
NEXT_ARG
();
if
(
rtnl_rttable_a2n
(
&
tid
,
*
argv
))
invarg
(
"invalid table ID
\n
"
,
*
argv
);
...
...
@@ -412,6 +423,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
}
else
if
(
matches
(
*
argv
,
"suppress_prefixlength"
)
==
0
||
strcmp
(
*
argv
,
"sup_pl"
)
==
0
)
{
int
pl
;
NEXT_ARG
();
if
(
get_s32
(
&
pl
,
*
argv
,
0
)
||
pl
<
0
)
invarg
(
"suppress_prefixlength value is invalid
\n
"
,
*
argv
);
...
...
@@ -420,6 +432,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
strcmp
(
*
argv
,
"sup_group"
)
==
0
)
{
NEXT_ARG
();
int
group
;
if
(
rtnl_group_a2n
(
&
group
,
*
argv
))
invarg
(
"Invalid
\"
suppress_ifgroup
\"
value
\n
"
,
*
argv
);
addattr32
(
&
req
.
n
,
sizeof
(
req
),
FRA_SUPPRESS_IFGROUP
,
group
);
...
...
@@ -446,6 +459,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
usage
();
else
if
(
matches
(
*
argv
,
"goto"
)
==
0
)
{
__u32
target
;
type
=
FR_ACT_GOTO
;
NEXT_ARG
();
if
(
get_u32
(
&
target
,
*
argv
,
0
))
...
...
@@ -480,7 +494,7 @@ static int flush_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *a
struct
rtnl_handle
rth2
;
struct
rtmsg
*
r
=
NLMSG_DATA
(
n
);
int
len
=
n
->
nlmsg_len
;
struct
rtattr
*
tb
[
FRA_MAX
+
1
];
struct
rtattr
*
tb
[
FRA_MAX
+
1
];
len
-=
NLMSG_LENGTH
(
sizeof
(
*
r
));
if
(
len
<
0
)
...
...
ip/iptoken.c
View file @
56f5daac
...
...
@@ -168,13 +168,11 @@ static int iptoken_set(int argc, char **argv)
}
if
(
!
have_token
)
{
fprintf
(
stderr
,
"Not enough information: token "
"is required.
\n
"
);
fprintf
(
stderr
,
"Not enough information: token is required.
\n
"
);
return
-
1
;
}
if
(
!
have_dev
)
{
fprintf
(
stderr
,
"Not enough information:
\"
dev
\"
"
"argument is required.
\n
"
);
fprintf
(
stderr
,
"Not enough information:
\"
dev
\"
argument is required.
\n
"
);
return
-
1
;
}
...
...
ip/iptuntap.c
View file @
56f5daac
...
...
@@ -36,7 +36,7 @@ static void usage(void) __attribute__((noreturn));
static
void
usage
(
void
)
{
fprintf
(
stderr
,
"Usage: ip tuntap { add | del | show | list | lst | help } [ dev PHYS_DEV ]
\n
"
);
fprintf
(
stderr
,
"Usage: ip tuntap { add | del | show | list | lst | help } [ dev PHYS_DEV ]
\n
"
);
fprintf
(
stderr
,
" [ mode { tun | tap } ] [ user USER ] [ group GROUP ]
\n
"
);
fprintf
(
stderr
,
" [ one_queue ] [ pi ] [ vnet_hdr ] [ multi_queue ]
\n
"
);
fprintf
(
stderr
,
"
\n
"
);
...
...
@@ -117,18 +117,18 @@ static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_
NEXT_ARG
();
if
(
matches
(
*
argv
,
"tun"
)
==
0
)
{
if
(
ifr
->
ifr_flags
&
IFF_TAP
)
{
fprintf
(
stderr
,
"You managed to ask for more than one tunnel mode.
\n
"
);
fprintf
(
stderr
,
"You managed to ask for more than one tunnel mode.
\n
"
);
exit
(
-
1
);
}
ifr
->
ifr_flags
|=
IFF_TUN
;
}
else
if
(
matches
(
*
argv
,
"tap"
)
==
0
)
{
if
(
ifr
->
ifr_flags
&
IFF_TUN
)
{
fprintf
(
stderr
,
"You managed to ask for more than one tunnel mode.
\n
"
);
fprintf
(
stderr
,
"You managed to ask for more than one tunnel mode.
\n
"
);
exit
(
-
1
);
}
ifr
->
ifr_flags
|=
IFF_TAP
;
}
else
{
fprintf
(
stderr
,
"Unknown tunnel mode
\"
%s
\"\n
"
,
*
argv
);
fprintf
(
stderr
,
"Unknown tunnel mode
\"
%s
\"\n
"
,
*
argv
);
exit
(
-
1
);
}
}
else
if
(
uid
&&
matches
(
*
argv
,
"user"
)
==
0
)
{
...
...
@@ -140,6 +140,7 @@ static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_
*
uid
=
user
;
else
{
struct
passwd
*
pw
=
getpwnam
(
*
argv
);
if
(
!
pw
)
{
fprintf
(
stderr
,
"invalid user
\"
%s
\"\n
"
,
*
argv
);
exit
(
-
1
);
...
...
@@ -156,6 +157,7 @@ static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_
*
gid
=
group
;
else
{
struct
group
*
gr
=
getgrnam
(
*
argv
);
if
(
!
gr
)
{
fprintf
(
stderr
,
"invalid group
\"
%s
\"\n
"
,
*
argv
);
exit
(
-
1
);
...
...
@@ -313,9 +315,9 @@ int do_iptuntap(int argc, char **argv)
if
(
matches
(
*
argv
,
"delete"
)
==
0
)
return
do_del
(
argc
-
1
,
argv
+
1
);
if
(
matches
(
*
argv
,
"show"
)
==
0
||
matches
(
*
argv
,
"lst"
)
==
0
||
matches
(
*
argv
,
"list"
)
==
0
)
return
do_show
(
argc
-
1
,
argv
+
1
);
matches
(
*
argv
,
"lst"
)
==
0
||
matches
(
*
argv
,
"list"
)
==
0
)
return
do_show
(
argc
-
1
,
argv
+
1
);
if
(
matches
(
*
argv
,
"help"
)
==
0
)
usage
();
}
else
...
...
ip/ipxfrm.c
View file @
56f5daac
...
...
@@ -50,7 +50,7 @@
strncat(buf, str, len); \
buf[sizeof(buf) - 1] = '\0'; \
} \
} while(0);
} while
(0);
struct
xfrm_filter
filter
;
...
...
@@ -111,7 +111,7 @@ struct typeent {
int
t_type
;
};
static
const
struct
typeent
xfrmproto_types
[]
=
{
static
const
struct
typeent
xfrmproto_types
[]
=
{
{
"esp"
,
IPPROTO_ESP
},
{
"ah"
,
IPPROTO_AH
},
{
"comp"
,
IPPROTO_COMP
},
{
"route2"
,
IPPROTO_ROUTING
},
{
"hao"
,
IPPROTO_DSTOPTS
},
{
"ipsec-any"
,
IPSEC_PROTO_ANY
},
...
...
@@ -124,6 +124,7 @@ int xfrm_xfrmproto_getbyname(char *name)
for
(
i
=
0
;
;
i
++
)
{
const
struct
typeent
*
t
=
&
xfrmproto_types
[
i
];
if
(
!
t
->
t_name
||
t
->
t_type
==
-
1
)
break
;
...
...
@@ -141,6 +142,7 @@ const char *strxf_xfrmproto(__u8 proto)
for
(
i
=
0
;
;
i
++
)
{
const
struct
typeent
*
t
=
&
xfrmproto_types
[
i
];
if
(
!
t
->
t_name
||
t
->
t_type
==
-
1
)
break
;
...
...
@@ -152,7 +154,7 @@ const char *strxf_xfrmproto(__u8 proto)
return
str
;
}
static
const
struct
typeent
algo_types
[]
=
{
static
const
struct
typeent
algo_types
[]
=
{
{
"enc"
,
XFRMA_ALG_CRYPT
},
{
"auth"
,
XFRMA_ALG_AUTH
},
{
"comp"
,
XFRMA_ALG_COMP
},
{
"aead"
,
XFRMA_ALG_AEAD
},
{
"auth-trunc"
,
XFRMA_ALG_AUTH_TRUNC
},
...
...
@@ -165,6 +167,7 @@ int xfrm_algotype_getbyname(char *name)
for
(
i
=
0
;
;
i
++
)
{
const
struct
typeent
*
t
=
&
algo_types
[
i
];
if
(
!
t
->
t_name
||
t
->
t_type
==
-
1
)
break
;
...
...
@@ -182,6 +185,7 @@ const char *strxf_algotype(int type)
for
(
i
=
0
;
;
i
++
)
{
const
struct
typeent
*
t
=
&
algo_types
[
i
];
if
(
!
t
->
t_name
||
t
->
t_type
==
-
1
)
break
;
...
...
@@ -302,6 +306,7 @@ void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
if
(
show_stats
>
0
||
force_spi
||
id
->
spi
)
{
__u32
spi
=
ntohl
(
id
->
spi
);
fprintf
(
fp
,
"spi 0x%08x"
,
spi
);
if
(
show_stats
>
0
)
fprintf
(
fp
,
"(%u)"
,
spi
);
...
...
@@ -340,6 +345,7 @@ void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
static
const
char
*
strxf_limit
(
__u64
limit
)
{
static
char
str
[
32
];
if
(
limit
==
XFRM_INF
)
strcpy
(
str
,
"(INF)"
);
else
...
...
@@ -389,7 +395,7 @@ void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
if
(
cfg
)
{
if
(
prefix
)
fputs
(
prefix
,
fp
);
fprintf
(
fp
,
"lifetime config:%s"
,
_SL_
);
fprintf
(
fp
,
"lifetime config:%s"
,
_SL_
);
if
(
prefix
)
fputs
(
prefix
,
fp
);
...
...
@@ -538,7 +544,7 @@ static void __xfrm_algo_print(struct xfrm_algo *algo, int type, int len,
if
(
keylen
>
0
)
{
fprintf
(
fp
,
"0x"
);
for
(
i
=
0
;
i
<
keylen
;
i
++
)
for
(
i
=
0
;
i
<
keylen
;
i
++
)
fprintf
(
fp
,
"%.2x"
,
(
unsigned
char
)
algo
->
alg_key
[
i
]);
if
(
show_stats
>
0
)
...
...
@@ -692,36 +698,42 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
if
(
tb
[
XFRMA_MARK
])
{
struct
rtattr
*
rta
=
tb
[
XFRMA_MARK
];
struct
xfrm_mark
*
m
=
(
struct
xfrm_mark
*
)
RTA_DATA
(
rta
);
fprintf
(
fp
,
"
\t
mark %#x/%#x"
,
m
->
v
,
m
->
m
);
fprintf
(
fp
,
"%s"
,
_SL_
);
}
if
(
tb
[
XFRMA_ALG_AUTH
]
&&
!
tb
[
XFRMA_ALG_AUTH_TRUNC
])
{
struct
rtattr
*
rta
=
tb
[
XFRMA_ALG_AUTH
];
xfrm_algo_print
((
struct
xfrm_algo
*
)
RTA_DATA
(
rta
),
XFRMA_ALG_AUTH
,
RTA_PAYLOAD
(
rta
),
fp
,
prefix
);
}
if
(
tb
[
XFRMA_ALG_AUTH_TRUNC
])
{
struct
rtattr
*
rta
=
tb
[
XFRMA_ALG_AUTH_TRUNC
];
xfrm_auth_trunc_print
((
struct
xfrm_algo_auth
*
)
RTA_DATA
(
rta
),
RTA_PAYLOAD
(
rta
),
fp
,
prefix
);
}
if
(
tb
[
XFRMA_ALG_AEAD
])
{
struct
rtattr
*
rta
=
tb
[
XFRMA_ALG_AEAD
];
xfrm_aead_print
((
struct
xfrm_algo_aead
*
)
RTA_DATA
(
rta
),
RTA_PAYLOAD
(
rta
),
fp
,
prefix
);
}
if
(
tb
[
XFRMA_ALG_CRYPT
])
{
struct
rtattr
*
rta
=
tb
[
XFRMA_ALG_CRYPT
];
xfrm_algo_print
((
struct
xfrm_algo
*
)
RTA_DATA
(
rta
),
XFRMA_ALG_CRYPT
,
RTA_PAYLOAD
(
rta
),
fp
,
prefix
);
}
if
(
tb
[
XFRMA_ALG_COMP
])
{
struct
rtattr
*
rta
=
tb
[
XFRMA_ALG_COMP
];
xfrm_algo_print
((
struct
xfrm_algo
*
)
RTA_DATA
(
rta
),
XFRMA_ALG_COMP
,
RTA_PAYLOAD
(
rta
),
fp
,
prefix
);
}
...
...
@@ -765,6 +777,7 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
if
(
tb
[
XFRMA_TMPL
])
{
struct
rtattr
*
rta
=
tb
[
XFRMA_TMPL
];
xfrm_tmpl_print
((
struct
xfrm_user_tmpl
*
)
RTA_DATA
(
rta
),
RTA_PAYLOAD
(
rta
),
fp
,
prefix
);
}
...
...
@@ -1140,11 +1153,11 @@ int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
if
(
id
->
spi
&&
id
->
proto
)
{
if
(
xfrm_xfrmproto_is_ro
(
id
->
proto
))
{
fprintf
(
stderr
,
"
\"
spi
\"
is invalid with XFRM-PROTO value
\"
%s
\"\n
"
,
strxf_xfrmproto
(
id
->
proto
));
strxf_xfrmproto
(
id
->
proto
));
exit
(
1
);
}
else
if
(
id
->
proto
==
IPPROTO_COMP
&&
ntohl
(
id
->
spi
)
>=
0x10000
)
{
fprintf
(
stderr
,
"SPI value is too large with XFRM-PROTO value
\"
%s
\"\n
"
,
strxf_xfrmproto
(
id
->
proto
));
strxf_xfrmproto
(
id
->
proto
));
exit
(
1
);
}
}
...
...
@@ -1238,6 +1251,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
upspec
=
0
;
else
{
struct
protoent
*
pp
;
pp
=
getprotobyname
(
*
argv
);
if
(
pp
)
upspec
=
pp
->
p_proto
;
...
...
@@ -1304,7 +1318,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
filter
.
upspec_dport_mask
=
XFRM_FILTER_MASK_FULL
;
}
else
if
(
strcmp
(
*
argv
,
"key"
)
==
0
)
{
unsigned
uval
;
unsigned
int
uval
;
grekey
=
*
argv
;
...
...
@@ -1313,7 +1327,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
if
(
strchr
(
*
argv
,
'.'
))
uval
=
htonl
(
get_addr32
(
*
argv
));
else
{
if
(
get_unsigned
(
&
uval
,
*
argv
,
0
)
<
0
)
{
if
(
get_unsigned
(
&
uval
,
*
argv
,
0
)
<
0
)
{
fprintf
(
stderr
,
"value after
\"
key
\"
is invalid
\n
"
);
exit
(
-
1
);
}
...
...
ip/link_gre.c
View file @
56f5daac
...
...
@@ -61,11 +61,11 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
struct
rtattr
*
greinfo
[
IFLA_GRE_MAX
+
1
];
__u16
iflags
=
0
;
__u16
oflags
=
0
;
unsigned
ikey
=
0
;
unsigned
okey
=
0
;
unsigned
saddr
=
0
;
unsigned
daddr
=
0
;
unsigned
link
=
0
;
unsigned
i
nt
i
key
=
0
;
unsigned
int
okey
=
0
;
unsigned
int
saddr
=
0
;
unsigned
int
daddr
=
0
;
unsigned
int
link
=
0
;
__u8
pmtudisc
=
1
;
__u8
ttl
=
0
;
__u8
tos
=
0
;
...
...
@@ -156,7 +156,7 @@ get_failed:
while
(
argc
>
0
)
{
if
(
!
matches
(
*
argv
,
"key"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
iflags
|=
GRE_KEY
;
...
...
@@ -174,14 +174,14 @@ get_failed:
ikey
=
okey
=
uval
;
}
else
if
(
!
matches
(
*
argv
,
"ikey"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
iflags
|=
GRE_KEY
;
if
(
strchr
(
*
argv
,
'.'
))
uval
=
get_addr32
(
*
argv
);
else
{
if
(
get_unsigned
(
&
uval
,
*
argv
,
0
)
<
0
)
{
if
(
get_unsigned
(
&
uval
,
*
argv
,
0
)
<
0
)
{
fprintf
(
stderr
,
"invalid value for
\"
ikey
\"
:
\"
%s
\"
; it should be an unsigned integer
\n
"
,
*
argv
);
exit
(
-
1
);
}
...
...
@@ -189,14 +189,14 @@ get_failed:
}
ikey
=
uval
;
}
else
if
(
!
matches
(
*
argv
,
"okey"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
oflags
|=
GRE_KEY
;
if
(
strchr
(
*
argv
,
'.'
))
uval
=
get_addr32
(
*
argv
);
else
{
if
(
get_unsigned
(
&
uval
,
*
argv
,
0
)
<
0
)
{
if
(
get_unsigned
(
&
uval
,
*
argv
,
0
)
<
0
)
{
fprintf
(
stderr
,
"invalid value for
\"
okey
\"
:
\"
%s
\"
; it should be an unsigned integer
\n
"
,
*
argv
);
exit
(
-
1
);
}
...
...
@@ -239,7 +239,7 @@ get_failed:
}
}
else
if
(
!
matches
(
*
argv
,
"ttl"
)
||
!
matches
(
*
argv
,
"hoplimit"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"inherit"
)
!=
0
)
{
...
...
@@ -343,14 +343,14 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
char
s2
[
64
];
const
char
*
local
=
"any"
;
const
char
*
remote
=
"any"
;
unsigned
iflags
=
0
;
unsigned
oflags
=
0
;
unsigned
i
nt
i
flags
=
0
;
unsigned
int
oflags
=
0
;
if
(
!
tb
)
return
;
if
(
tb
[
IFLA_GRE_REMOTE
])
{
unsigned
addr
=
rta_getattr_u32
(
tb
[
IFLA_GRE_REMOTE
]);
unsigned
int
addr
=
rta_getattr_u32
(
tb
[
IFLA_GRE_REMOTE
]);
if
(
addr
)
remote
=
format_host
(
AF_INET
,
4
,
&
addr
,
s1
,
sizeof
(
s1
));
...
...
@@ -359,7 +359,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf
(
f
,
"remote %s "
,
remote
);
if
(
tb
[
IFLA_GRE_LOCAL
])
{
unsigned
addr
=
rta_getattr_u32
(
tb
[
IFLA_GRE_LOCAL
]);
unsigned
int
addr
=
rta_getattr_u32
(
tb
[
IFLA_GRE_LOCAL
]);
if
(
addr
)
local
=
format_host
(
AF_INET
,
4
,
&
addr
,
s1
,
sizeof
(
s1
));
...
...
@@ -368,7 +368,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf
(
f
,
"local %s "
,
local
);
if
(
tb
[
IFLA_GRE_LINK
]
&&
rta_getattr_u32
(
tb
[
IFLA_GRE_LINK
]))
{
unsigned
link
=
rta_getattr_u32
(
tb
[
IFLA_GRE_LINK
]);
unsigned
int
link
=
rta_getattr_u32
(
tb
[
IFLA_GRE_LINK
]);
const
char
*
n
=
if_indextoname
(
link
,
s2
);
if
(
n
)
...
...
ip/link_gre6.c
View file @
56f5daac
...
...
@@ -71,13 +71,13 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
struct
rtattr
*
greinfo
[
IFLA_GRE_MAX
+
1
];
__u16
iflags
=
0
;
__u16
oflags
=
0
;
unsigned
ikey
=
0
;
unsigned
okey
=
0
;
unsigned
i
nt
i
key
=
0
;
unsigned
int
okey
=
0
;
struct
in6_addr
raddr
=
IN6ADDR_ANY_INIT
;
struct
in6_addr
laddr
=
IN6ADDR_ANY_INIT
;
unsigned
link
=
0
;
unsigned
flowinfo
=
0
;
unsigned
flags
=
0
;
unsigned
int
link
=
0
;
unsigned
int
flowinfo
=
0
;
unsigned
int
flags
=
0
;
__u8
hop_limit
=
DEFAULT_TNL_HOP_LIMIT
;
__u8
encap_limit
=
IPV6_DEFAULT_TNL_ENCAP_LIMIT
;
int
len
;
...
...
@@ -152,7 +152,7 @@ get_failed:
while
(
argc
>
0
)
{
if
(
!
matches
(
*
argv
,
"key"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
iflags
|=
GRE_KEY
;
...
...
@@ -170,14 +170,14 @@ get_failed:
ikey
=
okey
=
uval
;
}
else
if
(
!
matches
(
*
argv
,
"ikey"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
iflags
|=
GRE_KEY
;
if
(
strchr
(
*
argv
,
'.'
))
uval
=
get_addr32
(
*
argv
);
else
{
if
(
get_unsigned
(
&
uval
,
*
argv
,
0
)
<
0
)
{
if
(
get_unsigned
(
&
uval
,
*
argv
,
0
)
<
0
)
{
fprintf
(
stderr
,
"invalid value of
\"
ikey
\"\n
"
);
exit
(
-
1
);
}
...
...
@@ -185,14 +185,14 @@ get_failed:
}
ikey
=
uval
;
}
else
if
(
!
matches
(
*
argv
,
"okey"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
oflags
|=
GRE_KEY
;
if
(
strchr
(
*
argv
,
'.'
))
uval
=
get_addr32
(
*
argv
);
else
{
if
(
get_unsigned
(
&
uval
,
*
argv
,
0
)
<
0
)
{
if
(
get_unsigned
(
&
uval
,
*
argv
,
0
)
<
0
)
{
fprintf
(
stderr
,
"invalid value of
\"
okey
\"\n
"
);
exit
(
-
1
);
}
...
...
@@ -215,6 +215,7 @@ get_failed:
oflags
|=
GRE_CSUM
;
}
else
if
(
!
matches
(
*
argv
,
"remote"
))
{
inet_prefix
addr
;
NEXT_ARG
();
get_prefix
(
&
addr
,
*
argv
,
preferred_family
);
if
(
addr
.
family
==
AF_UNSPEC
)
...
...
@@ -222,6 +223,7 @@ get_failed:
memcpy
(
&
raddr
,
&
addr
.
data
,
sizeof
(
raddr
));
}
else
if
(
!
matches
(
*
argv
,
"local"
))
{
inet_prefix
addr
;
NEXT_ARG
();
get_prefix
(
&
addr
,
*
argv
,
preferred_family
);
if
(
addr
.
family
==
AF_UNSPEC
)
...
...
@@ -238,6 +240,7 @@ get_failed:
}
else
if
(
!
matches
(
*
argv
,
"ttl"
)
||
!
matches
(
*
argv
,
"hoplimit"
))
{
__u8
uval
;
NEXT_ARG
();
if
(
get_u8
(
&
uval
,
*
argv
,
0
))
invarg
(
"invalid TTL"
,
*
argv
);
...
...
@@ -246,6 +249,7 @@ get_failed:
!
matches
(
*
argv
,
"tclass"
)
||
!
matches
(
*
argv
,
"dsfield"
))
{
__u8
uval
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"inherit"
)
==
0
)
flags
|=
IP6_TNL_F_USE_ORIG_TCLASS
;
...
...
@@ -258,6 +262,7 @@ get_failed:
}
else
if
(
strcmp
(
*
argv
,
"flowlabel"
)
==
0
||
strcmp
(
*
argv
,
"fl"
)
==
0
)
{
__u32
uval
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"inherit"
)
==
0
)
flags
|=
IP6_TNL_F_USE_ORIG_FLOWLABEL
;
...
...
@@ -301,10 +306,10 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
char
s2
[
64
];
const
char
*
local
=
"any"
;
const
char
*
remote
=
"any"
;
unsigned
iflags
=
0
;
unsigned
oflags
=
0
;
unsigned
flags
=
0
;
unsigned
flowinfo
=
0
;
unsigned
i
nt
i
flags
=
0
;
unsigned
int
oflags
=
0
;
unsigned
int
flags
=
0
;
unsigned
int
flowinfo
=
0
;
struct
in6_addr
in6_addr_any
=
IN6ADDR_ANY_INIT
;
if
(
!
tb
)
...
...
@@ -318,6 +323,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if
(
tb
[
IFLA_GRE_REMOTE
])
{
struct
in6_addr
addr
;
memcpy
(
&
addr
,
RTA_DATA
(
tb
[
IFLA_GRE_REMOTE
]),
sizeof
(
addr
));
if
(
memcmp
(
&
addr
,
&
in6_addr_any
,
sizeof
(
addr
)))
...
...
@@ -328,6 +334,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if
(
tb
[
IFLA_GRE_LOCAL
])
{
struct
in6_addr
addr
;
memcpy
(
&
addr
,
RTA_DATA
(
tb
[
IFLA_GRE_LOCAL
]),
sizeof
(
addr
));
if
(
memcmp
(
&
addr
,
&
in6_addr_any
,
sizeof
(
addr
)))
...
...
@@ -337,7 +344,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf
(
f
,
"local %s "
,
local
);
if
(
tb
[
IFLA_GRE_LINK
]
&&
rta_getattr_u32
(
tb
[
IFLA_GRE_LINK
]))
{
unsigned
link
=
rta_getattr_u32
(
tb
[
IFLA_GRE_LINK
]);
unsigned
int
link
=
rta_getattr_u32
(
tb
[
IFLA_GRE_LINK
]);
const
char
*
n
=
if_indextoname
(
link
,
s2
);
if
(
n
)
...
...
ip/link_ip6tnl.c
View file @
56f5daac
...
...
@@ -35,7 +35,7 @@ static void print_usage(FILE *f)
fprintf
(
f
,
" [ mode { ip6ip6 | ipip6 | any } ]
\n
"
);
fprintf
(
f
,
" type ip6tnl [ remote ADDR ] [ local ADDR ]
\n
"
);
fprintf
(
f
,
" [ dev PHYS_DEV ] [ encaplimit ELIM ]
\n
"
);
fprintf
(
f
,
" [ hoplimit HLIM ] [ tclass TCLASS ] [ flowlabel FLOWLABEL ]
\n
"
);
fprintf
(
f
,
" [ hoplimit HLIM ] [ tclass TCLASS ] [ flowlabel FLOWLABEL ]
\n
"
);
fprintf
(
f
,
" [ dscp inherit ] [ fwmark inherit ]
\n
"
);
fprintf
(
f
,
"
\n
"
);
fprintf
(
f
,
"Where: NAME := STRING
\n
"
);
...
...
@@ -159,6 +159,7 @@ get_failed:
invarg
(
"Cannot guess tunnel mode."
,
*
argv
);
}
else
if
(
strcmp
(
*
argv
,
"remote"
)
==
0
)
{
inet_prefix
addr
;
NEXT_ARG
();
get_prefix
(
&
addr
,
*
argv
,
preferred_family
);
if
(
addr
.
family
==
AF_UNSPEC
)
...
...
@@ -166,6 +167,7 @@ get_failed:
memcpy
(
&
raddr
,
addr
.
data
,
addr
.
bytelen
);
}
else
if
(
strcmp
(
*
argv
,
"local"
)
==
0
)
{
inet_prefix
addr
;
NEXT_ARG
();
get_prefix
(
&
addr
,
*
argv
,
preferred_family
);
if
(
addr
.
family
==
AF_UNSPEC
)
...
...
@@ -180,6 +182,7 @@ get_failed:
strcmp
(
*
argv
,
"ttl"
)
==
0
||
strcmp
(
*
argv
,
"hlim"
)
==
0
)
{
__u8
uval
;
NEXT_ARG
();
if
(
get_u8
(
&
uval
,
*
argv
,
0
))
invarg
(
"invalid HLIM"
,
*
argv
);
...
...
@@ -190,6 +193,7 @@ get_failed:
flags
|=
IP6_TNL_F_IGN_ENCAP_LIMIT
;
}
else
{
__u8
uval
;
if
(
get_u8
(
&
uval
,
*
argv
,
0
)
<
-
1
)
invarg
(
"invalid ELIM"
,
*
argv
);
encap_limit
=
uval
;
...
...
@@ -200,6 +204,7 @@ get_failed:
strcmp
(
*
argv
,
"tos"
)
==
0
||
matches
(
*
argv
,
"dsfield"
)
==
0
)
{
__u8
uval
;
NEXT_ARG
();
flowinfo
&=
~
IP6_FLOWINFO_TCLASS
;
if
(
strcmp
(
*
argv
,
"inherit"
)
==
0
)
...
...
@@ -213,6 +218,7 @@ get_failed:
}
else
if
(
strcmp
(
*
argv
,
"flowlabel"
)
==
0
||
strcmp
(
*
argv
,
"fl"
)
==
0
)
{
__u32
uval
;
NEXT_ARG
();
flowinfo
&=
~
IP6_FLOWINFO_FLOWLABEL
;
if
(
strcmp
(
*
argv
,
"inherit"
)
==
0
)
...
...
@@ -299,7 +305,7 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
}
if
(
tb
[
IFLA_IPTUN_LINK
]
&&
rta_getattr_u32
(
tb
[
IFLA_IPTUN_LINK
]))
{
unsigned
link
=
rta_getattr_u32
(
tb
[
IFLA_IPTUN_LINK
]);
unsigned
int
link
=
rta_getattr_u32
(
tb
[
IFLA_IPTUN_LINK
]);
const
char
*
n
=
if_indextoname
(
link
,
s2
);
if
(
n
)
...
...
ip/link_iptnl.c
View file @
56f5daac
...
...
@@ -197,6 +197,7 @@ get_failed:
strcmp
(
*
argv
,
"tclass"
)
==
0
||
matches
(
*
argv
,
"dsfield"
)
==
0
)
{
__u32
uval
;
NEXT_ARG
();
if
(
strcmp
(
*
argv
,
"inherit"
)
!=
0
)
{
if
(
rtnl_dsfield_a2n
(
&
uval
,
*
argv
))
...
...
@@ -262,6 +263,7 @@ get_failed:
encapflags
&=
~
TUNNEL_ENCAP_FLAG_REMCSUM
;
}
else
if
(
strcmp
(
*
argv
,
"6rd-prefix"
)
==
0
)
{
inet_prefix
prefix
;
NEXT_ARG
();
if
(
get_prefix
(
&
prefix
,
*
argv
,
AF_INET6
))
invarg
(
"invalid 6rd_prefix
\n
"
,
*
argv
);
...
...
@@ -269,6 +271,7 @@ get_failed:
ip6rdprefixlen
=
prefix
.
bitlen
;
}
else
if
(
strcmp
(
*
argv
,
"6rd-relay_prefix"
)
==
0
)
{
inet_prefix
prefix
;
NEXT_ARG
();
if
(
get_prefix
(
&
prefix
,
*
argv
,
AF_INET
))
invarg
(
"invalid 6rd-relay_prefix
\n
"
,
*
argv
);
...
...
@@ -276,6 +279,7 @@ get_failed:
ip6rdrelayprefixlen
=
prefix
.
bitlen
;
}
else
if
(
strcmp
(
*
argv
,
"6rd-reset"
)
==
0
)
{
inet_prefix
prefix
;
get_prefix
(
&
prefix
,
"2002::"
,
AF_INET6
);
memcpy
(
&
ip6rdprefix
,
prefix
.
data
,
16
);
ip6rdprefixlen
=
16
;
...
...
@@ -332,7 +336,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
return
;
if
(
tb
[
IFLA_IPTUN_REMOTE
])
{
unsigned
addr
=
rta_getattr_u32
(
tb
[
IFLA_IPTUN_REMOTE
]);
unsigned
int
addr
=
rta_getattr_u32
(
tb
[
IFLA_IPTUN_REMOTE
]);
if
(
addr
)
remote
=
format_host
(
AF_INET
,
4
,
&
addr
,
s1
,
sizeof
(
s1
));
...
...
@@ -341,7 +345,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
fprintf
(
f
,
"remote %s "
,
remote
);
if
(
tb
[
IFLA_IPTUN_LOCAL
])
{
unsigned
addr
=
rta_getattr_u32
(
tb
[
IFLA_IPTUN_LOCAL
]);
unsigned
int
addr
=
rta_getattr_u32
(
tb
[
IFLA_IPTUN_LOCAL
]);
if
(
addr
)
local
=
format_host
(
AF_INET
,
4
,
&
addr
,
s1
,
sizeof
(
s1
));
...
...
@@ -350,7 +354,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
fprintf
(
f
,
"local %s "
,
local
);
if
(
tb
[
IFLA_IPTUN_LINK
]
&&
rta_getattr_u32
(
tb
[
IFLA_IPTUN_LINK
]))
{
unsigned
link
=
rta_getattr_u32
(
tb
[
IFLA_IPTUN_LINK
]);
unsigned
int
link
=
rta_getattr_u32
(
tb
[
IFLA_IPTUN_LINK
]);
const
char
*
n
=
if_indextoname
(
link
,
s2
);
if
(
n
)
...
...
ip/link_veth.c
View file @
56f5daac
...
...
@@ -37,7 +37,7 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
char
*
type
=
NULL
;
int
index
=
0
;
int
err
,
len
;
struct
rtattr
*
data
;
struct
rtattr
*
data
;
int
group
;
struct
ifinfomsg
*
ifm
,
*
peer_ifm
;
unsigned
int
ifi_flags
,
ifi_change
;
...
...
ip/link_vti.c
View file @
56f5daac
...
...
@@ -55,11 +55,11 @@ static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
struct
rtattr
*
tb
[
IFLA_MAX
+
1
];
struct
rtattr
*
linkinfo
[
IFLA_INFO_MAX
+
1
];
struct
rtattr
*
vtiinfo
[
IFLA_VTI_MAX
+
1
];
unsigned
ikey
=
0
;
unsigned
okey
=
0
;
unsigned
saddr
=
0
;
unsigned
daddr
=
0
;
unsigned
link
=
0
;
unsigned
i
nt
i
key
=
0
;
unsigned
int
okey
=
0
;
unsigned
int
saddr
=
0
;
unsigned
int
daddr
=
0
;
unsigned
int
link
=
0
;
int
len
;
if
(
!
(
n
->
nlmsg_flags
&
NLM_F_CREATE
))
{
...
...
@@ -114,7 +114,7 @@ get_failed:
while
(
argc
>
0
)
{
if
(
!
matches
(
*
argv
,
"key"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
if
(
strchr
(
*
argv
,
'.'
))
...
...
@@ -130,7 +130,7 @@ get_failed:
ikey
=
okey
=
uval
;
}
else
if
(
!
matches
(
*
argv
,
"ikey"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
if
(
strchr
(
*
argv
,
'.'
))
...
...
@@ -144,7 +144,7 @@ get_failed:
}
ikey
=
uval
;
}
else
if
(
!
matches
(
*
argv
,
"okey"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
if
(
strchr
(
*
argv
,
'.'
))
...
...
@@ -207,7 +207,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
return
;
if
(
tb
[
IFLA_VTI_REMOTE
])
{
unsigned
addr
=
*
(
__u32
*
)
RTA_DATA
(
tb
[
IFLA_VTI_REMOTE
]);
unsigned
int
addr
=
*
(
__u32
*
)
RTA_DATA
(
tb
[
IFLA_VTI_REMOTE
]);
if
(
addr
)
remote
=
format_host
(
AF_INET
,
4
,
&
addr
,
s1
,
sizeof
(
s1
));
...
...
@@ -216,7 +216,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf
(
f
,
"remote %s "
,
remote
);
if
(
tb
[
IFLA_VTI_LOCAL
])
{
unsigned
addr
=
*
(
__u32
*
)
RTA_DATA
(
tb
[
IFLA_VTI_LOCAL
]);
unsigned
int
addr
=
*
(
__u32
*
)
RTA_DATA
(
tb
[
IFLA_VTI_LOCAL
]);
if
(
addr
)
local
=
format_host
(
AF_INET
,
4
,
&
addr
,
s1
,
sizeof
(
s1
));
...
...
@@ -225,7 +225,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf
(
f
,
"local %s "
,
local
);
if
(
tb
[
IFLA_VTI_LINK
]
&&
*
(
__u32
*
)
RTA_DATA
(
tb
[
IFLA_VTI_LINK
]))
{
unsigned
link
=
*
(
__u32
*
)
RTA_DATA
(
tb
[
IFLA_VTI_LINK
]);
unsigned
int
link
=
*
(
__u32
*
)
RTA_DATA
(
tb
[
IFLA_VTI_LINK
]);
const
char
*
n
=
if_indextoname
(
link
,
s2
);
if
(
n
)
...
...
ip/link_vti6.c
View file @
56f5daac
...
...
@@ -53,9 +53,9 @@ static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
struct
rtattr
*
vtiinfo
[
IFLA_VTI_MAX
+
1
];
struct
in6_addr
saddr
;
struct
in6_addr
daddr
;
unsigned
ikey
=
0
;
unsigned
okey
=
0
;
unsigned
link
=
0
;
unsigned
i
nt
i
key
=
0
;
unsigned
int
okey
=
0
;
unsigned
int
link
=
0
;
int
len
;
if
(
!
(
n
->
nlmsg_flags
&
NLM_F_CREATE
))
{
...
...
@@ -110,7 +110,7 @@ get_failed:
while
(
argc
>
0
)
{
if
(
!
matches
(
*
argv
,
"key"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
if
(
strchr
(
*
argv
,
'.'
))
...
...
@@ -126,7 +126,7 @@ get_failed:
ikey
=
okey
=
uval
;
}
else
if
(
!
matches
(
*
argv
,
"ikey"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
if
(
strchr
(
*
argv
,
'.'
))
...
...
@@ -140,7 +140,7 @@ get_failed:
}
ikey
=
uval
;
}
else
if
(
!
matches
(
*
argv
,
"okey"
))
{
unsigned
uval
;
unsigned
int
uval
;
NEXT_ARG
();
if
(
strchr
(
*
argv
,
'.'
))
...
...
@@ -160,6 +160,7 @@ get_failed:
exit
(
-
1
);
}
else
{
inet_prefix
addr
;
get_prefix
(
&
addr
,
*
argv
,
AF_INET6
);
memcpy
(
&
daddr
,
addr
.
data
,
addr
.
bytelen
);
}
...
...
@@ -170,6 +171,7 @@ get_failed:
exit
(
-
1
);
}
else
{
inet_prefix
addr
;
get_prefix
(
&
addr
,
*
argv
,
AF_INET6
);
memcpy
(
&
saddr
,
addr
.
data
,
addr
.
bytelen
);
}
...
...
@@ -222,7 +224,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf
(
f
,
"local %s "
,
local
);
if
(
tb
[
IFLA_VTI_LINK
]
&&
*
(
__u32
*
)
RTA_DATA
(
tb
[
IFLA_VTI_LINK
]))
{
unsigned
link
=
*
(
__u32
*
)
RTA_DATA
(
tb
[
IFLA_VTI_LINK
]);
unsigned
int
link
=
*
(
__u32
*
)
RTA_DATA
(
tb
[
IFLA_VTI_LINK
]);
const
char
*
n
=
if_indextoname
(
link
,
s2
);
if
(
n
)
...
...
ip/rtmon.c
View file @
56f5daac
...
...
@@ -25,13 +25,13 @@
#include "utils.h"
#include "libnetlink.h"
int
resolve_hosts
=
0
;
int
resolve_hosts
;
static
int
init_phase
=
1
;
static
void
write_stamp
(
FILE
*
fp
)
{
char
buf
[
128
];
struct
nlmsghdr
*
n1
=
(
void
*
)
buf
;
struct
nlmsghdr
*
n1
=
(
void
*
)
buf
;
struct
timeval
tv
;
n1
->
nlmsg_type
=
NLMSG_TSTAMP
;
...
...
@@ -40,18 +40,19 @@ static void write_stamp(FILE *fp)
n1
->
nlmsg_pid
=
0
;
n1
->
nlmsg_len
=
NLMSG_LENGTH
(
4
*
2
);
gettimeofday
(
&
tv
,
NULL
);
((
__u32
*
)
NLMSG_DATA
(
n1
))[
0
]
=
tv
.
tv_sec
;
((
__u32
*
)
NLMSG_DATA
(
n1
))[
1
]
=
tv
.
tv_usec
;
fwrite
((
void
*
)
n1
,
1
,
NLMSG_ALIGN
(
n1
->
nlmsg_len
),
fp
);
((
__u32
*
)
NLMSG_DATA
(
n1
))[
0
]
=
tv
.
tv_sec
;
((
__u32
*
)
NLMSG_DATA
(
n1
))[
1
]
=
tv
.
tv_usec
;
fwrite
((
void
*
)
n1
,
1
,
NLMSG_ALIGN
(
n1
->
nlmsg_len
),
fp
);
}
static
int
dump_msg
(
const
struct
sockaddr_nl
*
who
,
struct
rtnl_ctrl_data
*
ctrl
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
if
(
!
init_phase
)
write_stamp
(
fp
);
fwrite
((
void
*
)
n
,
1
,
NLMSG_ALIGN
(
n
->
nlmsg_len
),
fp
);
fwrite
((
void
*
)
n
,
1
,
NLMSG_ALIGN
(
n
->
nlmsg_len
),
fp
);
fflush
(
fp
);
return
0
;
}
...
...
@@ -75,7 +76,7 @@ main(int argc, char **argv)
FILE
*
fp
;
struct
rtnl_handle
rth
;
int
family
=
AF_UNSPEC
;
unsigned
groups
=
~
0U
;
unsigned
int
groups
=
~
0U
;
int
llink
=
0
;
int
laddr
=
0
;
int
lroute
=
0
;
...
...
@@ -115,13 +116,13 @@ main(int argc, char **argv)
usage
();
file
=
argv
[
1
];
}
else
if
(
matches
(
argv
[
1
],
"link"
)
==
0
)
{
llink
=
1
;
llink
=
1
;
groups
=
0
;
}
else
if
(
matches
(
argv
[
1
],
"address"
)
==
0
)
{
laddr
=
1
;
laddr
=
1
;
groups
=
0
;
}
else
if
(
matches
(
argv
[
1
],
"route"
)
==
0
)
{
lroute
=
1
;
lroute
=
1
;
groups
=
0
;
}
else
if
(
strcmp
(
argv
[
1
],
"all"
)
==
0
)
{
groups
=
~
0U
;
...
...
@@ -176,7 +177,7 @@ main(int argc, char **argv)
init_phase
=
0
;
if
(
rtnl_listen
(
&
rth
,
dump_msg
,
(
void
*
)
fp
)
<
0
)
if
(
rtnl_listen
(
&
rth
,
dump_msg
,
(
void
*
)
fp
)
<
0
)
exit
(
2
);
exit
(
0
);
...
...
ip/tcp_metrics.c
View file @
56f5daac
...
...
@@ -168,6 +168,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
if
(
f
.
flushb
)
{
struct
nlmsghdr
*
fn
;
TCPM_REQUEST
(
req2
,
128
,
TCP_METRICS_CMD_DEL
,
NLM_F_REQUEST
);
addattr_l
(
&
req2
.
n
,
sizeof
(
req2
),
atype
,
&
daddr
.
data
,
...
...
@@ -333,6 +334,7 @@ static int tcpm_do_cmd(int cmd, int argc, char **argv)
if
(
strcmp
(
*
argv
,
"src"
)
==
0
||
strcmp
(
*
argv
,
"source"
)
==
0
)
{
char
*
who
=
*
argv
;
NEXT_ARG
();
if
(
matches
(
*
argv
,
"help"
)
==
0
)
usage
();
...
...
@@ -354,6 +356,7 @@ static int tcpm_do_cmd(int cmd, int argc, char **argv)
}
}
else
{
char
*
who
=
"address"
;
if
(
strcmp
(
*
argv
,
"addr"
)
==
0
||
strcmp
(
*
argv
,
"address"
)
==
0
)
{
who
=
*
argv
;
...
...
@@ -504,7 +507,7 @@ int do_tcp_metrics(int argc, char **argv)
if
(
matches
(
argv
[
0
],
"help"
)
==
0
)
usage
();
fprintf
(
stderr
,
"Command
\"
%s
\"
is unknown,
"
"try
\"
ip tcp_metrics help
\"
.
\n
"
,
*
argv
);
fprintf
(
stderr
,
"Command
\"
%s
\"
is unknown,
try
\"
ip tcp_metrics help
\"
.
\n
"
,
*
argv
);
exit
(
-
1
);
}
ip/tunnel.c
View file @
56f5daac
...
...
@@ -72,7 +72,7 @@ int tnl_get_ioctl(const char *basedev, void *p)
int
err
;
strncpy
(
ifr
.
ifr_name
,
basedev
,
IFNAMSIZ
);
ifr
.
ifr_ifru
.
ifru_data
=
(
void
*
)
p
;
ifr
.
ifr_ifru
.
ifru_data
=
(
void
*
)
p
;
fd
=
socket
(
preferred_family
,
SOCK_DGRAM
,
0
);
if
(
fd
<
0
)
{
...
...
@@ -183,7 +183,7 @@ int tnl_ioctl_get_6rd(const char *name, void *p)
__be32
tnl_parse_key
(
const
char
*
name
,
const
char
*
key
)
{
unsigned
uval
;
unsigned
int
uval
;
if
(
strchr
(
key
,
'.'
))
return
get_addr32
(
key
);
...
...
@@ -209,10 +209,10 @@ void tnl_print_stats(const char *buf)
tx_fifo
,
tx_colls
,
tx_carrier
,
rx_multi
;
if
(
sscanf
(
buf
,
"%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu"
,
&
rx_bytes
,
&
rx_packets
,
&
rx_errs
,
&
rx_drops
,
&
rx_fifo
,
&
rx_frame
,
&
rx_multi
,
&
tx_bytes
,
&
tx_packets
,
&
tx_errs
,
&
tx_drops
,
&
tx_fifo
,
&
tx_colls
,
&
tx_carrier
)
!=
14
)
&
rx_bytes
,
&
rx_packets
,
&
rx_errs
,
&
rx_drops
,
&
rx_fifo
,
&
rx_frame
,
&
rx_multi
,
&
tx_bytes
,
&
tx_packets
,
&
tx_errs
,
&
tx_drops
,
&
tx_fifo
,
&
tx_colls
,
&
tx_carrier
)
!=
14
)
return
;
printf
(
"%s"
,
_SL_
);
...
...
ip/xfrm_monitor.c
View file @
56f5daac
...
...
@@ -46,10 +46,10 @@ static void usage(void)
static
int
xfrm_acquire_print
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
xfrm_user_acquire
*
xacq
=
NLMSG_DATA
(
n
);
int
len
=
n
->
nlmsg_len
;
struct
rtattr
*
tb
[
XFRMA_MAX
+
1
];
struct
rtattr
*
tb
[
XFRMA_MAX
+
1
];
__u16
family
;
len
-=
NLMSG_LENGTH
(
sizeof
(
*
xacq
));
...
...
@@ -71,6 +71,7 @@ static int xfrm_acquire_print(const struct sockaddr_nl *who,
fprintf
(
fp
,
"proto %s "
,
strxf_xfrmproto
(
xacq
->
id
.
proto
));
if
(
show_stats
>
0
||
xacq
->
id
.
spi
)
{
__u32
spi
=
ntohl
(
xacq
->
id
.
spi
);
fprintf
(
fp
,
"spi 0x%08x"
,
spi
);
if
(
show_stats
>
0
)
fprintf
(
fp
,
"(%u)"
,
spi
);
...
...
@@ -107,7 +108,7 @@ static int xfrm_acquire_print(const struct sockaddr_nl *who,
static
int
xfrm_state_flush_print
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
xfrm_usersa_flush
*
xsf
=
NLMSG_DATA
(
n
);
int
len
=
n
->
nlmsg_len
;
const
char
*
str
;
...
...
@@ -137,8 +138,8 @@ static int xfrm_state_flush_print(const struct sockaddr_nl *who,
static
int
xfrm_policy_flush_print
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
struct
rtattr
*
tb
[
XFRMA_MAX
+
1
];
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
rtattr
*
tb
[
XFRMA_MAX
+
1
];
FILE
*
fp
=
(
FILE
*
)
arg
;
int
len
=
n
->
nlmsg_len
;
len
-=
NLMSG_SPACE
(
0
);
...
...
@@ -175,10 +176,10 @@ static int xfrm_policy_flush_print(const struct sockaddr_nl *who,
static
int
xfrm_report_print
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
xfrm_user_report
*
xrep
=
NLMSG_DATA
(
n
);
int
len
=
n
->
nlmsg_len
;
struct
rtattr
*
tb
[
XFRMA_MAX
+
1
];
struct
rtattr
*
tb
[
XFRMA_MAX
+
1
];
__u16
family
;
len
-=
NLMSG_LENGTH
(
sizeof
(
*
xrep
));
...
...
@@ -210,7 +211,8 @@ static int xfrm_report_print(const struct sockaddr_nl *who,
static
void
xfrm_ae_flags_print
(
__u32
flags
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
fprintf
(
fp
,
" (0x%x) "
,
flags
);
if
(
!
flags
)
return
;
...
...
@@ -241,13 +243,13 @@ static void xfrm_usersa_print(const struct xfrm_usersa_id *sa_id, __u32 reqid, F
static
int
xfrm_ae_print
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
xfrm_aevent_id
*
id
=
NLMSG_DATA
(
n
);
char
abuf
[
256
];
fprintf
(
fp
,
"Async event "
);
xfrm_ae_flags_print
(
id
->
flags
,
arg
);
fprintf
(
fp
,
"
\n\t
"
);
fprintf
(
fp
,
"
\n\t
"
);
memset
(
abuf
,
'\0'
,
sizeof
(
abuf
));
fprintf
(
fp
,
"src %s "
,
rt_addr_n2a
(
id
->
sa_id
.
family
,
sizeof
(
id
->
saddr
),
&
id
->
saddr
,
...
...
@@ -272,7 +274,7 @@ static void xfrm_print_addr(FILE *fp, int family, xfrm_address_t *a)
static
int
xfrm_mapping_print
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
xfrm_user_mapping
*
map
=
NLMSG_DATA
(
n
);
fprintf
(
fp
,
"Mapping change "
);
...
...
@@ -293,7 +295,7 @@ static int xfrm_accept_msg(const struct sockaddr_nl *who,
struct
rtnl_ctrl_data
*
ctrl
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
if
(
timestamp
)
print_timestamp
(
fp
);
...
...
@@ -353,13 +355,13 @@ extern struct rtnl_handle rth;
int
do_xfrm_monitor
(
int
argc
,
char
**
argv
)
{
char
*
file
=
NULL
;
unsigned
groups
=
~
((
unsigned
)
0
);
/* XXX */
int
lacquire
=
0
;
int
lexpire
=
0
;
int
laevent
=
0
;
int
lpolicy
=
0
;
int
lsa
=
0
;
int
lreport
=
0
;
unsigned
int
groups
=
~
((
unsigned
)
0
);
/* XXX */
int
lacquire
=
0
;
int
lexpire
=
0
;
int
laevent
=
0
;
int
lpolicy
=
0
;
int
lsa
=
0
;
int
lreport
=
0
;
rtnl_close
(
&
rth
);
...
...
@@ -370,22 +372,22 @@ int do_xfrm_monitor(int argc, char **argv)
}
else
if
(
matches
(
*
argv
,
"all-nsid"
)
==
0
)
{
listen_all_nsid
=
1
;
}
else
if
(
matches
(
*
argv
,
"acquire"
)
==
0
)
{
lacquire
=
1
;
lacquire
=
1
;
groups
=
0
;
}
else
if
(
matches
(
*
argv
,
"expire"
)
==
0
)
{
lexpire
=
1
;
lexpire
=
1
;
groups
=
0
;
}
else
if
(
matches
(
*
argv
,
"SA"
)
==
0
)
{
lsa
=
1
;
lsa
=
1
;
groups
=
0
;
}
else
if
(
matches
(
*
argv
,
"aevent"
)
==
0
)
{
laevent
=
1
;
laevent
=
1
;
groups
=
0
;
}
else
if
(
matches
(
*
argv
,
"policy"
)
==
0
)
{
lpolicy
=
1
;
lpolicy
=
1
;
groups
=
0
;
}
else
if
(
matches
(
*
argv
,
"report"
)
==
0
)
{
lreport
=
1
;
lreport
=
1
;
groups
=
0
;
}
else
if
(
matches
(
*
argv
,
"help"
)
==
0
)
{
usage
();
...
...
@@ -428,7 +430,7 @@ int do_xfrm_monitor(int argc, char **argv)
if
(
listen_all_nsid
&&
rtnl_listen_all_nsid
(
&
rth
)
<
0
)
exit
(
1
);
if
(
rtnl_listen
(
&
rth
,
xfrm_accept_msg
,
(
void
*
)
stdout
)
<
0
)
if
(
rtnl_listen
(
&
rth
,
xfrm_accept_msg
,
(
void
*
)
stdout
)
<
0
)
exit
(
2
);
return
0
;
...
...
ip/xfrm_policy.c
View file @
56f5daac
...
...
@@ -33,7 +33,7 @@
#include "xfrm.h"
#include "ip_common.h"
/
/#define NLMSG_DELETEALL_BUF_SIZE (4096-512)
/
* #define NLMSG_DELETEALL_BUF_SIZE (4096-512) */
#define NLMSG_DELETEALL_BUF_SIZE 8192
/*
...
...
@@ -241,7 +241,7 @@ int xfrm_sctx_parse(char *ctxstr, char *s,
return
0
;
}
static
int
xfrm_policy_modify
(
int
cmd
,
unsigned
flags
,
int
argc
,
char
**
argv
)
static
int
xfrm_policy_modify
(
int
cmd
,
unsigned
int
flags
,
int
argc
,
char
**
argv
)
{
struct
rtnl_handle
rth
;
struct
{
...
...
@@ -376,7 +376,7 @@ static int xfrm_policy_modify(int cmd, unsigned flags, int argc, char **argv)
int
r
=
addattr_l
(
&
req
.
n
,
sizeof
(
req
.
buf
),
XFRMA_MARK
,
(
void
*
)
&
mark
,
sizeof
(
mark
));
if
(
r
<
0
)
{
fprintf
(
stderr
,
"%s: XFRMA_MARK failed
\n
"
,
__func__
);
fprintf
(
stderr
,
"%s: XFRMA_MARK failed
\n
"
,
__func__
);
exit
(
1
);
}
}
...
...
@@ -459,13 +459,13 @@ static int xfrm_policy_filter_match(struct xfrm_userpolicy_info *xpinfo,
int
xfrm_policy_print
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
struct
rtattr
*
tb
[
XFRMA_MAX
+
1
];
struct
rtattr
*
rta
;
struct
rtattr
*
tb
[
XFRMA_MAX
+
1
];
struct
rtattr
*
rta
;
struct
xfrm_userpolicy_info
*
xpinfo
=
NULL
;
struct
xfrm_user_polexpire
*
xpexp
=
NULL
;
struct
xfrm_userpolicy_id
*
xpid
=
NULL
;
__u8
ptype
=
XFRM_POLICY_TYPE_MAIN
;
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
int
len
=
n
->
nlmsg_len
;
if
(
n
->
nlmsg_type
!=
XFRM_MSG_NEWPOLICY
&&
...
...
@@ -526,7 +526,7 @@ int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
fprintf
(
fp
,
"Expired "
);
if
(
n
->
nlmsg_type
==
XFRM_MSG_DELPOLICY
)
{
/
/xfrm_policy_id_print();
/
* xfrm_policy_id_print(); */
if
(
!
tb
[
XFRMA_POLICY
])
{
fprintf
(
stderr
,
"Buggy XFRM_MSG_DELPOLICY: no XFRMA_POLICY
\n
"
);
return
-
1
;
...
...
@@ -659,7 +659,7 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete,
int
r
=
addattr_l
(
&
req
.
n
,
sizeof
(
req
.
buf
),
XFRMA_MARK
,
(
void
*
)
&
mark
,
sizeof
(
mark
));
if
(
r
<
0
)
{
fprintf
(
stderr
,
"%s: XFRMA_MARK failed
\n
"
,
__func__
);
fprintf
(
stderr
,
"%s: XFRMA_MARK failed
\n
"
,
__func__
);
exit
(
1
);
}
}
...
...
@@ -691,7 +691,7 @@ static int xfrm_policy_get(int argc, char **argv)
xfrm_policy_get_or_delete
(
argc
,
argv
,
0
,
n
,
sizeof
(
buf
));
if
(
xfrm_policy_print
(
NULL
,
n
,
(
void
*
)
stdout
)
<
0
)
{
if
(
xfrm_policy_print
(
NULL
,
n
,
(
void
*
)
stdout
)
<
0
)
{
fprintf
(
stderr
,
"An error :-)
\n
"
);
exit
(
1
);
}
...
...
@@ -761,7 +761,7 @@ static int xfrm_policy_keep(const struct sockaddr_nl *who,
xpid
->
index
=
xpinfo
->
index
;
xb
->
offset
+=
new_n
->
nlmsg_len
;
xb
->
nlmsg_count
++
;
xb
->
nlmsg_count
++
;
return
0
;
}
...
...
@@ -915,12 +915,12 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall)
exit
(
0
);
}
static
int
print_spdinfo
(
struct
nlmsghdr
*
n
,
void
*
arg
)
static
int
print_spdinfo
(
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
__u32
*
f
=
NLMSG_DATA
(
n
);
struct
rtattr
*
tb
[
XFRMA_SPD_MAX
+
1
];
struct
rtattr
*
rta
;
struct
rtattr
*
tb
[
XFRMA_SPD_MAX
+
1
];
struct
rtattr
*
rta
;
int
len
=
n
->
nlmsg_len
;
...
...
@@ -933,7 +933,7 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg)
rta
=
XFRMSAPD_RTA
(
f
);
parse_rtattr
(
tb
,
XFRMA_SPD_MAX
,
rta
,
len
);
fprintf
(
fp
,
"
\t
SPD"
);
fprintf
(
fp
,
"
\t
SPD"
);
if
(
tb
[
XFRMA_SPD_INFO
])
{
struct
xfrmu_spdinfo
*
si
;
...
...
@@ -942,16 +942,16 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg)
return
-
1
;
}
si
=
RTA_DATA
(
tb
[
XFRMA_SPD_INFO
]);
fprintf
(
fp
,
" IN %d"
,
si
->
incnt
);
fprintf
(
fp
,
" OUT %d"
,
si
->
outcnt
);
fprintf
(
fp
,
" FWD %d"
,
si
->
fwdcnt
);
fprintf
(
fp
,
" IN %d"
,
si
->
incnt
);
fprintf
(
fp
,
" OUT %d"
,
si
->
outcnt
);
fprintf
(
fp
,
" FWD %d"
,
si
->
fwdcnt
);
if
(
show_stats
)
{
fprintf
(
fp
,
" (Sock:"
);
fprintf
(
fp
,
" IN %d"
,
si
->
inscnt
);
fprintf
(
fp
,
" OUT %d"
,
si
->
outscnt
);
fprintf
(
fp
,
" FWD %d"
,
si
->
fwdscnt
);
fprintf
(
fp
,
")"
);
fprintf
(
fp
,
" (Sock:"
);
fprintf
(
fp
,
" IN %d"
,
si
->
inscnt
);
fprintf
(
fp
,
" OUT %d"
,
si
->
outscnt
);
fprintf
(
fp
,
" FWD %d"
,
si
->
fwdscnt
);
fprintf
(
fp
,
")"
);
}
fprintf
(
fp
,
"%s"
,
_SL_
);
...
...
@@ -965,34 +965,36 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg)
return
-
1
;
}
sh
=
RTA_DATA
(
tb
[
XFRMA_SPD_HINFO
]);
fprintf
(
fp
,
"
\t
SPD buckets:"
);
fprintf
(
fp
,
" count %d"
,
sh
->
spdhcnt
);
fprintf
(
fp
,
" Max %d"
,
sh
->
spdhmcnt
);
fprintf
(
fp
,
"
\t
SPD buckets:"
);
fprintf
(
fp
,
" count %d"
,
sh
->
spdhcnt
);
fprintf
(
fp
,
" Max %d"
,
sh
->
spdhmcnt
);
fprintf
(
fp
,
"%s"
,
_SL_
);
}
if
(
tb
[
XFRMA_SPD_IPV4_HTHRESH
])
{
struct
xfrmu_spdhthresh
*
th
;
if
(
RTA_PAYLOAD
(
tb
[
XFRMA_SPD_IPV4_HTHRESH
])
<
sizeof
(
*
th
))
{
fprintf
(
stderr
,
"SPDinfo: Wrong len %d
\n
"
,
len
);
return
-
1
;
}
th
=
RTA_DATA
(
tb
[
XFRMA_SPD_IPV4_HTHRESH
]);
fprintf
(
fp
,
"
\t
SPD IPv4 thresholds:"
);
fprintf
(
fp
,
" local %d"
,
th
->
lbits
);
fprintf
(
fp
,
" remote %d"
,
th
->
rbits
);
fprintf
(
fp
,
"
\t
SPD IPv4 thresholds:"
);
fprintf
(
fp
,
" local %d"
,
th
->
lbits
);
fprintf
(
fp
,
" remote %d"
,
th
->
rbits
);
fprintf
(
fp
,
"%s"
,
_SL_
);
}
if
(
tb
[
XFRMA_SPD_IPV6_HTHRESH
])
{
struct
xfrmu_spdhthresh
*
th
;
if
(
RTA_PAYLOAD
(
tb
[
XFRMA_SPD_IPV6_HTHRESH
])
<
sizeof
(
*
th
))
{
fprintf
(
stderr
,
"SPDinfo: Wrong len %d
\n
"
,
len
);
return
-
1
;
}
th
=
RTA_DATA
(
tb
[
XFRMA_SPD_IPV6_HTHRESH
]);
fprintf
(
fp
,
"
\t
SPD IPv6 thresholds:"
);
fprintf
(
fp
,
" local %d"
,
th
->
lbits
);
fprintf
(
fp
,
" remote %d"
,
th
->
rbits
);
fprintf
(
fp
,
"
\t
SPD IPv6 thresholds:"
);
fprintf
(
fp
,
" local %d"
,
th
->
lbits
);
fprintf
(
fp
,
" remote %d"
,
th
->
rbits
);
fprintf
(
fp
,
"%s"
,
_SL_
);
}
}
...
...
@@ -1000,7 +1002,7 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg)
if
(
oneline
)
fprintf
(
fp
,
"
\n
"
);
return
0
;
return
0
;
}
static
int
xfrm_spd_setinfo
(
int
argc
,
char
**
argv
)
...
...
@@ -1093,7 +1095,7 @@ static int xfrm_spd_getinfo(int argc, char **argv)
if
(
rtnl_talk
(
&
rth
,
&
req
.
n
,
&
req
.
n
,
sizeof
(
req
))
<
0
)
exit
(
2
);
print_spdinfo
(
&
req
.
n
,
(
void
*
)
stdout
);
print_spdinfo
(
&
req
.
n
,
(
void
*
)
stdout
);
rtnl_close
(
&
rth
);
...
...
ip/xfrm_state.c
View file @
56f5daac
...
...
@@ -32,7 +32,7 @@
#include "xfrm.h"
#include "ip_common.h"
/
/#define NLMSG_DELETEALL_BUF_SIZE (4096-512)
/
* #define NLMSG_DELETEALL_BUF_SIZE (4096-512) */
#define NLMSG_DELETEALL_BUF_SIZE 8192
/*
...
...
@@ -107,7 +107,7 @@ static void usage(void)
fprintf
(
stderr
,
"LIMIT-LIST := [ LIMIT-LIST ] limit LIMIT
\n
"
);
fprintf
(
stderr
,
"LIMIT := { time-soft | time-hard | time-use-soft | time-use-hard } SECONDS |
\n
"
);
fprintf
(
stderr
,
" { byte-soft | byte-hard } SIZE | { packet-soft | packet-hard } COUNT
\n
"
);
fprintf
(
stderr
,
"ENCAP := { espinudp | espinudp-nonike } SPORT DPORT OADDR
\n
"
);
fprintf
(
stderr
,
"ENCAP := { espinudp | espinudp-nonike } SPORT DPORT OADDR
\n
"
);
exit
(
-
1
);
}
...
...
@@ -142,7 +142,7 @@ static int xfrm_algo_parse(struct xfrm_algo *alg, enum xfrm_attr_type_t type,
if
(
len
>
max
)
invarg
(
"ALGO-KEYMAT value makes buffer overflow
\n
"
,
key
);
for
(
i
=
-
(
plen
%
2
),
j
=
0
;
j
<
len
;
i
+=
2
,
j
++
)
{
for
(
i
=
-
(
plen
%
2
),
j
=
0
;
j
<
len
;
i
+=
2
,
j
++
)
{
char
vbuf
[
3
];
__u8
val
;
...
...
@@ -266,13 +266,13 @@ static int xfrm_state_extra_flag_parse(__u32 *extra_flags, int *argcp, char ***a
return
0
;
}
static
int
xfrm_state_modify
(
int
cmd
,
unsigned
flags
,
int
argc
,
char
**
argv
)
static
int
xfrm_state_modify
(
int
cmd
,
unsigned
int
flags
,
int
argc
,
char
**
argv
)
{
struct
rtnl_handle
rth
;
struct
{
struct
nlmsghdr
n
;
struct
xfrm_usersa_info
xsinfo
;
char
buf
[
RTA_BUF_SIZE
];
char
buf
[
RTA_BUF_SIZE
];
}
req
;
struct
xfrm_replay_state
replay
;
struct
xfrm_replay_state_esn
replay_esn
;
...
...
@@ -356,7 +356,7 @@ static int xfrm_state_modify(int cmd, unsigned flags, int argc, char **argv)
}
else
if
(
strcmp
(
*
argv
,
"encap"
)
==
0
)
{
struct
xfrm_encap_tmpl
encap
;
inet_prefix
oa
;
NEXT_ARG
();
NEXT_ARG
();
xfrm_encap_type_parse
(
&
encap
.
encap_type
,
&
argc
,
&
argv
);
NEXT_ARG
();
if
(
get_u16
(
&
encap
.
encap_sport
,
*
argv
,
0
))
...
...
@@ -408,6 +408,7 @@ static int xfrm_state_modify(int cmd, unsigned flags, int argc, char **argv)
}
else
{
/* try to assume ALGO */
int
type
=
xfrm_algotype_getbyname
(
*
argv
);
switch
(
type
)
{
case
XFRMA_ALG_AEAD
:
case
XFRMA_ALG_CRYPT
:
...
...
@@ -701,7 +702,7 @@ static int xfrm_state_allocspi(int argc, char **argv)
struct
{
struct
nlmsghdr
n
;
struct
xfrm_userspi_info
xspi
;
char
buf
[
RTA_BUF_SIZE
];
char
buf
[
RTA_BUF_SIZE
];
}
req
;
char
*
idp
=
NULL
;
char
*
minp
=
NULL
;
...
...
@@ -827,7 +828,7 @@ static int xfrm_state_allocspi(int argc, char **argv)
if
(
rtnl_talk
(
&
rth
,
&
req
.
n
,
res_n
,
sizeof
(
res_buf
))
<
0
)
exit
(
2
);
if
(
xfrm_state_print
(
NULL
,
res_n
,
(
void
*
)
stdout
)
<
0
)
{
if
(
xfrm_state_print
(
NULL
,
res_n
,
(
void
*
)
stdout
)
<
0
)
{
fprintf
(
stderr
,
"An error :-)
\n
"
);
exit
(
1
);
}
...
...
@@ -868,9 +869,9 @@ static int xfrm_state_filter_match(struct xfrm_usersa_info *xsinfo)
int
xfrm_state_print
(
const
struct
sockaddr_nl
*
who
,
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
rtattr
*
tb
[
XFRMA_MAX
+
1
];
struct
rtattr
*
rta
;
FILE
*
fp
=
(
FILE
*
)
arg
;
struct
rtattr
*
tb
[
XFRMA_MAX
+
1
];
struct
rtattr
*
rta
;
struct
xfrm_usersa_info
*
xsinfo
=
NULL
;
struct
xfrm_user_expire
*
xexp
=
NULL
;
struct
xfrm_usersa_id
*
xsid
=
NULL
;
...
...
@@ -924,7 +925,7 @@ int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
parse_rtattr
(
tb
,
XFRMA_MAX
,
rta
,
len
);
if
(
n
->
nlmsg_type
==
XFRM_MSG_DELSA
)
{
/
/xfrm_policy_id_print();
/
* xfrm_policy_id_print(); */
if
(
!
tb
[
XFRMA_SA
])
{
fprintf
(
stderr
,
"Buggy XFRM_MSG_DELSA: no XFRMA_SA
\n
"
);
...
...
@@ -958,7 +959,7 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete)
struct
{
struct
nlmsghdr
n
;
struct
xfrm_usersa_id
xsid
;
char
buf
[
RTA_BUF_SIZE
];
char
buf
[
RTA_BUF_SIZE
];
}
req
;
struct
xfrm_id
id
;
char
*
idp
=
NULL
;
...
...
@@ -1025,7 +1026,7 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete)
if
(
rtnl_talk
(
&
rth
,
&
req
.
n
,
res_n
,
sizeof
(
req
))
<
0
)
exit
(
2
);
if
(
xfrm_state_print
(
NULL
,
res_n
,
(
void
*
)
stdout
)
<
0
)
{
if
(
xfrm_state_print
(
NULL
,
res_n
,
(
void
*
)
stdout
)
<
0
)
{
fprintf
(
stderr
,
"An error :-)
\n
"
);
exit
(
1
);
}
...
...
@@ -1087,7 +1088,7 @@ static int xfrm_state_keep(const struct sockaddr_nl *who,
sizeof
(
xsid
->
daddr
));
xb
->
offset
+=
new_n
->
nlmsg_len
;
xb
->
nlmsg_count
++
;
xb
->
nlmsg_count
++
;
return
0
;
}
...
...
@@ -1097,7 +1098,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall)
char
*
idp
=
NULL
;
struct
rtnl_handle
rth
;
if
(
argc
>
0
)
if
(
argc
>
0
)
filter
.
use
=
1
;
filter
.
xsinfo
.
family
=
preferred_family
;
...
...
@@ -1231,7 +1232,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall)
static
int
print_sadinfo
(
struct
nlmsghdr
*
n
,
void
*
arg
)
{
FILE
*
fp
=
(
FILE
*
)
arg
;
FILE
*
fp
=
(
FILE
*
)
arg
;
__u32
*
f
=
NLMSG_DATA
(
n
);
struct
rtattr
*
tb
[
XFRMA_SAD_MAX
+
1
];
struct
rtattr
*
rta
;
...
...
@@ -1249,11 +1250,11 @@ static int print_sadinfo(struct nlmsghdr *n, void *arg)
parse_rtattr
(
tb
,
XFRMA_SAD_MAX
,
rta
,
len
);
if
(
tb
[
XFRMA_SAD_CNT
])
{
fprintf
(
fp
,
"
\t
SAD"
);
fprintf
(
fp
,
"
\t
SAD"
);
cnt
=
(
__u32
*
)
RTA_DATA
(
tb
[
XFRMA_SAD_CNT
]);
fprintf
(
fp
,
" count %d"
,
*
cnt
);
fprintf
(
fp
,
" count %d"
,
*
cnt
);
}
else
{
fprintf
(
fp
,
"BAD SAD info returned
\n
"
);
fprintf
(
fp
,
"BAD SAD info returned
\n
"
);
return
-
1
;
}
...
...
@@ -1262,20 +1263,20 @@ static int print_sadinfo(struct nlmsghdr *n, void *arg)
struct
xfrmu_sadhinfo
*
si
;
if
(
RTA_PAYLOAD
(
tb
[
XFRMA_SAD_HINFO
])
<
sizeof
(
*
si
))
{
fprintf
(
fp
,
"BAD SAD length returned
\n
"
);
fprintf
(
fp
,
"BAD SAD length returned
\n
"
);
return
-
1
;
}
si
=
RTA_DATA
(
tb
[
XFRMA_SAD_HINFO
]);
fprintf
(
fp
,
" (buckets "
);
fprintf
(
fp
,
"count %d"
,
si
->
sadhcnt
);
fprintf
(
fp
,
" Max %d"
,
si
->
sadhmcnt
);
fprintf
(
fp
,
")"
);
fprintf
(
fp
,
" (buckets "
);
fprintf
(
fp
,
"count %d"
,
si
->
sadhcnt
);
fprintf
(
fp
,
" Max %d"
,
si
->
sadhmcnt
);
fprintf
(
fp
,
")"
);
}
}
fprintf
(
fp
,
"
\n
"
);
fprintf
(
fp
,
"
\n
"
);
return
0
;
return
0
;
}
static
int
xfrm_sad_getinfo
(
int
argc
,
char
**
argv
)
...
...
@@ -1299,7 +1300,7 @@ static int xfrm_sad_getinfo(int argc, char **argv)
if
(
rtnl_talk
(
&
rth
,
&
req
.
n
,
&
req
.
n
,
sizeof
(
req
))
<
0
)
exit
(
2
);
print_sadinfo
(
&
req
.
n
,
(
void
*
)
stdout
);
print_sadinfo
(
&
req
.
n
,
(
void
*
)
stdout
);
rtnl_close
(
&
rth
);
...
...
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