Skip to content

Commit f8c1f96

Browse files
committed
netlink: set LINUX_RTM_NEWADDR and LINUX_RTM_NEWNEIGH on responses
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]>
1 parent 3f49602 commit f8c1f96

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

bsd/sys/compat/linux/linux_netlink.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ netlink_process_getaddr_msg(struct socket *so, struct nlmsghdr *nlm)
588588
if (!ifa->ifa_addr)
589589
continue;
590590

591-
nlh = nlmsg_begin(m, nlm->nlmsg_pid, nlm->nlmsg_seq, LINUX_RTM_GETADDR, sizeof(*ifm), nlm->nlmsg_flags);
591+
nlh = nlmsg_begin(m, nlm->nlmsg_pid, nlm->nlmsg_seq, LINUX_RTM_NEWADDR, sizeof(*ifm), nlm->nlmsg_flags);
592592
if (!nlh) {
593593
error = ENOBUFS;
594594
goto done;
@@ -720,7 +720,7 @@ netlink_getneigh_lle_cb(struct lltable *llt, struct llentry *lle, void *data)
720720
struct nlmsghdr *nlm = cbdata->nlm;
721721
struct mbuf *m = cbdata->m;
722722
struct ndmsg *ndm;
723-
struct nlmsghdr *nlh = nlmsg_begin(m, nlm->nlmsg_pid, nlm->nlmsg_seq, LINUX_RTM_GETNEIGH, sizeof(*ndm), nlm->nlmsg_flags);
723+
struct nlmsghdr *nlh = nlmsg_begin(m, nlm->nlmsg_pid, nlm->nlmsg_seq, LINUX_RTM_NEWNEIGH, sizeof(*ndm), nlm->nlmsg_flags);
724724

725725
if (!nlh) {
726726
return ENOBUFS;
@@ -753,7 +753,7 @@ netlink_getneigh_lle_cb(struct lltable *llt, struct llentry *lle, void *data)
753753
}
754754
}
755755
#endif
756-
756+
757757
if (nla_put(m, NDA_LLADDR, 6, lle->ll_addr.mac16)) {
758758
return ENOBUFS;
759759
}
@@ -875,29 +875,29 @@ extern struct domain netlinkdomain; /* or at least forward */
875875

876876
static struct protosw netlinksw[] = {
877877
initialize_with([] (protosw& x) {
878-
x.pr_type = SOCK_RAW;
878+
x.pr_type = SOCK_RAW;
879879
x.pr_domain = &netlinkdomain;
880880
x.pr_flags = PR_ATOMIC|PR_ADDR;
881881
x.pr_output = netlink_output;
882882
x.pr_ctlinput = raw_ctlinput;
883-
x.pr_init = raw_init;
883+
x.pr_init = raw_init;
884884
x.pr_usrreqs = &netlink_usrreqs;
885885
}),
886886
initialize_with([] (protosw& x) {
887-
x.pr_type = SOCK_DGRAM;
887+
x.pr_type = SOCK_DGRAM;
888888
x.pr_domain = &netlinkdomain;
889889
x.pr_flags = PR_ATOMIC|PR_ADDR;
890890
x.pr_output = netlink_output;
891891
x.pr_ctlinput = raw_ctlinput;
892-
x.pr_init = raw_init;
892+
x.pr_init = raw_init;
893893
x.pr_usrreqs = &netlink_usrreqs;
894894
}),
895895
};
896896

897897
struct domain netlinkdomain = initialize_with([] (domain& x) {
898-
x.dom_family = PF_NETLINK;
899-
x.dom_name = "netlink";
900-
x.dom_protosw = netlinksw;
898+
x.dom_family = PF_NETLINK;
899+
x.dom_name = "netlink";
900+
x.dom_protosw = netlinksw;
901901
x.dom_protoswNPROTOSW = &netlinksw[sizeof(netlinksw)/sizeof(netlinksw[0])];
902902
});
903903

0 commit comments

Comments
 (0)