Page MenuHomeFreeBSD

D39324.id119660.diff
No OneTemporary

D39324.id119660.diff

diff --git a/sbin/route/route_netlink.c b/sbin/route/route_netlink.c
--- a/sbin/route/route_netlink.c
+++ b/sbin/route/route_netlink.c
@@ -6,6 +6,8 @@
#include <sys/bitcount.h>
#include <sys/param.h>
+#include <sys/linker.h>
+#include <sys/module.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/time.h>
@@ -90,6 +92,23 @@
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 snl_state ss_cmd;
};
@@ -97,8 +116,7 @@
static void
nl_helper_init(struct nl_helper *h)
{
- if (!snl_init(&h->ss_cmd, NETLINK_ROUTE))
- err(1, "unable to open netlink socket");
+ nl_init_socket(&h->ss_cmd);
}
static void
@@ -680,8 +698,7 @@
struct snl_state ss_event = {};
struct nl_helper h;
- if (!snl_init(&ss_event, NETLINK_ROUTE))
- err(1, "unable to open netlink socket");
+ nl_init_socket(&ss_event);
nl_helper_init(&h);
int groups[] = {
@@ -789,8 +806,7 @@
struct snl_writer nw;
struct nl_helper h = {};
- if (!snl_init(&ss, NETLINK_ROUTE))
- err(1, "unable to open netlink socket");
+ nl_init_socket(&ss);
snl_init_writer(&ss, &nw);
struct nlmsghdr *hdr = snl_create_msg_request(&nw, NL_RTM_GETROUTE);

File Metadata

Mime Type
text/plain
Expires
Tue, Mar 17, 12:56 PM (17 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29787552
Default Alt Text
D39324.id119660.diff (1 KB)

Event Timeline