git: afbff46b9bc2 - stable/13 - netlink: fix non-default builds (no INET, INET6, ROUTE_MPATH).

From: Alexander V. Chernikov <melifaro_at_FreeBSD.org>
Date: Mon, 23 Jan 2023 22:11:47 UTC
The branch stable/13 has been updated by melifaro:

URL: https://cgit.FreeBSD.org/src/commit/?id=afbff46b9bc2ed3a3495d1b09da898dfaada292a

commit afbff46b9bc2ed3a3495d1b09da898dfaada292a
Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2022-10-02 13:02:24 +0000
Commit:     Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2023-01-23 22:04:02 +0000

    netlink: fix non-default builds (no INET, INET6, ROUTE_MPATH).
    
    (cherry picked from commit 356724fc931f4af1ed992a24f114070b14bb430a)
---
 sys/netlink/route/neigh.c   |  4 ++--
 sys/netlink/route/nexthop.c |  8 ++++++--
 sys/netlink/route/route.c   | 20 +++++++++++++++++---
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/sys/netlink/route/neigh.c b/sys/netlink/route/neigh.c
index 73844398d26d..44245e14b6b6 100644
--- a/sys/netlink/route/neigh.c
+++ b/sys/netlink/route/neigh.c
@@ -344,8 +344,8 @@ rtnl_handle_newneigh(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *
 	int addrlen = attrs.nda_ifp->if_addrlen;
 	if (attrs.nda_lladdr->nla_len != sizeof(struct nlattr) + addrlen) {
 		NLMSG_REPORT_ERR_MSG(npt,
-		    "NDA_LLADDR address length (%ld) is different from expected (%d)",
-		    attrs.nda_lladdr->nla_len - sizeof(struct nlattr), addrlen);
+		    "NDA_LLADDR address length (%d) is different from expected (%d)",
+		    (int)attrs.nda_lladdr->nla_len - (int)sizeof(struct nlattr), addrlen);
 		return (EINVAL);
 	}
 
diff --git a/sys/netlink/route/nexthop.c b/sys/netlink/route/nexthop.c
index 77be3a612641..31816d84f189 100644
--- a/sys/netlink/route/nexthop.c
+++ b/sys/netlink/route/nexthop.c
@@ -29,6 +29,7 @@
 __FBSDID("$FreeBSD$");
 #include "opt_inet.h"
 #include "opt_inet6.h"
+#include "opt_route.h"
 #include <sys/types.h>
 #include <sys/ck.h>
 #include <sys/kernel.h>
