Skip to content

Commit

Permalink
netlink: set LINUX_RTM_NEWADDR and LINUX_RTM_NEWNEIGH on responses
Browse files Browse the repository at this point in the history
This patch fixes a minor bug in handling RTM_GETADDR and RTM_GETNEIGH
requests. It tweaks the relevant code to set the RTM_NEWADDR and RTM_NEWNEIGH
type for the responses respectively.

This is important as for example Golang runtime tests the nlmsg_type of
the netlink response and breaks if it is wrong.

Signed-off-by: Waldemar Kozaczuk <[email protected]>
  • Loading branch information
wkozaczuk committed Jun 13, 2022
1 parent 3f49602 commit f8c1f96
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions bsd/sys/compat/linux/linux_netlink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ netlink_process_getaddr_msg(struct socket *so, struct nlmsghdr *nlm)
if (!ifa->ifa_addr)
continue;

nlh = nlmsg_begin(m, nlm->nlmsg_pid, nlm->nlmsg_seq, LINUX_RTM_GETADDR, sizeof(*ifm), nlm->nlmsg_flags);
nlh = nlmsg_begin(m, nlm->nlmsg_pid, nlm->nlmsg_seq, LINUX_RTM_NEWADDR, sizeof(*ifm), nlm->nlmsg_flags);
if (!nlh) {
error = ENOBUFS;
goto done;
Expand Down Expand Up @@ -720,7 +720,7 @@ netlink_getneigh_lle_cb(struct lltable *llt, struct llentry *lle, void *data)
struct nlmsghdr *nlm = cbdata->nlm;
struct mbuf *m = cbdata->m;
struct ndmsg *ndm;
struct nlmsghdr *nlh = nlmsg_begin(m, nlm->nlmsg_pid, nlm->nlmsg_seq, LINUX_RTM_GETNEIGH, sizeof(*ndm), nlm->nlmsg_flags);
struct nlmsghdr *nlh = nlmsg_begin(m, nlm->nlmsg_pid, nlm->nlmsg_seq, LINUX_RTM_NEWNEIGH, sizeof(*ndm), nlm->nlmsg_flags);

if (!nlh) {
return ENOBUFS;
Expand Down Expand Up @@ -753,7 +753,7 @@ netlink_getneigh_lle_cb(struct lltable *llt, struct llentry *lle, void *data)
}
}
#endif

if (nla_put(m, NDA_LLADDR, 6, lle->ll_addr.mac16)) {
return ENOBUFS;
}
Expand Down Expand Up @@ -875,29 +875,29 @@ extern struct domain netlinkdomain; /* or at least forward */

static struct protosw netlinksw[] = {
initialize_with([] (protosw& x) {
x.pr_type = SOCK_RAW;
x.pr_type = SOCK_RAW;
x.pr_domain = &netlinkdomain;
x.pr_flags = PR_ATOMIC|PR_ADDR;
x.pr_output = netlink_output;
x.pr_ctlinput = raw_ctlinput;
x.pr_init = raw_init;
x.pr_init = raw_init;
x.pr_usrreqs = &netlink_usrreqs;
}),
initialize_with([] (protosw& x) {
x.pr_type = SOCK_DGRAM;
x.pr_type = SOCK_DGRAM;
x.pr_domain = &netlinkdomain;
x.pr_flags = PR_ATOMIC|PR_ADDR;
x.pr_output = netlink_output;
x.pr_ctlinput = raw_ctlinput;
x.pr_init = raw_init;
x.pr_init = raw_init;
x.pr_usrreqs = &netlink_usrreqs;
}),
};

struct domain netlinkdomain = initialize_with([] (domain& x) {
x.dom_family = PF_NETLINK;
x.dom_name = "netlink";
x.dom_protosw = netlinksw;
x.dom_family = PF_NETLINK;
x.dom_name = "netlink";
x.dom_protosw = netlinksw;
x.dom_protoswNPROTOSW = &netlinksw[sizeof(netlinksw)/sizeof(netlinksw[0])];
});

Expand Down

0 comments on commit f8c1f96

Please sign in to comment.