Skip to content

Commit acb0156

Browse files
committed
[nh-encap] Add parsing support to populate a struct rtnl_nh_encap
There is support for parsing and populating rtnl_nexthop's encap. However, not for rtnl_nh's encapsulation. Refactor this and make it such that the parsing code for both is reused. Signed-off-by: Christoph Paasch <[email protected]>
1 parent 51848a0 commit acb0156

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

lib/route/nexthop-encap.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#ifndef NETLINK_NEXTHOP_ENCAP_H_
22
#define NETLINK_NEXTHOP_ENCAP_H_
33

4+
struct rtnl_nh_encap;
5+
46
struct nh_encap_ops {
57
uint16_t encap_type;
68

79
int (*build_msg)(struct nl_msg *msg, void *priv);
8-
int (*parse_msg)(struct nlattr *nla, struct rtnl_nexthop *rtnh);
10+
int (*parse_msg)(struct nlattr *nla, struct rtnl_nh_encap **encap_out);
911

1012
int (*compare)(void *a, void *b);
1113
void *(*clone)(void *priv);
@@ -14,13 +16,11 @@ struct nh_encap_ops {
1416
void (*destructor)(void *priv);
1517
};
1618

17-
struct rtnl_nh_encap;
18-
1919
/*
2020
* generic nexthop encap
2121
*/
2222
int nh_encap_parse_msg(struct nlattr *encap, struct nlattr *encap_type,
23-
struct rtnl_nexthop *rtnh);
23+
struct rtnl_nh_encap **encap_out);
2424
int nh_encap_build_msg(struct nl_msg *msg, struct rtnl_nh_encap *rtnh_encap);
2525

2626
void nh_encap_dump(struct rtnl_nh_encap *rtnh_encap, struct nl_dump_params *dp);

lib/route/nexthop_encap.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int nh_encap_build_msg(struct nl_msg *msg, struct rtnl_nh_encap *rtnh_encap)
7272
}
7373

7474
int nh_encap_parse_msg(struct nlattr *encap, struct nlattr *encap_type,
75-
struct rtnl_nexthop *rtnh)
75+
struct rtnl_nh_encap **encap_out)
7676
{
7777
uint16_t e_type = nla_get_u16(encap_type);
7878

@@ -91,7 +91,10 @@ int nh_encap_parse_msg(struct nlattr *encap, struct nlattr *encap_type,
9191
return -NLE_MSGTYPE_NOSUPPORT;
9292
}
9393

94-
return lwtunnel_encap_types[e_type].ops->parse_msg(encap, rtnh);
94+
if (!lwtunnel_encap_types[e_type].ops->parse_msg)
95+
return -NLE_MSGTYPE_NOSUPPORT;
96+
97+
return lwtunnel_encap_types[e_type].ops->parse_msg(encap, encap_out);
9598
}
9699

97100
int nh_encap_compare(struct rtnl_nh_encap *a, struct rtnl_nh_encap *b)

lib/route/nh_encap_mpls.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ static struct nla_policy mpls_encap_policy[MPLS_IPTUNNEL_MAX + 1] = {
7272
[MPLS_IPTUNNEL_TTL] = { .type = NLA_U8 },
7373
};
7474

75-
static int mpls_encap_parse_msg(struct nlattr *nla, struct rtnl_nexthop *nh)
75+
static int mpls_encap_parse_msg(struct nlattr *nla,
76+
struct rtnl_nh_encap **encap_out)
7677
{
7778
_nl_auto_rtnl_nh_encap struct rtnl_nh_encap *nh_encap = NULL;
7879
_nl_auto_nl_addr struct nl_addr *labels = NULL;
@@ -102,9 +103,7 @@ static int mpls_encap_parse_msg(struct nlattr *nla, struct rtnl_nexthop *nh)
102103
if (err < 0)
103104
return err;
104105

105-
err = rtnl_route_nh_set_encap(nh, _nl_steal_pointer(&nh_encap));
106-
if (err < 0)
107-
return err;
106+
*encap_out = _nl_steal_pointer(&nh_encap);
108107

109108
return 0;
110109
}

lib/route/route_obj.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,9 +1149,17 @@ static int parse_multipath(struct rtnl_route *route, struct nlattr *attr)
11491149
}
11501150

11511151
if (ntb[RTA_ENCAP] && ntb[RTA_ENCAP_TYPE]) {
1152+
_nl_auto_rtnl_nh_encap struct rtnl_nh_encap
1153+
*encap = NULL;
1154+
11521155
err = nh_encap_parse_msg(ntb[RTA_ENCAP],
11531156
ntb[RTA_ENCAP_TYPE],
1154-
nh);
1157+
&encap);
1158+
if (err < 0)
1159+
return err;
1160+
1161+
err = rtnl_route_nh_set_encap(
1162+
nh, _nl_steal_pointer(&encap));
11551163
if (err < 0)
11561164
return err;
11571165
}
@@ -1358,11 +1366,18 @@ int rtnl_route_parse(struct nlmsghdr *nlh, struct rtnl_route **result)
13581366
}
13591367

13601368
if (tb[RTA_ENCAP] && tb[RTA_ENCAP_TYPE]) {
1369+
_nl_auto_rtnl_nh_encap struct rtnl_nh_encap *encap = NULL;
1370+
13611371
if (!old_nh && !(old_nh = rtnl_route_nh_alloc()))
13621372
return -NLE_NOMEM;
13631373

1364-
err = nh_encap_parse_msg(tb[RTA_ENCAP],
1365-
tb[RTA_ENCAP_TYPE], old_nh);
1374+
err = nh_encap_parse_msg(tb[RTA_ENCAP], tb[RTA_ENCAP_TYPE],
1375+
&encap);
1376+
if (err < 0)
1377+
return err;
1378+
1379+
err = rtnl_route_nh_set_encap(old_nh,
1380+
_nl_steal_pointer(&encap));
13661381
if (err < 0)
13671382
return err;
13681383
}

0 commit comments

Comments
 (0)