@@ -268,10 +269,12 @@ nl_find_base_unhop(struct unhop_ctl *ctl, uint32_t uidx)
 static struct nhop_object *
 clone_unhop(const struct user_nhop *unhop, uint32_t fibnum, int family, int nh_flags)
 {
+#ifdef ROUTE_MPATH
 	const struct weightened_nhop *wn;
 	struct weightened_nhop *wn_new, wn_base[MAX_STACK_NHOPS];
-	struct nhop_object *nh = NULL;
 	uint32_t num_nhops;
+#endif
+	struct nhop_object *nh = NULL;
 	int error;
 
 	if (unhop->un_nhop_src != NULL) {
@@ -296,7 +299,7 @@ clone_unhop(const struct user_nhop *unhop, uint32_t fibnum, int family, int nh_f
 		nhop_set_pxtype_flag(nh, nh_flags);
 		return (nhop_get_nhop(nh, &error));
 	}
-
+#ifdef ROUTE_MPATH
 	wn = unhop->un_nhgrp_src;
 	num_nhops = unhop->un_nhgrp_count;
 
@@ -326,6 +329,7 @@ clone_unhop(const struct user_nhop *unhop, uint32_t fibnum, int family, int nh_f
 
 	if (wn_new != wn_base)
 		free(wn_new, M_TEMP);
+#endif
 	return (nh);
 }
 
diff --git a/sys/netlink/route/route.c b/sys/netlink/route/route.c
index 7573b371155e..63489dc8173a 100644
--- a/sys/netlink/route/route.c
+++ b/sys/netlink/route/route.c
@@ -67,6 +67,7 @@ get_rtm_type(const struct nhop_object *nh)
 static uint8_t
 nl_get_rtm_protocol(const struct nhop_object *nh)
 {
+#ifdef ROUTE_MPATH
 	if (NH_IS_NHGRP(nh)) {
 		const struct nhgrp_object *nhg = (const struct nhgrp_object *)nh;
 		uint8_t origin = nhgrp_get_origin(nhg);
@@ -74,6 +75,7 @@ nl_get_rtm_protocol(const struct nhop_object *nh)
 			return (origin);
 		nh = nhg->nhops[0];
 	}
+#endif
 	uint8_t origin = nhop_get_origin(nh);
 	if (origin != RTPROT_UNSPEC)
 		return (origin);
@@ -162,6 +164,7 @@ dump_rc_nhop_mtu(struct nl_writer *nw, const struct nhop_object *nh)
 	*((uint32_t *)(nla + 1)) = nh->nh_mtu;
 }
 
+#ifdef ROUTE_MPATH
 static void
 dump_rc_nhg(struct nl_writer *nw, const struct nhgrp_object *nhg, struct rtmsg *rtm)
 {
@@ -201,15 +204,17 @@ dump_rc_nhg(struct nl_writer *nw, const struct nhgrp_object *nhg, struct rtmsg *
 	}
 	nlattr_set_len(nw, off);
 }
+#endif
 
 static void
 dump_rc_nhop(struct nl_writer *nw, const struct nhop_object *nh, struct rtmsg *rtm)
 {
+#ifdef ROUTE_MPATH
 	if (NH_IS_NHGRP(nh)) {
 		dump_rc_nhg(nw, (const struct nhgrp_object *)nh, rtm);
 		return;
 	}
-
+#endif
 	uint32_t rtflags = nhop_get_rtflags(nh);
 
 	/*
@@ -279,6 +284,7 @@ dump_px(uint32_t fibnum, const struct nlmsghdr *hdr,
 	int plen = 0;
 	uint32_t scopeid = 0;
 	switch (family) {
+#ifdef INET
 	case AF_INET:
 		{
 			struct in_addr addr;
@@ -286,6 +292,8 @@ dump_px(uint32_t fibnum, const struct nlmsghdr *hdr,
 			nlattr_add(nw, NL_RTA_DST, 4, &addr);
 			break;
 		}
+#endif
+#ifdef INET6
 	case AF_INET6:
 		{
 			struct in6_addr addr;
@@ -293,6 +301,7 @@ dump_px(uint32_t fibnum, const struct nlmsghdr *hdr,
 			nlattr_add(nw, NL_RTA_DST, 16, &addr);
 			break;
 		}
+#endif
 	default:
 		FIB_LOG(LOG_NOTICE, fibnum, family, "unsupported rt family: %d", family);
 		error = EAFNOSUPPORT;
@@ -707,6 +716,7 @@ get_op_flags(int nlm_flags)
 	return (op_flags);
 }
 
+#ifdef ROUTE_MPATH
 static int
 create_nexthop_one(struct nl_parsed_route *attrs, struct rta_mpath_nh *mpnh,
     struct nl_pstate *npt, struct nhop_object **pnh)
@@ -729,19 +739,20 @@ create_nexthop_one(struct nl_parsed_route *attrs, struct rta_mpath_nh *mpnh,
 
 	return (error);
 }
+#endif
 
 static struct nhop_object *
 create_nexthop_from_attrs(struct nl_parsed_route *attrs,
     struct nl_pstate *npt, int *perror)
 {
-	struct nhop_object *nh;
+	struct nhop_object *nh = NULL;
 	int error = 0;
 
 	if (attrs->rta_multipath != NULL) {
+#ifdef ROUTE_MPATH
 		/* Multipath w/o explicit nexthops */
 		int num_nhops = attrs->rta_multipath->num_nhops;
 		struct weightened_nhop *wn = npt_alloc(npt, sizeof(*wn) * num_nhops);
-		nh = NULL;
 
 		for (int i = 0; i < num_nhops; i++) {
 			struct rta_mpath_nh *mpnh = &attrs->rta_multipath->nhops[i];
@@ -763,6 +774,9 @@ create_nexthop_from_attrs(struct nl_parsed_route *attrs,
 			for (int i = 0; i < num_nhops; i++)
 				nhop_free(wn[i].nh);
 		}
+#else
+		error = ENOTSUP;
+#endif
 		*perror = error;
 	} else {
 		nh = nhop_alloc(attrs->rta_table, attrs->rtm_family);