route: try to autoload netlink(4) module if not present in the kernel.
Differential Revision: https://reviews.freebsd.org/D39324
This commit is contained in:
parent
f5a365e51f
commit
140ddeba08
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include <sys/bitcount.h>
|
#include <sys/bitcount.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
#include <sys/linker.h>
|
||||||
|
#include <sys/module.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@ -90,6 +92,23 @@ get_netmask(struct snl_state *ss, int family, int plen)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
nl_init_socket(struct snl_state *ss)
|
||||||
|
{
|
||||||
|
if (snl_init(ss, NETLINK_ROUTE))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (modfind("netlink") == -1 && errno == ENOENT) {
|
||||||
|
/* Try to load */
|
||||||
|
if (kldload("netlink") == -1)
|
||||||
|
err(1, "netlink is not loaded and load attempt failed");
|
||||||
|
if (snl_init(ss, NETLINK_ROUTE))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
err(1, "unable to open netlink socket");
|
||||||
|
}
|
||||||
|
|
||||||
struct nl_helper {
|
struct nl_helper {
|
||||||
struct snl_state ss_cmd;
|
struct snl_state ss_cmd;
|
||||||
};
|
};
|
||||||
@ -97,8 +116,7 @@ struct nl_helper {
|
|||||||
static void
|
static void
|
||||||
nl_helper_init(struct nl_helper *h)
|
nl_helper_init(struct nl_helper *h)
|
||||||
{
|
{
|
||||||
if (!snl_init(&h->ss_cmd, NETLINK_ROUTE))
|
nl_init_socket(&h->ss_cmd);
|
||||||
err(1, "unable to open netlink socket");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -680,8 +698,7 @@ monitor_nl(int fib)
|
|||||||
struct snl_state ss_event = {};
|
struct snl_state ss_event = {};
|
||||||
struct nl_helper h;
|
struct nl_helper h;
|
||||||
|
|
||||||
if (!snl_init(&ss_event, NETLINK_ROUTE))
|
nl_init_socket(&ss_event);
|
||||||
err(1, "unable to open netlink socket");
|
|
||||||
nl_helper_init(&h);
|
nl_helper_init(&h);
|
||||||
|
|
||||||
int groups[] = {
|
int groups[] = {
|
||||||
@ -789,8 +806,7 @@ flushroutes_fib_nl(int fib, int af)
|
|||||||
struct snl_writer nw;
|
struct snl_writer nw;
|
||||||
struct nl_helper h = {};
|
struct nl_helper h = {};
|
||||||
|
|
||||||
if (!snl_init(&ss, NETLINK_ROUTE))
|
nl_init_socket(&ss);
|
||||||
err(1, "unable to open netlink socket");
|
|
||||||
snl_init_writer(&ss, &nw);
|
snl_init_writer(&ss, &nw);
|
||||||
|
|
||||||
struct nlmsghdr *hdr = snl_create_msg_request(&nw, NL_RTM_GETROUTE);
|
struct nlmsghdr *hdr = snl_create_msg_request(&nw, NL_RTM_GETROUTE);
|
||||||
|
Loading…
Reference in New Issue
Block a user