mirror of
https://github.com/systemd/systemd.git
synced 2025-03-10 16:58:28 +03:00
rtnl: make checks for default routes more strict
Also check that the source netmask is 0, not only the destination netmask.
This commit is contained in:
parent
e9140aff75
commit
a98433c05c
@ -197,7 +197,7 @@ int local_gateways(sd_rtnl *context, int ifindex, struct local_address **ret) {
|
|||||||
for (m = reply; m; m = sd_rtnl_message_next(m)) {
|
for (m = reply; m; m = sd_rtnl_message_next(m)) {
|
||||||
struct local_address *a;
|
struct local_address *a;
|
||||||
uint16_t type;
|
uint16_t type;
|
||||||
unsigned char dst_len;
|
unsigned char dst_len, src_len;
|
||||||
uint32_t ifi;
|
uint32_t ifi;
|
||||||
|
|
||||||
r = sd_rtnl_message_get_errno(m);
|
r = sd_rtnl_message_get_errno(m);
|
||||||
@ -211,14 +211,19 @@ int local_gateways(sd_rtnl *context, int ifindex, struct local_address **ret) {
|
|||||||
if (type != RTM_NEWROUTE)
|
if (type != RTM_NEWROUTE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* We only care for default routes */
|
||||||
r = sd_rtnl_message_route_get_dst_len(m, &dst_len);
|
r = sd_rtnl_message_route_get_dst_len(m, &dst_len);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
/* We only care for default routes */
|
|
||||||
if (dst_len != 0)
|
if (dst_len != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
r = sd_rtnl_message_route_get_src_len(m, &src_len);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
if (src_len != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
r = sd_rtnl_message_read_u32(m, RTA_OIF, &ifi);
|
r = sd_rtnl_message_read_u32(m, RTA_OIF, &ifi);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
@ -158,6 +158,21 @@ int sd_rtnl_message_route_get_dst_len(sd_rtnl_message *m, unsigned char *dst_len
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sd_rtnl_message_route_get_src_len(sd_rtnl_message *m, unsigned char *src_len) {
|
||||||
|
struct rtmsg *rtm;
|
||||||
|
|
||||||
|
assert_return(m, -EINVAL);
|
||||||
|
assert_return(m->hdr, -EINVAL);
|
||||||
|
assert_return(rtnl_message_type_is_route(m->hdr->nlmsg_type), -EINVAL);
|
||||||
|
assert_return(src_len, -EINVAL);
|
||||||
|
|
||||||
|
rtm = NLMSG_DATA(m->hdr);
|
||||||
|
|
||||||
|
*src_len = rtm->rtm_src_len;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int sd_rtnl_message_new_route(sd_rtnl *rtnl, sd_rtnl_message **ret,
|
int sd_rtnl_message_new_route(sd_rtnl *rtnl, sd_rtnl_message **ret,
|
||||||
uint16_t nlmsg_type, int rtm_family,
|
uint16_t nlmsg_type, int rtm_family,
|
||||||
unsigned char rtm_protocol) {
|
unsigned char rtm_protocol) {
|
||||||
|
@ -105,6 +105,7 @@ int sd_rtnl_message_route_set_dst_prefixlen(sd_rtnl_message *m, unsigned char pr
|
|||||||
int sd_rtnl_message_route_set_scope(sd_rtnl_message *m, unsigned char scope);
|
int sd_rtnl_message_route_set_scope(sd_rtnl_message *m, unsigned char scope);
|
||||||
int sd_rtnl_message_route_get_family(sd_rtnl_message *m, int *family);
|
int sd_rtnl_message_route_get_family(sd_rtnl_message *m, int *family);
|
||||||
int sd_rtnl_message_route_get_dst_len(sd_rtnl_message *m, unsigned char *dst_len);
|
int sd_rtnl_message_route_get_dst_len(sd_rtnl_message *m, unsigned char *dst_len);
|
||||||
|
int sd_rtnl_message_route_get_src_len(sd_rtnl_message *m, unsigned char *src_len);
|
||||||
|
|
||||||
int sd_rtnl_message_neigh_get_family(sd_rtnl_message *m, int *family);
|
int sd_rtnl_message_neigh_get_family(sd_rtnl_message *m, int *family);
|
||||||
int sd_rtnl_message_neigh_get_ifindex(sd_rtnl_message *m, int *family);
|
int sd_rtnl_message_neigh_get_ifindex(sd_rtnl_message *m, int *family);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user