diff options
author | Thomas Winter <Thomas.Winter@alliedtelesis.co.nz> | 2018-06-11 20:57:30 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-03-11 23:07:24 (GMT) |
commit | 8e1da8ec9d45bb6a3a09b8e263943ac7d7cac2eb (patch) | |
tree | 39eda633319ce2bca98e27fbf362486c558d85fe | |
parent | bda19be660662b34d281218872f9038be4a2c125 (diff) | |
download | libnl-8e1da8ec9d45bb6a3a09b8e263943ac7d7cac2eb.zip libnl-8e1da8ec9d45bb6a3a09b8e263943ac7d7cac2eb.tar.gz libnl-8e1da8ec9d45bb6a3a09b8e263943ac7d7cac2eb.tar.bz2 |
ipip: 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/ipip.h | 3 | ||||
-rw-r--r-- | lib/route/link/ipip.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 60a8cd8..72e1300 100644 --- a/doc/route.txt +++ b/doc/route.txt @@ -941,6 +941,9 @@ extern uint8_t rtnl_link_ipip_get_tos(struct rtnl_link *link); extern int rtnl_link_ipip_set_pmtudisc(struct rtnl_link *link, uint8_t pmtudisc); extern uint8_t rtnl_link_ipip_get_pmtudisc(struct rtnl_link *link); +extern int rtnl_link_ipip_set_fwmark(struct rtnl_link *link, uint32_t fwmark); +extern int rtnl_link_ipip_get_fwmark(struct rtnl_link *link, uint32_t *fwmark); + ----- .Example: Add a ipip tunnel device diff --git a/include/netlink/route/link/ipip.h b/include/netlink/route/link/ipip.h index 38db21a..65d9f18 100644 --- a/include/netlink/route/link/ipip.h +++ b/include/netlink/route/link/ipip.h @@ -35,6 +35,9 @@ extern "C" { extern int rtnl_link_ipip_set_pmtudisc(struct rtnl_link *link, uint8_t pmtudisc); extern uint8_t rtnl_link_ipip_get_pmtudisc(struct rtnl_link *link); + extern int rtnl_link_ipip_set_fwmark(struct rtnl_link *link, uint32_t fwmark); + extern int rtnl_link_ipip_get_fwmark(struct rtnl_link *link, uint32_t *fwmark); + #ifdef __cplusplus } #endif diff --git a/lib/route/link/ipip.c b/lib/route/link/ipip.c index 1c527c7..e905ef9 100644 --- a/lib/route/link/ipip.c +++ b/lib/route/link/ipip.c @@ -32,6 +32,7 @@ #define IPIP_ATTR_TTL (1 << 3) #define IPIP_ATTR_TOS (1 << 4) #define IPIP_ATTR_PMTUDISC (1 << 5) +#define IPIP_ATTR_FWMARK (1 << 6) struct ipip_info { @@ -41,6 +42,7 @@ struct ipip_info uint32_t link; uint32_t local; uint32_t remote; + uint32_t fwmark; uint32_t ipip_mask; }; @@ -51,6 +53,7 @@ static struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = { [IFLA_IPTUN_TTL] = { .type = NLA_U8 }, [IFLA_IPTUN_TOS] = { .type = NLA_U8 }, [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 }, + [IFLA_IPTUN_FWMARK] = { .type = NLA_U32 }, }; static int ipip_alloc(struct rtnl_link *link) @@ -119,6 +122,11 @@ static int ipip_parse(struct rtnl_link *link, struct nlattr *data, ipip->ipip_mask |= IPIP_ATTR_PMTUDISC; } + if (tb[IFLA_IPTUN_FWMARK]) { + ipip->fwmark = nla_get_u32(tb[IFLA_IPTUN_FWMARK]); + ipip->ipip_mask |= IPIP_ATTR_FWMARK; + } + err = 0; errout: @@ -152,6 +160,9 @@ static int ipip_put_attrs(struct nl_msg *msg, struct rtnl_link *link) if (ipip->ipip_mask & IPIP_ATTR_PMTUDISC) NLA_PUT_U8(msg, IFLA_IPTUN_PMTUDISC, ipip->pmtudisc); + if (ipip->ipip_mask & IPIP_ATTR_FWMARK) + NLA_PUT_U32(msg, IFLA_IPTUN_FWMARK, ipip->fwmark); + nla_nest_end(msg, data); nla_put_failure: @@ -221,6 +232,11 @@ static void ipip_dump_details(struct rtnl_link *link, struct nl_dump_params *p) nl_dump(p, " pmtudisc "); nl_dump_line(p, "enabled (%#x)\n", ipip->pmtudisc); } + + if (ipip->ipip_mask & IPIP_ATTR_FWMARK) { + nl_dump(p, " fwmark "); + nl_dump_line(p, "%x\n", ipip->fwmark); + } } static int ipip_clone(struct rtnl_link *dst, struct rtnl_link *src) @@ -522,6 +538,46 @@ uint8_t rtnl_link_ipip_get_pmtudisc(struct rtnl_link *link) return ipip->pmtudisc; } +/** + * Set IPIP tunnel fwmark + * @arg link Link object + * @arg fwmark fwmark + * + * @return 0 on success or a negative error code + */ +int rtnl_link_ipip_set_fwmark(struct rtnl_link *link, uint32_t fwmark) +{ + struct ipip_info *ipip = link->l_info; + + IS_IPIP_LINK_ASSERT(link); + + ipip->fwmark = fwmark; + ipip->ipip_mask |= IPIP_ATTR_FWMARK; + + return 0; +} + +/** + * Get IPIP 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_ipip_get_fwmark(struct rtnl_link *link, uint32_t *fwmark) +{ + struct ipip_info *ipip = link->l_info; + + IS_IPIP_LINK_ASSERT(link); + + if (!(ipip->ipip_mask & IPIP_ATTR_FWMARK)) + return -NLE_NOATTR; + + *fwmark = ipip->fwmark; + + return 0; +} + static void __init ipip_init(void) { rtnl_link_register_info(&ipip_info_ops); diff --git a/libnl-route-3.sym b/libnl-route-3.sym index 7c1682d..f6f4a51 100644 --- a/libnl-route-3.sym +++ b/libnl-route-3.sym @@ -1193,6 +1193,8 @@ global: rtnl_link_ip6vti_set_remote; rtnl_link_ipgre_get_fwmark; rtnl_link_ipgre_set_fwmark; + rtnl_link_ipip_get_fwmark; + rtnl_link_ipip_set_fwmark; rtnl_link_ipvti_get_fwmark; rtnl_link_ipvti_set_fwmark; rtnl_link_is_ip6gre; |