Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F163537031
D58294.id182123.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D58294.id182123.diff
View Options
diff --git a/sbin/route/keywords b/sbin/route/keywords
--- a/sbin/route/keywords
+++ b/sbin/route/keywords
@@ -36,6 +36,7 @@
nostick
osi
prefixlen
+prefsrc
proto1
proto2
proxy
diff --git a/sbin/route/route.c b/sbin/route/route.c
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -946,6 +946,7 @@
errx(EX_USAGE,
"invalid fib number: %s", *argv);
break;
+ case K_PREFSRC:
case K_IFA:
if (!--argc)
usage(NULL);
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
@@ -174,6 +174,7 @@
struct sockaddr *dst = get_addr(so, rtm_addrs, RTAX_DST);
struct sockaddr *mask = get_addr(so, rtm_addrs, RTAX_NETMASK);
struct sockaddr *gw = get_addr(so, rtm_addrs, RTAX_GATEWAY);
+ struct sockaddr *prefsrc = get_addr(so, rtm_addrs, RTAX_IFA);
if (dst == NULL)
return (EINVAL);
@@ -225,6 +226,7 @@
rtm->rtm_flags = RTM_F_PREFIX;
snl_add_msg_attr_ip(&nw, RTA_DST, dst);
+ snl_add_msg_attr_ip(&nw, RTA_PREFSRC, prefsrc);
snl_add_msg_attr_u32(&nw, RTA_TABLE, fib);
uint32_t rta_oif = 0;
diff --git a/sys/netlink/netlink_snl_route_parsers.h b/sys/netlink/netlink_snl_route_parsers.h
--- a/sys/netlink/netlink_snl_route_parsers.h
+++ b/sys/netlink/netlink_snl_route_parsers.h
@@ -113,6 +113,7 @@
struct snl_parsed_route {
struct sockaddr *rta_dst;
struct sockaddr *rta_gw;
+ struct sockaddr *rta_pref_src;
struct nlattr *rta_metrics;
struct rta_mpath rta_multipath;
uint32_t rta_oif;
@@ -142,6 +143,7 @@
{ .type = NL_RTA_OIF, .off = _OUT(rta_oif), .cb = snl_attr_get_uint32 },
{ .type = NL_RTA_GATEWAY, .off = _OUT(rta_gw), .cb = snl_attr_get_ip },
{ .type = NL_RTA_PRIORITY, .off = _OUT(rta_metric), .cb = snl_attr_get_uint32 },
+ { .type = NL_RTA_PREFSRC, .off = _OUT(rta_pref_src), .cb = snl_attr_get_ip },
{ .type = NL_RTA_METRICS, .arg = &_metrics_parser, .cb = snl_attr_get_nested },
{ .type = NL_RTA_MULTIPATH, .off = _OUT(rta_multipath), .cb = nlattr_get_multipath },
{ .type = NL_RTA_KNH_ID, .off = _OUT(rta_knh_id), .cb = snl_attr_get_uint32 },
diff --git a/sys/netlink/route/route.h b/sys/netlink/route/route.h
--- a/sys/netlink/route/route.h
+++ b/sys/netlink/route/route.h
@@ -145,12 +145,12 @@
enum rtattr_type_t {
NL_RTA_UNSPEC,
NL_RTA_DST = 1, /* binary, IPv4/IPv6 destination */
- NL_RTA_SRC = 2, /* binary, preferred source address */
+ NL_RTA_SRC = 2, /* not supported */
NL_RTA_IIF = 3, /* not supported */
NL_RTA_OIF = 4, /* u32, transmit ifindex */
NL_RTA_GATEWAY = 5, /* binary: IPv4/IPv6 gateway */
NL_RTA_PRIORITY = 6, /* u32, path metric */
- NL_RTA_PREFSRC = 7, /* not supported */
+ NL_RTA_PREFSRC = 7, /* binary, preferred source address */
NL_RTA_METRICS = 8, /* nested, list of NL_RTAX* attrs */
NL_RTA_MULTIPATH = 9, /* binary, array of struct rtnexthop */
NL_RTA_PROTOINFO = 10, /* not supported / deprecated */
@@ -200,6 +200,7 @@
#define RTA_GATEWAY NL_RTA_GATEWAY
#define RTA_PRIORITY NL_RTA_PRIORITY
#define RTA_PREFSRC NL_RTA_PREFSRC
+#define RTA_IFA NL_RTA_PREFSRC
#define RTA_METRICS NL_RTA_METRICS
#define RTA_MULTIPATH NL_RTA_MULTIPATH
#define RTA_PROTOINFO NL_RTA_PROTOINFO
diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c
--- a/sys/netlink/route/rt.c
+++ b/sys/netlink/route/rt.c
@@ -158,6 +158,29 @@
}
}
+static void
+dump_rc_nhop_prefsrc(struct nl_writer *nw, const struct nhop_object *nh)
+{
+ const struct ifaddr *ifa = nh->nh_ifa;
+#ifdef INET6
+ struct in6_addr in6;
+#endif
+
+ switch (ifa->ifa_addr->sa_family) {
+ case AF_INET:
+ nlattr_add(nw, NL_RTA_PREFSRC, 4,
+ &((struct sockaddr_in *)((ifa)->ifa_addr))->sin_addr);
+ break;
+#ifdef INET6
+ case AF_INET6:
+ in6 = ((struct sockaddr_in6 *)((ifa)->ifa_addr))->sin6_addr;
+ in6_clearscope(&in6);
+ nlattr_add(nw, NL_RTA_PREFSRC, 16, &in6);
+ break;
+#endif
+ }
+}
+
static void
dump_rc_nhop_mtu(struct nl_writer *nw, const struct nhop_object *nh)
{
@@ -193,6 +216,7 @@
if (nh->nh_flags & NHF_GATEWAY)
dump_rc_nhop_gw(nw, nh);
+ dump_rc_nhop_prefsrc(nw, nh);
wn = nhgrp_get_nhops(nhg, &num_nhops);
base_rtflags = nhop_get_rtflags(wn[0].nh);
uidx = nhgrp_get_uidx(nhg);
@@ -269,6 +293,7 @@
if (nh->nh_flags & NHF_GATEWAY)
dump_rc_nhop_gw(nw, nh);
+ dump_rc_nhop_prefsrc(nw, nh);
uidx = nhop_get_uidx(nh);
if (uidx != 0)
nlattr_add_u32(nw, NL_RTA_NH_ID, uidx);
@@ -518,6 +543,7 @@
struct nl_parsed_route {
struct sockaddr *rta_dst;
struct sockaddr *rta_gw;
+ struct sockaddr *rta_pref_src;
struct ifnet *rta_oif;
struct rta_mpath *rta_multipath;
uint32_t rta_table;
@@ -547,6 +573,7 @@
{ .type = NL_RTA_OIF, .off = _OUT(rta_oif), .cb = nlattr_get_ifp },
{ .type = NL_RTA_GATEWAY, .off = _OUT(rta_gw), .cb = nlattr_get_ip },
{ .type = NL_RTA_PRIORITY, .off = _OUT(rta_metric), .cb = nlattr_get_uint32 },
+ { .type = NL_RTA_PREFSRC, .off = _OUT(rta_pref_src), .cb = nlattr_get_ip },
{ .type = NL_RTA_METRICS, .arg = &metrics_parser, .cb = nlattr_get_nested },
{ .type = NL_RTA_MULTIPATH, .off = _OUT(rta_multipath), .cb = nlattr_get_multipath },
{ .type = NL_RTA_WEIGHT, .off = _OUT(rta_weight), .cb = nlattr_get_uint32 },
@@ -575,6 +602,7 @@
set_scope6(attrs->rta_dst, attrs->rta_oif);
set_scope6(attrs->rta_gw, attrs->rta_oif);
+ set_scope6(attrs->rta_pref_src, attrs->rta_oif);
return (true);
}
NL_DECLARE_PARSER_EXT(rtm_parser, struct rtmsg, NULL, nlf_p_rtmsg, nla_p_rtmsg, post_p_rtmsg);
@@ -873,6 +901,16 @@
}
if (mpnh->ifp != NULL)
nhop_set_transmit_ifp(nh, mpnh->ifp);
+ if (attrs->rta_pref_src != NULL) {
+ struct ifaddr *ifa = NULL;
+ if (mpnh->ifp != NULL)
+ ifa = ifaof_ifpforaddr(attrs->rta_pref_src, mpnh->ifp);
+ else
+ ifa = ifa_ifwithaddr(attrs->rta_pref_src);
+ if (ifa == NULL)
+ return (EINVAL);
+ nhop_set_src(nh, ifa);
+ }
nhop_set_pxtype_flag(nh, get_pxflag(attrs));
nhop_set_rtflags(nh, attrs->rta_rtflags);
nhop_set_metric(nh, attrs->rta_metric);
@@ -943,6 +981,18 @@
return (NULL);
}
}
+ if (attrs->rta_pref_src != NULL) {
+ struct ifaddr *ifa = NULL;
+ if (nh->nh_ifp != NULL)
+ ifa = ifaof_ifpforaddr(attrs->rta_pref_src, nh->nh_ifp);
+ else
+ ifa = ifa_ifwithaddr(attrs->rta_pref_src);
+ if (ifa == NULL) {
+ *perror = EINVAL;
+ return (NULL);
+ }
+ nhop_set_src(nh, ifa);
+ }
if (attrs->rta_oif != NULL)
nhop_set_transmit_ifp(nh, attrs->rta_oif);
if (attrs->rtax_mtu != 0)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jul 25, 6:19 AM (8 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35465066
Default Alt Text
D58294.id182123.diff (6 KB)
Attached To
Mode
D58294: netlink: Add RTA_PREFSRC support
Attached
Detach File
Event Timeline
Log In to Comment