Make the netlink link flags and router setting code work properly.
MTU setting still needs some fixes; it sets the link mtu correctly, but has a bad interaction with the hardware link status detection.
This commit is contained in:
parent
d2f413d46e
commit
d8e3dc61ea
54
ndhc/ifset.c
54
ndhc/ifset.c
@ -145,22 +145,19 @@ static ssize_t rtnl_do_send(int fd, uint8_t *sbuf, size_t slen,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
const struct nlmsghdr *nlh = (const struct nlmsghdr *)response;
|
const struct nlmsghdr *nlh = (const struct nlmsghdr *)response;
|
||||||
switch (nlh->nlmsg_type) {
|
if (nlh->nlmsg_type == NLMSG_ERROR) {
|
||||||
case NLMSG_ERROR:
|
if (nlmsg_get_error(nlh) == 0)
|
||||||
|
return 0;
|
||||||
|
else {
|
||||||
log_line("%s: (%s) netlink sendto returned NLMSG_ERROR: %s",
|
log_line("%s: (%s) netlink sendto returned NLMSG_ERROR: %s",
|
||||||
client_config.interface, fnname,
|
client_config.interface, fnname,
|
||||||
strerror(nlmsg_get_error(nlh)));
|
strerror(nlmsg_get_error(nlh)));
|
||||||
return -1;
|
return -1;
|
||||||
case NLMSG_DONE:
|
|
||||||
return 0;
|
|
||||||
case NLMSG_OVERRUN:
|
|
||||||
log_line("%s: (%s) Received a NLMSG_OVERRUN.",
|
|
||||||
client_config.interface, __func__);
|
|
||||||
case NLMSG_NOOP:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return 0;
|
}
|
||||||
|
log_line("%s: (%s) netlink sendto returned an error.",
|
||||||
|
client_config.interface, __func__);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t rtnl_if_flags_send(int fd, int type, int ifi_flags)
|
static ssize_t rtnl_if_flags_send(int fd, int type, int ifi_flags)
|
||||||
@ -174,7 +171,7 @@ static ssize_t rtnl_if_flags_send(int fd, int type, int ifi_flags)
|
|||||||
header = (struct nlmsghdr *)request;
|
header = (struct nlmsghdr *)request;
|
||||||
header->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
header->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
||||||
header->nlmsg_type = type;
|
header->nlmsg_type = type;
|
||||||
header->nlmsg_flags = NLM_F_REPLACE | NLM_F_ACK | NLM_F_REQUEST;
|
header->nlmsg_flags = NLM_F_ACK | NLM_F_REQUEST;
|
||||||
header->nlmsg_seq = ifset_nl_seq++;
|
header->nlmsg_seq = ifset_nl_seq++;
|
||||||
|
|
||||||
ifinfomsg = NLMSG_DATA(header);
|
ifinfomsg = NLMSG_DATA(header);
|
||||||
@ -189,7 +186,7 @@ static ssize_t rtnl_if_mtu_set(int fd, unsigned int mtu)
|
|||||||
{
|
{
|
||||||
uint8_t request[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
|
uint8_t request[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
|
||||||
NLMSG_ALIGN(sizeof(struct ifinfomsg)) +
|
NLMSG_ALIGN(sizeof(struct ifinfomsg)) +
|
||||||
RTA_LENGTH(sizeof(uint32_t))];
|
RTA_LENGTH(sizeof(unsigned int))];
|
||||||
struct nlmsghdr *header;
|
struct nlmsghdr *header;
|
||||||
struct ifinfomsg *ifinfomsg;
|
struct ifinfomsg *ifinfomsg;
|
||||||
|
|
||||||
@ -197,7 +194,7 @@ static ssize_t rtnl_if_mtu_set(int fd, unsigned int mtu)
|
|||||||
header = (struct nlmsghdr *)request;
|
header = (struct nlmsghdr *)request;
|
||||||
header->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
header->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
||||||
header->nlmsg_type = RTM_SETLINK;
|
header->nlmsg_type = RTM_SETLINK;
|
||||||
header->nlmsg_flags = NLM_F_REPLACE | NLM_F_ACK | NLM_F_REQUEST;
|
header->nlmsg_flags = NLM_F_ACK | NLM_F_REQUEST;
|
||||||
header->nlmsg_seq = ifset_nl_seq++;
|
header->nlmsg_seq = ifset_nl_seq++;
|
||||||
|
|
||||||
ifinfomsg = NLMSG_DATA(header);
|
ifinfomsg = NLMSG_DATA(header);
|
||||||
@ -267,8 +264,9 @@ static ssize_t rtnl_addr_broadcast_send(int fd, int type, int ifa_flags,
|
|||||||
static ssize_t rtnl_set_default_gw_v4(int fd, uint32_t gw4, int metric)
|
static ssize_t rtnl_set_default_gw_v4(int fd, uint32_t gw4, int metric)
|
||||||
{
|
{
|
||||||
uint8_t request[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
|
uint8_t request[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
|
||||||
NLMSG_ALIGN(sizeof(struct ifinfomsg)) +
|
NLMSG_ALIGN(sizeof(struct rtmsg)) +
|
||||||
RTA_LENGTH(sizeof(uint32_t))];
|
3 * RTA_LENGTH(sizeof(struct in6_addr)) +
|
||||||
|
RTA_LENGTH(sizeof(int))];
|
||||||
struct nlmsghdr *header;
|
struct nlmsghdr *header;
|
||||||
struct rtmsg *rtmsg;
|
struct rtmsg *rtmsg;
|
||||||
|
|
||||||
@ -276,13 +274,13 @@ static ssize_t rtnl_set_default_gw_v4(int fd, uint32_t gw4, int metric)
|
|||||||
header = (struct nlmsghdr *)request;
|
header = (struct nlmsghdr *)request;
|
||||||
header->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
|
header->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
|
||||||
header->nlmsg_type = RTM_NEWROUTE;
|
header->nlmsg_type = RTM_NEWROUTE;
|
||||||
header->nlmsg_flags = NLM_F_REPLACE | NLM_F_ACK | NLM_F_REQUEST;
|
header->nlmsg_flags = NLM_F_CREATE | NLM_F_REPLACE | NLM_F_ACK
|
||||||
|
| NLM_F_REQUEST;
|
||||||
header->nlmsg_seq = ifset_nl_seq++;
|
header->nlmsg_seq = ifset_nl_seq++;
|
||||||
|
|
||||||
rtmsg = NLMSG_DATA(header);
|
rtmsg = NLMSG_DATA(header);
|
||||||
rtmsg->rtm_family = AF_INET;
|
rtmsg->rtm_family = AF_INET;
|
||||||
rtmsg->rtm_table = RT_TABLE_DEFAULT;
|
rtmsg->rtm_protocol = RTPROT_DHCP;
|
||||||
rtmsg->rtm_protocol = RTPROT_STATIC;
|
|
||||||
rtmsg->rtm_scope = RT_SCOPE_UNIVERSE;
|
rtmsg->rtm_scope = RT_SCOPE_UNIVERSE;
|
||||||
rtmsg->rtm_type = RTN_UNICAST;
|
rtmsg->rtm_type = RTN_UNICAST;
|
||||||
|
|
||||||
@ -306,12 +304,14 @@ static ssize_t rtnl_set_default_gw_v4(int fd, uint32_t gw4, int metric)
|
|||||||
client_config.interface, __func__);
|
client_config.interface, __func__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (nl_add_rtattr(header, sizeof request, RTA_METRICS,
|
if (metric > 0) {
|
||||||
|
if (nl_add_rtattr(header, sizeof request, RTA_PRIORITY,
|
||||||
&metric, sizeof metric) < 0) {
|
&metric, sizeof metric) < 0) {
|
||||||
log_line("%s: (%s) couldn't add RTA_METRICS to nlmsg",
|
log_line("%s: (%s) couldn't add RTA_PRIORITY to nlmsg",
|
||||||
client_config.interface, __func__);
|
client_config.interface, __func__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return rtnl_do_send(fd, request, header->nlmsg_len, __func__);
|
return rtnl_do_send(fd, request, header->nlmsg_len, __func__);
|
||||||
}
|
}
|
||||||
@ -573,14 +573,16 @@ void perform_router(const char *str_router, size_t len)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: Probably need to clear out the old default gw.
|
if (rtnl_set_default_gw_v4(fd, router.s_addr, 0) < 0)
|
||||||
|
|
||||||
if (rtnl_set_default_gw_v4(fd, router.s_addr, 1) < 0)
|
|
||||||
log_line("%s: (%s) failed to set route: %s",
|
log_line("%s: (%s) failed to set route: %s",
|
||||||
client_config.interface, __func__, strerror(errno));
|
client_config.interface, __func__, strerror(errno));
|
||||||
else
|
else
|
||||||
log_line("Gateway router set to: '%s'", str_router);
|
log_line("Gateway router set to: '%s'", str_router);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
//static char xxxz[] = "1500";
|
||||||
|
//perform_mtu(xxxz, sizeof xxxz);
|
||||||
}
|
}
|
||||||
|
|
||||||
void perform_mtu(const char *str, size_t len)
|
void perform_mtu(const char *str, size_t len)
|
||||||
@ -602,8 +604,8 @@ void perform_mtu(const char *str, size_t len)
|
|||||||
client_config.interface, __func__);
|
client_config.interface, __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (tmtu > UINT_MAX) {
|
if (tmtu > INT_MAX) {
|
||||||
log_line("%s: (%s) provided mtu arg would overflow unsigned int",
|
log_line("%s: (%s) provided mtu arg would overflow int",
|
||||||
client_config.interface, __func__);
|
client_config.interface, __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user