diff options
author | Thomas Winter <Thomas.Winter@alliedtelesis.co.nz> | 2018-06-08 04:18:40 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-03-11 23:05:37 (GMT) |
commit | 2995710d3f13a95701e54fda33ce80eb5f811f8f (patch) | |
tree | 84853fecab6f0b1611c61f6082fd0c960216ac98 | |
parent | d9dc6c20a36077757f1fa29047c0722382098cd4 (diff) | |
download | libnl-2995710d3f13a95701e54fda33ce80eb5f811f8f.zip libnl-2995710d3f13a95701e54fda33ce80eb5f811f8f.tar.gz libnl-2995710d3f13a95701e54fda33ce80eb5f811f8f.tar.bz2 |
ipgre: Add fwmark API
This is a new option that was added in Linux v4.12.
Signed-off-by: Thomas Winter <Thomas.Winter@alliedtelesis.co.nz>
-rw-r--r-- | doc/route.txt | 3 | ||||
-rw-r--r-- | include/netlink/route/link/ipgre.h | 3 | ||||
-rw-r--r-- | lib/route/link/ipgre.c | 56 | ||||
-rw-r--r-- | libnl-route-3.sym | 2 |
4 files changed, 64 insertions, 0 deletions
diff --git a/doc/route.txt b/doc/route.txt index 01e0a7b..d303978 100644 --- a/doc/route.txt +++ b/doc/route.txt @@ -1019,6 +1019,9 @@ extern uint8_t rtnl_link_ipgre_get_tos(struct rtnl_link *link); extern int rtnl_link_ipgre_set_pmtudisc(struct rtnl_link *link, uint8_t pmtudisc); extern uint8_t rtnl_link_ipgre_get_pmtudisc(struct rtnl_link *link); +extern int rtnl_link_ipgre_set_fwmark(struct rtnl_link *link, uint32_t fwmark); +extern int rtnl_link_ipgre_get_fwmark(struct rtnl_link *link, uint32_t *fwmark); + ----- .Example: Add a ipgre tunnel device diff --git a/include/netlink/route/link/ipgre.h b/include/netlink/route/link/ipgre.h index 9e757af..09a4957 100644 --- a/include/netlink/route/link/ipgre.h +++ b/include/netlink/route/link/ipgre.h @@ -51,6 +51,9 @@ extern "C" { extern int rtnl_link_ipgre_set_pmtudisc(struct rtnl_link *link, uint8_t pmtudisc); extern uint8_t rtnl_link_ipgre_get_pmtudisc(struct rtnl_link *link); + extern int rtnl_link_ipgre_set_fwmark(struct rtnl_link *link, uint32_t fwmark); + extern int rtnl_link_ipgre_get_fwmark(struct rtnl_link *link, uint32_t *fwmark); + #ifdef __cplusplus } #endif diff --git a/lib/route/link/ipgre.c b/lib/route/link/ipgre.c index 63c66b4..f5a4998 100644 --- a/lib/route/link/ipgre.c +++ b/lib/route/link/ipgre.c @@ -36,6 +36,7 @@ #define IPGRE_ATTR_TTL (1 << 7) #define IPGRE_ATTR_TOS (1 << 8) #define IPGRE_ATTR_PMTUDISC (1 << 9) +#define IPGRE_ATTR_FWMARK (1 << 10) struct ipgre_info { @@ -49,6 +50,7 @@ struct ipgre_info uint32_t link; uint32_t local; uint32_t remote; + uint32_t fwmark; uint32_t ipgre_mask; }; @@ -63,6 +65,7 @@ static struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = { [IFLA_GRE_TTL] = { .type = NLA_U8 }, [IFLA_GRE_TOS] = { .type = NLA_U8 }, [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 }, + [IFLA_GRE_FWMARK] = { .type = NLA_U32 }, }; static int ipgre_alloc(struct rtnl_link *link) @@ -151,6 +154,11 @@ static int ipgre_parse(struct rtnl_link *link, struct nlattr *data, ipgre->ipgre_mask |= IPGRE_ATTR_PMTUDISC; } + if (tb[IFLA_GRE_FWMARK]) { + ipgre->fwmark = nla_get_u32(tb[IFLA_GRE_FWMARK]); + ipgre->ipgre_mask |= IPGRE_ATTR_FWMARK; + } + err = 0; errout: @@ -196,6 +204,9 @@ static int ipgre_put_attrs(struct nl_msg *msg, struct rtnl_link *link) if (ipgre->ipgre_mask & IPGRE_ATTR_PMTUDISC) NLA_PUT_U8(msg, IFLA_GRE_PMTUDISC, ipgre->pmtudisc); + if (ipgre->ipgre_mask & IPGRE_ATTR_FWMARK) + NLA_PUT_U32(msg, IFLA_GRE_FWMARK, ipgre->fwmark); + nla_nest_end(msg, data); nla_put_failure: @@ -286,6 +297,11 @@ static void ipgre_dump_details(struct rtnl_link *link, struct nl_dump_params *p) nl_dump(p, " pmtudisc "); nl_dump_line(p, "enabled (%#x)\n", ipgre->pmtudisc); } + + if (ipgre->ipgre_mask & IPGRE_ATTR_FWMARK) { + nl_dump(p, " fwmark "); + nl_dump_line(p, "%x\n", ipgre->fwmark); + } } static int ipgre_clone(struct rtnl_link *dst, struct rtnl_link *src) @@ -823,6 +839,46 @@ uint8_t rtnl_link_get_pmtudisc(struct rtnl_link *link) return rtnl_link_ipgre_get_pmtudisc (link); } +/** + * Set IPGRE tunnel fwmark + * @arg link Link object + * @arg fwmark fwmark + * + * @return 0 on success or a negative error code + */ +int rtnl_link_ipgre_set_fwmark(struct rtnl_link *link, uint32_t fwmark) +{ + struct ipgre_info *ipgre = link->l_info; + + IS_IPGRE_LINK_ASSERT(link); + + ipgre->fwmark = fwmark; + ipgre->ipgre_mask |= IPGRE_ATTR_FWMARK; + + return 0; +} + +/** + * Get IPGRE tunnel fwmark + * @arg link Link object + * @arg fwmark addr to fill in with the fwmark + * + * @return 0 on success or a negative error code + */ +int rtnl_link_ipgre_get_fwmark(struct rtnl_link *link, uint32_t *fwmark) +{ + struct ipgre_info *ipgre = link->l_info; + + IS_IPGRE_LINK_ASSERT(link); + + if (!(ipgre->ipgre_mask & IPGRE_ATTR_FWMARK)) + return -NLE_NOATTR; + + *fwmark = ipgre->fwmark; + + return 0; +} + static void __init ipgre_init(void) { rtnl_link_register_info(&ipgre_info_ops); diff --git a/libnl-route-3.sym b/libnl-route-3.sym index c009288..ec66f27 100644 --- a/libnl-route-3.sym +++ b/libnl-route-3.sym @@ -1189,6 +1189,8 @@ global: rtnl_link_ip6vti_set_local; rtnl_link_ip6vti_set_okey; rtnl_link_ip6vti_set_remote; + rtnl_link_ipgre_get_fwmark; + rtnl_link_ipgre_set_fwmark; rtnl_link_is_ip6gre; rtnl_link_is_ip6vti; rtnl_link_macsec_get_offload; |