History

net: mctp: add gateway routing support

This change allows for gateway routing, where a route table entry may reference a routable endpoint (by network and EID), instead of routing directly to a netdevice. We add support for a RTM_GATEWAY attribute for netlink route updates, with an attribute format of: struct mctp_fq_addr { unsigned int net; mctp_eid_t eid; } - we need the net here to uniquely identify the target EID, as we no longer have the device reference directly (which would provide the net id in the case of direct routes). This makes route lookups recursive, as a route lookup that returns a gateway route must be resolved into a direct route (ie, to a device) eventually. We provide a limit to the route lookups, to prevent infinite loop routing. The route lookup populates a new 'nexthop' field in the dst structure, which now specifies the key for the neighbour table lookup on device output, rather than using the packet destination address directly.

Jeremy Kerr committed 1 year ago

Commit ad39c121 parent 28ddbb24 files · +173 −57Browse files

Unified · Split

4 files
  1. include/net/mctp.h +12 −1
  2. include/uapi/linux/mctp.h +8 −0
  3. net/mctp/route.c +151 −55
  4. net/mctp/test/utils.c +2 −1
include/net/mctp.h+12−1
@@ -237,8 +237,18 @@ struct mctp_route { · 236 unmodified lines
237 mctp_eid_t min, max;237 mctp_eid_t min, max;
238 238
239 unsigned char type;239 unsigned char type;
240
240 unsigned int mtu;241 unsigned int mtu;
241 struct mctp_dev *dev;242
243 enum {
244 MCTP_ROUTE_DIRECT,
245 MCTP_ROUTE_GATEWAY,
246 } dst_type;
247 union {
248 struct mctp_dev *dev;
249 struct mctp_fq_addr gateway;
250 };
251
242 int (*output)(struct mctp_dst *dst,252 int (*output)(struct mctp_dst *dst,
243 struct sk_buff *skb);253 struct sk_buff *skb);
244 254
@@ -256,6 +266,7 @@ struct mctp_route { · 11 unmodified lines
256struct mctp_dst {266struct mctp_dst {
257 struct mctp_dev *dev;267 struct mctp_dev *dev;
258 unsigned int mtu;268 unsigned int mtu;
269 mctp_eid_t nexthop;
259 270
260 /* set for direct addressing */271 /* set for direct addressing */
261 unsigned char halen;272 unsigned char halen;
include/uapi/linux/mctp.h+8−0
@@ -37,6 +37,14 @@ struct sockaddr_mctp_ext { · 36 unmodified lines
37 __u8 smctp_haddr[MAX_ADDR_LEN];37 __u8 smctp_haddr[MAX_ADDR_LEN];
38};38};
39 39
40/* A "fully qualified" MCTP address, which includes the system-local network ID,
41 * required to uniquely resolve a routable EID.
42 */
43struct mctp_fq_addr {
44 unsigned int net;
45 mctp_eid_t eid;
46};
47
40#define MCTP_NET_ANY 0x048#define MCTP_NET_ANY 0x0
41 49
42#define MCTP_ADDR_NULL 0x0050#define MCTP_ADDR_NULL 0x00
net/mctp/route.c+151−55
@@ -563,7 +563,6 @@ out: · 562 unmodified lines
563 563
564static int mctp_dst_output(struct mctp_dst *dst, struct sk_buff *skb)564static int mctp_dst_output(struct mctp_dst *dst, struct sk_buff *skb)
565{565{
566 struct mctp_hdr *hdr = mctp_hdr(skb);
567 char daddr_buf[MAX_ADDR_LEN];566 char daddr_buf[MAX_ADDR_LEN];
568 char *daddr = NULL;567 char *daddr = NULL;
569 int rc;568 int rc;
@@ -586,7 +585,7 @@ static int mctp_dst_output(struct mctp_dst *dst, struct sk_buff *skb) · 16 unmodified lines
586 daddr = dst->haddr;585 daddr = dst->haddr;
587 } else {586 } else {
588 /* If lookup fails let the device handle daddr==NULL */587 /* If lookup fails let the device handle daddr==NULL */
589 if (mctp_neigh_lookup(dst->dev, hdr->dest, daddr_buf) == 0)588 if (mctp_neigh_lookup(dst->dev, dst->nexthop, daddr_buf) == 0)
590 daddr = daddr_buf;589 daddr = daddr_buf;
591 }590 }
592 591
@@ -610,7 +609,8 @@ static int mctp_dst_output(struct mctp_dst *dst, struct sk_buff *skb) · 17 unmodified lines
610static void mctp_route_release(struct mctp_route *rt)609static void mctp_route_release(struct mctp_route *rt)
611{610{
612 if (refcount_dec_and_test(&rt->refs)) {611 if (refcount_dec_and_test(&rt->refs)) {
613 mctp_dev_put(rt->dev);612 if (rt->dst_type == MCTP_ROUTE_DIRECT)
613 mctp_dev_put(rt->dev);
614 kfree_rcu(rt, rcu);614 kfree_rcu(rt, rcu);
615 }615 }
616}616}
@@ -799,10 +799,16 @@ static struct mctp_sk_key *mctp_lookup_prealloc_tag(struct mctp_sock *msk, · 182 unmodified lines
799}799}
800 800
801/* routing lookups */801/* routing lookups */
802static unsigned int mctp_route_netid(struct mctp_route *rt)
803{
804 return rt->dst_type == MCTP_ROUTE_DIRECT ?
805 READ_ONCE(rt->dev->net) : rt->gateway.net;
806}
807
802static bool mctp_rt_match_eid(struct mctp_route *rt,808static bool mctp_rt_match_eid(struct mctp_route *rt,
803 unsigned int net, mctp_eid_t eid)809 unsigned int net, mctp_eid_t eid)
804{810{
805 return READ_ONCE(rt->dev->net) == net &&811 return mctp_route_netid(rt) == net &&
806 rt->min <= eid && rt->max >= eid;812 rt->min <= eid && rt->max >= eid;
807}813}
808 814
@@ -811,16 +817,21 @@ static bool mctp_rt_compare_exact(struct mctp_route *rt1, · 2 unmodified lines
811 struct mctp_route *rt2)817 struct mctp_route *rt2)
812{818{
813 ASSERT_RTNL();819 ASSERT_RTNL();
814 return rt1->dev->net == rt2->dev->net &&820 return mctp_route_netid(rt1) == mctp_route_netid(rt2) &&
815 rt1->min == rt2->min &&821 rt1->min == rt2->min &&
816 rt1->max == rt2->max;822 rt1->max == rt2->max;
817}823}
818 824
819static void mctp_dst_from_route(struct mctp_dst *dst, struct mctp_route *route)825/* must only be called on a direct route, as the final output hop */
826static void mctp_dst_from_route(struct mctp_dst *dst, mctp_eid_t eid,
827 unsigned int mtu, struct mctp_route *route)
820{828{
821 mctp_dev_hold(route->dev);829 mctp_dev_hold(route->dev);
830 dst->nexthop = eid;
822 dst->dev = route->dev;831 dst->dev = route->dev;
823 dst->mtu = route->mtu ?: READ_ONCE(dst->dev->dev->mtu);832 dst->mtu = READ_ONCE(dst->dev->dev->mtu);
833 if (mtu)
834 dst->mtu = min(dst->mtu, mtu);
824 dst->halen = 0;835 dst->halen = 0;
825 dst->output = route->output;836 dst->output = route->output;
826}837}
@@ -854,6 +865,7 @@ int mctp_dst_from_extaddr(struct mctp_dst *dst, struct net *net, int ifindex, · 27 unmodified lines
854 dst->mtu = READ_ONCE(netdev->mtu);865 dst->mtu = READ_ONCE(netdev->mtu);
855 dst->halen = halen;866 dst->halen = halen;
856 dst->output = mctp_dst_output;867 dst->output = mctp_dst_output;
868 dst->nexthop = 0;
857 memcpy(dst->haddr, haddr, halen);869 memcpy(dst->haddr, haddr, halen);
858 870
859 rc = 0;871 rc = 0;
@@ -868,24 +880,54 @@ void mctp_dst_release(struct mctp_dst *dst) · 8 unmodified lines
868 mctp_dev_put(dst->dev);880 mctp_dev_put(dst->dev);
869}881}
870 882
883static struct mctp_route *mctp_route_lookup_single(struct net *net,
884 unsigned int dnet,
885 mctp_eid_t daddr)
886{
887 struct mctp_route *rt;
888
889 list_for_each_entry_rcu(rt, &net->mctp.routes, list) {
890 if (mctp_rt_match_eid(rt, dnet, daddr))
891 return rt;
892 }
893
894 return NULL;
895}
896
871/* populates *dst on successful lookup, if set */897/* populates *dst on successful lookup, if set */
872int mctp_route_lookup(struct net *net, unsigned int dnet,898int mctp_route_lookup(struct net *net, unsigned int dnet,
873 mctp_eid_t daddr, struct mctp_dst *dst)899 mctp_eid_t daddr, struct mctp_dst *dst)
874{900{
901 const unsigned int max_depth = 32;
902 unsigned int depth, mtu = 0;
875 int rc = -EHOSTUNREACH;903 int rc = -EHOSTUNREACH;
876 struct mctp_route *rt;
877 904
878 rcu_read_lock();905 rcu_read_lock();
879 906
880 list_for_each_entry_rcu(rt, &net->mctp.routes, list) {907 for (depth = 0; depth < max_depth; depth++) {
881 /* TODO: add metrics */908 struct mctp_route *rt;
882 if (!mctp_rt_match_eid(rt, dnet, daddr))
883 continue;
884 909
885 if (dst)910 rt = mctp_route_lookup_single(net, dnet, daddr);
886 mctp_dst_from_route(dst, rt);911 if (!rt)
887 rc = 0;912 break;
888 break;913
914 /* clamp mtu to the smallest in the path, allowing 0
915 * to specify no restrictions
916 */
917 if (mtu && rt->mtu)
918 mtu = min(mtu, rt->mtu);
919 else
920 mtu = mtu ?: rt->mtu;
921
922 if (rt->dst_type == MCTP_ROUTE_DIRECT) {
923 if (dst)
924 mctp_dst_from_route(dst, daddr, mtu, rt);
925 rc = 0;
926 break;
927
928 } else if (rt->dst_type == MCTP_ROUTE_GATEWAY) {
929 daddr = rt->gateway.eid;
930 }
889 }931 }
890 932
891 rcu_read_unlock();933 rcu_read_unlock();
@@ -902,10 +944,13 @@ static int mctp_route_lookup_null(struct net *net, struct net_device *dev, · 10 unmodified lines
902 rcu_read_lock();944 rcu_read_lock();
903 945
904 list_for_each_entry_rcu(rt, &net->mctp.routes, list) {946 list_for_each_entry_rcu(rt, &net->mctp.routes, list) {
905 if (rt->dev->dev != dev || rt->type != RTN_LOCAL)947 if (rt->dst_type != MCTP_ROUTE_DIRECT || rt->type != RTN_LOCAL)
948 continue;
949
950 if (rt->dev->dev != dev)
906 continue;951 continue;
907 952
908 mctp_dst_from_route(dst, rt);953 mctp_dst_from_route(dst, 0, 0, rt);
909 rc = 0;954 rc = 0;
910 break;955 break;
911 }956 }
@@ -1085,11 +1130,6 @@ out_release: · 173 unmodified lines
1085 return rc;1130 return rc;
1086}1131}
1087 1132
1088static unsigned int mctp_route_netid(struct mctp_route *rt)
1089{
1090 return rt->dev->net;
1091}
1092
1093/* route management */1133/* route management */
1094 1134
1095/* mctp_route_add(): Add the provided route, previously allocated via1135/* mctp_route_add(): Add the provided route, previously allocated via
@@ -1097,9 +1137,9 @@ static unsigned int mctp_route_netid(struct mctp_route *rt) · 1 unmodified line
1097 * hold on rt->dev for usage in the route table. On failure a caller will want1137 * hold on rt->dev for usage in the route table. On failure a caller will want
1098 * to mctp_route_release().1138 * to mctp_route_release().
1099 *1139 *
1100 * We expect that the caller has set rt->type, rt->min, rt->max, rt->dev and1140 * We expect that the caller has set rt->type, rt->dst_type, rt->min, rt->max,
1101 * rt->mtu, and that the route holds a reference to rt->dev (via mctp_dev_hold).1141 * rt->mtu and either rt->dev (with a reference held appropriately) or
1102 * Other fields will be populated.1142 * rt->gateway. Other fields will be populated.
1103 */1143 */
1104static int mctp_route_add(struct net *net, struct mctp_route *rt)1144static int mctp_route_add(struct net *net, struct mctp_route *rt)
1105{1145{
@@ -1108,7 +1148,10 @@ static int mctp_route_add(struct net *net, struct mctp_route *rt) · 2 unmodified lines
1108 if (!mctp_address_unicast(rt->min) || !mctp_address_unicast(rt->max))1148 if (!mctp_address_unicast(rt->min) || !mctp_address_unicast(rt->max))
1109 return -EINVAL;1149 return -EINVAL;
1110 1150
1111 if (!rt->dev)1151 if (rt->dst_type == MCTP_ROUTE_DIRECT && !rt->dev)
1152 return -EINVAL;
1153
1154 if (rt->dst_type == MCTP_ROUTE_GATEWAY && !rt->gateway.eid)
1112 return -EINVAL;1155 return -EINVAL;
1113 1156
1114 switch (rt->type) {1157 switch (rt->type) {
@@ -1177,6 +1220,7 @@ int mctp_route_add_local(struct mctp_dev *mdev, mctp_eid_t addr) · 62 unmodified lines
1177 1220
1178 rt->min = addr;1221 rt->min = addr;
1179 rt->max = addr;1222 rt->max = addr;
1223 rt->dst_type = MCTP_ROUTE_DIRECT;
1180 rt->dev = mdev;1224 rt->dev = mdev;
1181 rt->type = RTN_LOCAL;1225 rt->type = RTN_LOCAL;
1182 1226
@@ -1203,7 +1247,7 @@ void mctp_route_remove_dev(struct mctp_dev *mdev) · 20 unmodified lines
1203 1247
1204 ASSERT_RTNL();1248 ASSERT_RTNL();
1205 list_for_each_entry_safe(rt, tmp, &net->mctp.routes, list) {1249 list_for_each_entry_safe(rt, tmp, &net->mctp.routes, list) {
1206 if (rt->dev == mdev) {1250 if (rt->dst_type == MCTP_ROUTE_DIRECT && rt->dev == mdev) {
1207 list_del_rcu(&rt->list);1251 list_del_rcu(&rt->list);
1208 /* TODO: immediate RTM_DELROUTE */1252 /* TODO: immediate RTM_DELROUTE */
1209 mctp_route_release(rt);1253 mctp_route_release(rt);
@@ -1296,21 +1340,28 @@ static const struct nla_policy rta_mctp_policy[RTA_MAX + 1] = { · 86 unmodified lines
1296 [RTA_DST] = { .type = NLA_U8 },1340 [RTA_DST] = { .type = NLA_U8 },
1297 [RTA_METRICS] = { .type = NLA_NESTED },1341 [RTA_METRICS] = { .type = NLA_NESTED },
1298 [RTA_OIF] = { .type = NLA_U32 },1342 [RTA_OIF] = { .type = NLA_U32 },
1343 [RTA_GATEWAY] = NLA_POLICY_EXACT_LEN(sizeof(struct mctp_fq_addr)),
1299};1344};
1300 1345
1301static const struct nla_policy rta_metrics_policy[RTAX_MAX + 1] = {1346static const struct nla_policy rta_metrics_policy[RTAX_MAX + 1] = {
1302 [RTAX_MTU] = { .type = NLA_U32 },1347 [RTAX_MTU] = { .type = NLA_U32 },
1303};1348};
1304 1349
1305/* base parsing; common to both _lookup and _populate variants */1350/* base parsing; common to both _lookup and _populate variants.
1351 *
1352 * For gateway routes (which have a RTA_GATEWAY, and no RTA_OIF), we populate
1353 * *gatweayp. for direct routes (RTA_OIF, no RTA_GATEWAY), we populate *mdev.
1354 */
1306static int mctp_route_nlparse_common(struct net *net, struct nlmsghdr *nlh,1355static int mctp_route_nlparse_common(struct net *net, struct nlmsghdr *nlh,
1307 struct netlink_ext_ack *extack,1356 struct netlink_ext_ack *extack,
1308 struct nlattr **tb, struct rtmsg **rtm,1357 struct nlattr **tb, struct rtmsg **rtm,
1309 struct mctp_dev **mdev,1358 struct mctp_dev **mdev,
1359 struct mctp_fq_addr *gatewayp,
1310 mctp_eid_t *daddr_start)1360 mctp_eid_t *daddr_start)
1311{1361{
1362 struct mctp_fq_addr *gateway = NULL;
1363 unsigned int ifindex = 0;
1312 struct net_device *dev;1364 struct net_device *dev;
1313 unsigned int ifindex;
1314 int rc;1365 int rc;
1315 1366
1316 rc = nlmsg_parse(nlh, sizeof(struct rtmsg), tb, RTA_MAX,1367 rc = nlmsg_parse(nlh, sizeof(struct rtmsg), tb, RTA_MAX,
@@ -1326,11 +1377,44 @@ static int mctp_route_nlparse_common(struct net *net, struct nlmsghdr *nlh, · 9 unmodified lines
1326 }1377 }
1327 *daddr_start = nla_get_u8(tb[RTA_DST]);1378 *daddr_start = nla_get_u8(tb[RTA_DST]);
1328 1379
1329 if (!tb[RTA_OIF]) {1380 if (tb[RTA_OIF])
1330 NL_SET_ERR_MSG(extack, "ifindex missing");1381 ifindex = nla_get_u32(tb[RTA_OIF]);
1382
1383 if (tb[RTA_GATEWAY])
1384 gateway = nla_data(tb[RTA_GATEWAY]);
1385
1386 if (ifindex && gateway) {
1387 NL_SET_ERR_MSG(extack,
1388 "cannot specify both ifindex and gateway");
1389 return -EINVAL;
1390
1391 } else if (ifindex) {
1392 dev = __dev_get_by_index(net, ifindex);
1393 if (!dev) {
1394 NL_SET_ERR_MSG(extack, "bad ifindex");
1395 return -ENODEV;
1396 }
1397 *mdev = mctp_dev_get_rtnl(dev);
1398 if (!*mdev)
1399 return -ENODEV;
1400 gatewayp->eid = 0;
1401
1402 } else if (gateway) {
1403 if (!mctp_address_unicast(gateway->eid)) {
1404 NL_SET_ERR_MSG(extack, "bad gateway");
1405 return -EINVAL;
1406 }
1407
1408 gatewayp->eid = gateway->eid;
1409 gatewayp->net = gateway->net != MCTP_NET_ANY ?
1410 gateway->net :
1411 READ_ONCE(net->mctp.default_net);
1412 *mdev = NULL;
1413
1414 } else {
1415 NL_SET_ERR_MSG(extack, "no route output provided");
1331 return -EINVAL;1416 return -EINVAL;
1332 }1417 }
1333 ifindex = nla_get_u32(tb[RTA_OIF]);
1334 1418
1335 *rtm = nlmsg_data(nlh);1419 *rtm = nlmsg_data(nlh);
1336 if ((*rtm)->rtm_family != AF_MCTP) {1420 if ((*rtm)->rtm_family != AF_MCTP) {
@@ -1343,16 +1427,6 @@ static int mctp_route_nlparse_common(struct net *net, struct nlmsghdr *nlh, · 6 unmodified lines
1343 return -EINVAL;1427 return -EINVAL;
1344 }1428 }
1345 1429
1346 dev = __dev_get_by_index(net, ifindex);
1347 if (!dev) {
1348 NL_SET_ERR_MSG(extack, "bad ifindex");
1349 return -ENODEV;
1350 }
1351
1352 *mdev = mctp_dev_get_rtnl(dev);
1353 if (!*mdev)
1354 return -ENODEV;
1355
1356 return 0;1430 return 0;
1357}1431}
1358 1432
@@ -1366,24 +1440,34 @@ static int mctp_route_nlparse_lookup(struct net *net, struct nlmsghdr *nlh, · 7 unmodified lines
1366 unsigned int *daddr_extent)1440 unsigned int *daddr_extent)
1367{1441{
1368 struct nlattr *tb[RTA_MAX + 1];1442 struct nlattr *tb[RTA_MAX + 1];
1443 struct mctp_fq_addr gw;
1369 struct mctp_dev *mdev;1444 struct mctp_dev *mdev;
1370 struct rtmsg *rtm;1445 struct rtmsg *rtm;
1371 int rc;1446 int rc;
1372 1447
1373 rc = mctp_route_nlparse_common(net, nlh, extack, tb, &rtm,1448 rc = mctp_route_nlparse_common(net, nlh, extack, tb, &rtm,
1374 &mdev, daddr_start);1449 &mdev, &gw, daddr_start);
1375 if (rc)1450 if (rc)
1376 return rc;1451 return rc;
1377 1452
1378 *netid = mdev->net;1453 if (mdev) {
1454 *netid = mdev->net;
1455 } else if (gw.eid) {
1456 *netid = gw.net;
1457 } else {
1458 /* bug: _nlparse_common should not allow this */
1459 return -1;
1460 }
1461
1379 *type = rtm->rtm_type;1462 *type = rtm->rtm_type;
1380 *daddr_extent = rtm->rtm_dst_len;1463 *daddr_extent = rtm->rtm_dst_len;
1381 1464
1382 return 0;1465 return 0;
1383}1466}
1384 1467
1385/* Full route parse for RTM_NEWROUTE: populate @rt. On success, the route will1468/* Full route parse for RTM_NEWROUTE: populate @rt. On success,
1386 * hold a reference to the dev.1469 * MCTP_ROUTE_DIRECT routes (ie, those with a direct dev) will hold a reference
1470 * to that dev.
1387 */1471 */
1388static int mctp_route_nlparse_populate(struct net *net, struct nlmsghdr *nlh,1472static int mctp_route_nlparse_populate(struct net *net, struct nlmsghdr *nlh,
1389 struct netlink_ext_ack *extack,1473 struct netlink_ext_ack *extack,
@@ -1392,6 +1476,7 @@ static int mctp_route_nlparse_populate(struct net *net, struct nlmsghdr *nlh, · 2 unmodified lines
1392 struct nlattr *tbx[RTAX_MAX + 1];1476 struct nlattr *tbx[RTAX_MAX + 1];
1393 struct nlattr *tb[RTA_MAX + 1];1477 struct nlattr *tb[RTA_MAX + 1];
1394 unsigned int daddr_extent;1478 unsigned int daddr_extent;
1479 struct mctp_fq_addr gw;
1395 mctp_eid_t daddr_start;1480 mctp_eid_t daddr_start;
1396 struct mctp_dev *dev;1481 struct mctp_dev *dev;
1397 struct rtmsg *rtm;1482 struct rtmsg *rtm;
@@ -1399,7 +1484,7 @@ static int mctp_route_nlparse_populate(struct net *net, struct nlmsghdr *nlh, · 1 unmodified line
1399 int rc;1484 int rc;
1400 1485
1401 rc = mctp_route_nlparse_common(net, nlh, extack, tb, &rtm,1486 rc = mctp_route_nlparse_common(net, nlh, extack, tb, &rtm,
1402 &dev, &daddr_start);1487 &dev, &gw, &daddr_start);
1403 if (rc)1488 if (rc)
1404 return rc;1489 return rc;
1405 1490
@@ -1425,8 +1510,15 @@ static int mctp_route_nlparse_populate(struct net *net, struct nlmsghdr *nlh, · 19 unmodified lines
1425 rt->min = daddr_start;1510 rt->min = daddr_start;
1426 rt->max = daddr_start + daddr_extent;1511 rt->max = daddr_start + daddr_extent;
1427 rt->mtu = mtu;1512 rt->mtu = mtu;
1428 rt->dev = dev;1513 if (gw.eid) {
1429 mctp_dev_hold(rt->dev);1514 rt->dst_type = MCTP_ROUTE_GATEWAY;
1515 rt->gateway.eid = gw.eid;
1516 rt->gateway.net = gw.net;
1517 } else {
1518 rt->dst_type = MCTP_ROUTE_DIRECT;
1519 rt->dev = dev;
1520 mctp_dev_hold(rt->dev);
1521 }
1430 1522
1431 return 0;1523 return 0;
1432}1524}
@@ -1446,7 +1538,8 @@ static int mctp_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, · 13 unmodified lines
1446 if (rc < 0)1538 if (rc < 0)
1447 goto err_free;1539 goto err_free;
1448 1540
1449 if (rt->dev->dev->flags & IFF_LOOPBACK) {1541 if (rt->dst_type == MCTP_ROUTE_DIRECT &&
1542 rt->dev->dev->flags & IFF_LOOPBACK) {
1450 NL_SET_ERR_MSG(extack, "no routes to loopback");1543 NL_SET_ERR_MSG(extack, "no routes to loopback");
1451 rc = -EINVAL;1544 rc = -EINVAL;
1452 goto err_free;1545 goto err_free;
@@ -1505,7 +1598,6 @@ static int mctp_fill_rtinfo(struct sk_buff *skb, struct mctp_route *rt, · 52 unmodified lines
1505 hdr->rtm_tos = 0;1598 hdr->rtm_tos = 0;
1506 hdr->rtm_table = RT_TABLE_DEFAULT;1599 hdr->rtm_table = RT_TABLE_DEFAULT;
1507 hdr->rtm_protocol = RTPROT_STATIC; /* everything is user-defined */1600 hdr->rtm_protocol = RTPROT_STATIC; /* everything is user-defined */
1508 hdr->rtm_scope = RT_SCOPE_LINK; /* TODO: scope in mctp_route? */
1509 hdr->rtm_type = rt->type;1601 hdr->rtm_type = rt->type;
1510 1602
1511 if (nla_put_u8(skb, RTA_DST, rt->min))1603 if (nla_put_u8(skb, RTA_DST, rt->min))
@@ -1522,13 +1614,17 @@ static int mctp_fill_rtinfo(struct sk_buff *skb, struct mctp_route *rt, · 10 unmodified lines
1522 1614
1523 nla_nest_end(skb, metrics);1615 nla_nest_end(skb, metrics);
1524 1616
1525 if (rt->dev) {1617 if (rt->dst_type == MCTP_ROUTE_DIRECT) {
1618 hdr->rtm_scope = RT_SCOPE_LINK;
1526 if (nla_put_u32(skb, RTA_OIF, rt->dev->dev->ifindex))1619 if (nla_put_u32(skb, RTA_OIF, rt->dev->dev->ifindex))
1527 goto cancel;1620 goto cancel;
1621 } else if (rt->dst_type == MCTP_ROUTE_GATEWAY) {
1622 hdr->rtm_scope = RT_SCOPE_UNIVERSE;
1623 if (nla_put(skb, RTA_GATEWAY,
1624 sizeof(rt->gateway), &rt->gateway))
1625 goto cancel;
1528 }1626 }
1529 1627
1530 /* TODO: conditional neighbour physaddr? */
1531
1532 nlmsg_end(skb, nlh);1628 nlmsg_end(skb, nlh);
1533 1629
1534 return 0;1630 return 0;
net/mctp/test/utils.c+2−1
@@ -134,6 +134,7 @@ struct mctp_test_route *mctp_test_create_route(struct net *net, · 133 unmodified lines
134 rt->rt.max = eid;134 rt->rt.max = eid;
135 rt->rt.mtu = mtu;135 rt->rt.mtu = mtu;
136 rt->rt.type = RTN_UNSPEC;136 rt->rt.type = RTN_UNSPEC;
137 rt->rt.dst_type = MCTP_ROUTE_DIRECT;
137 if (dev)138 if (dev)
138 mctp_dev_hold(dev);139 mctp_dev_hold(dev);
139 rt->rt.dev = dev;140 rt->rt.dev = dev;
@@ -176,7 +177,7 @@ void mctp_test_route_destroy(struct kunit *test, struct mctp_test_route *rt) · 36 unmodified lines
176 list_del_rcu(&rt->rt.list);177 list_del_rcu(&rt->rt.list);
177 rtnl_unlock();178 rtnl_unlock();
178 179
179 if (rt->rt.dev)180 if (rt->rt.dst_type == MCTP_ROUTE_DIRECT && rt->rt.dev)
180 mctp_dev_put(rt->rt.dev);181 mctp_dev_put(rt->rt.dev);
181 182
182 refs = refcount_read(&rt->rt.refs);183 refs = refcount_read(&rt->rt.refs);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t