From 009e9f8d95f408ade9ce8012b50b990691eff1e2 Mon Sep 17 00:00:00 2001 From: "Kiedrzyn, PatrykX" Date: Tue, 24 Mar 2020 19:06:41 +0100 Subject: [15/17] Extend GEM attribute list --- include/netlink/route/link/gem.h | 10 +- lib/route/link/gem.c | 212 ++++++++++++++++++++++++++++++- libnl-route-3.sym | 8 ++ 3 files changed, 223 insertions(+), 7 deletions(-) diff --git a/include/netlink/route/link/gem.h b/include/netlink/route/link/gem.h index 2d20d4d..8414ba7 100644 --- a/include/netlink/route/link/gem.h +++ b/include/netlink/route/link/gem.h @@ -1,6 +1,6 @@ /****************************************************************************** * - * Copyright (c) 2018 Intel Corporation + * Copyright (c) 2018 - 2020 Intel Corporation * *****************************************************************************/ @@ -18,9 +18,17 @@ extern struct rtnl_link *rtnl_link_gem_alloc(void); extern int rtnl_link_is_gem(struct rtnl_link *); extern int rtnl_link_gem_set_id(struct rtnl_link *, uint16_t); extern int rtnl_link_gem_set_index(struct rtnl_link *, uint16_t); +extern int rtnl_link_gem_set_traffic_type(struct rtnl_link *, uint8_t); +extern int rtnl_link_gem_set_dir(struct rtnl_link *, uint8_t); +extern int rtnl_link_gem_set_enc(struct rtnl_link *, uint8_t); +extern int rtnl_link_gem_set_max_size(struct rtnl_link *, uint16_t); extern int rtnl_link_gem_set_tcont(struct rtnl_link *, uint32_t); extern int rtnl_link_gem_get_id(struct rtnl_link *); extern int rtnl_link_gem_get_index(struct rtnl_link *); +extern int rtnl_link_gem_get_traffic_type(struct rtnl_link *); +extern int rtnl_link_gem_get_dir(struct rtnl_link *); +extern int rtnl_link_gem_get_enc(struct rtnl_link *); +extern int rtnl_link_gem_get_max_size(struct rtnl_link *); extern int rtnl_link_gem_get_tcont(struct rtnl_link *); #ifdef __cplusplus diff --git a/lib/route/link/gem.c b/lib/route/link/gem.c index fa13333..45b4ca7 100644 --- a/lib/route/link/gem.c +++ b/lib/route/link/gem.c @@ -1,6 +1,6 @@ /****************************************************************************** * - * Copyright (c) 2018 Intel Corporation + * Copyright (c) 2018 - 2020 Intel Corporation * *****************************************************************************/ @@ -16,12 +16,20 @@ /** @cond SKIP */ #define GEM_HAS_IDX (1<<0) #define GEM_HAS_ID (1<<1) -#define GEM_HAS_TCONT (1<<2) +#define GEM_HAS_TRAFFIC_TYPE (1<<2) +#define GEM_HAS_DIR (1<<3) +#define GEM_HAS_ENC (1<<4) +#define GEM_HAS_MAX_SIZE (1<<5) +#define GEM_HAS_TCONT (1<<6) struct gem_info { uint16_t index; uint16_t id; + uint8_t traffic_type; + uint8_t dir; + uint8_t enc; + uint16_t max_size; uint32_t tcont_if; uint32_t mask; }; @@ -32,6 +40,10 @@ enum { IFLA_PON_GEM_IDX, IFLA_PON_GEM_ID, IFLA_PON_GEM_TCONT, + IFLA_PON_GEM_TRAFFIC_TYPE, + IFLA_PON_GEM_MAX_SIZE, + IFLA_PON_GEM_DIR, + IFLA_PON_GEM_ENC, IFLA_PON_GEM_MAX }; @@ -40,6 +52,10 @@ enum { static struct nla_policy gem_policy[IFLA_PON_GEM_MAX + 1] = { [IFLA_PON_GEM_IDX] = { .type = NLA_U16 }, [IFLA_PON_GEM_ID] = { .type = NLA_U32 }, + [IFLA_PON_GEM_TRAFFIC_TYPE] = { .type = NLA_U8 }, + [IFLA_PON_GEM_DIR] = { .type = NLA_U8 }, + [IFLA_PON_GEM_ENC] = { .type = NLA_U8 }, + [IFLA_PON_GEM_MAX_SIZE] = { .type = NLA_U16 }, [IFLA_PON_GEM_TCONT] = { .type = NLA_U32 }, }; @@ -89,6 +105,26 @@ static int gem_parse(struct rtnl_link *link, struct nlattr *data, gi->mask |= GEM_HAS_ID; } + if (tb[IFLA_PON_GEM_TRAFFIC_TYPE]) { + gi->traffic_type = nla_get_u32(tb[IFLA_PON_GEM_TRAFFIC_TYPE]); + gi->mask |= GEM_HAS_TRAFFIC_TYPE; + } + + if (tb[IFLA_PON_GEM_DIR]) { + gi->dir = nla_get_u32(tb[IFLA_PON_GEM_DIR]); + gi->mask |= GEM_HAS_DIR; + } + + if (tb[IFLA_PON_GEM_ENC]) { + gi->enc = nla_get_u32(tb[IFLA_PON_GEM_ENC]); + gi->mask |= GEM_HAS_ENC; + } + + if (tb[IFLA_PON_GEM_MAX_SIZE]) { + gi->max_size = nla_get_u32(tb[IFLA_PON_GEM_MAX_SIZE]); + gi->mask |= GEM_HAS_MAX_SIZE; + } + if (tb[IFLA_PON_GEM_TCONT]) { gi->tcont_if = nla_get_u32(tb[IFLA_PON_GEM_TCONT]); gi->mask |= GEM_HAS_TCONT; @@ -111,8 +147,10 @@ static void gem_dump_line(struct rtnl_link *link, struct nl_dump_params *p) { struct gem_info *gi = link->l_info; - nl_dump(p, "index %d gem-id %d tcont-id %d", gi->index, gi->id, - gi->tcont_if); + nl_dump(p, + "index %d gem-id %d traffic-type %d dir %d enc %d max-size %d tcont-id %d", + gi->index, gi->id, gi->traffic_type, gi->dir, gi->enc, + gi->max_size, gi->tcont_if); } static void gem_dump_details(struct rtnl_link *link, struct nl_dump_params *p) @@ -120,8 +158,10 @@ static void gem_dump_details(struct rtnl_link *link, struct nl_dump_params *p) struct gem_info *gi = link->l_info; /* TODO: To be extended? */ - nl_dump(p, "index %d gem-id %d tcont-id %d", gi->index, gi->id, - gi->tcont_if); + nl_dump(p, + "index %d gem-id %d traffic-type %d dir %d enc %d max-size %d tcont-id %d", + gi->index, gi->id, gi->traffic_type, gi->dir, gi->enc, + gi->max_size, gi->tcont_if); nl_dump(p, "\n"); } @@ -156,6 +196,18 @@ static int gem_put_attrs(struct nl_msg *msg, struct rtnl_link *link) if (gi->mask & GEM_HAS_ID) NLA_PUT_U32(msg, IFLA_PON_GEM_ID, gi->id); + if (gi->mask & GEM_HAS_TRAFFIC_TYPE) + NLA_PUT_U8(msg, IFLA_PON_GEM_TRAFFIC_TYPE, gi->traffic_type); + + if (gi->mask & GEM_HAS_DIR) + NLA_PUT_U8(msg, IFLA_PON_GEM_DIR, gi->dir); + + if (gi->mask & GEM_HAS_ENC) + NLA_PUT_U8(msg, IFLA_PON_GEM_ENC, gi->enc); + + if (gi->mask & GEM_HAS_MAX_SIZE) + NLA_PUT_U16(msg, IFLA_PON_GEM_MAX_SIZE, gi->max_size); + if (gi->mask & GEM_HAS_TCONT) NLA_PUT_U32(msg, IFLA_PON_GEM_TCONT, gi->tcont_if); @@ -297,6 +349,154 @@ int rtnl_link_gem_get_id(struct rtnl_link *link) return 0; } +/** + * Set GEM traffic type + * @arg link Link object + * @arg traffic_type GEM traffic type + * + * @return 0 on success or a negative error code + */ +int rtnl_link_gem_set_traffic_type(struct rtnl_link *link, uint8_t traffic_type) +{ + struct gem_info *gi = link->l_info; + + IS_GEM_LINK_ASSERT(link); + + gi->traffic_type = traffic_type; + gi->mask |= GEM_HAS_TRAFFIC_TYPE; + + return 0; +} + +/** + * Get GEM traffic type + * @arg link Link object + * + * @return GEM traffic type, 0 if not set or a negative error code. + */ +int rtnl_link_gem_get_traffic_type(struct rtnl_link *link) +{ + struct gem_info *gi = link->l_info; + + IS_GEM_LINK_ASSERT(link); + + if (gi->mask & GEM_HAS_TRAFFIC_TYPE) + return gi->traffic_type; + else + return 0; +} + +/** +* Set GEM direction +* @arg link Link object +* @arg dir GEM direction +* +* @return 0 on success or a negative error code +*/ +int rtnl_link_gem_set_dir(struct rtnl_link *link, uint8_t dir) +{ + struct gem_info *gi = link->l_info; + + IS_GEM_LINK_ASSERT(link); + + gi->dir = dir; + gi->mask |= GEM_HAS_DIR; + + return 0; +} + +/** +* Get GEM direction +* @arg link Link object +* +* @return GEM direction, 0 if not set or a negative error code. +*/ +int rtnl_link_gem_get_dir(struct rtnl_link *link) +{ + struct gem_info *gi = link->l_info; + + IS_GEM_LINK_ASSERT(link); + + if (gi->mask & GEM_HAS_DIR) + return gi->dir; + else + return 0; +} + +/** + * Set GEM port encryption mode + * @arg link Link object + * @arg enc GEM port encryption mode + * + * @return 0 on success or a negative error code + */ +int rtnl_link_gem_set_enc(struct rtnl_link *link, uint8_t enc) +{ + struct gem_info *gi = link->l_info; + + IS_GEM_LINK_ASSERT(link); + + gi->enc = enc; + gi->mask |= GEM_HAS_ENC; + + return 0; +} + +/** + * Get GEM port encryption mode + * @arg link Link object + * + * @return GEM port encryption mode, 0 if not set or a negative error code. + */ +int rtnl_link_gem_get_enc(struct rtnl_link *link) +{ + struct gem_info *gi = link->l_info; + + IS_GEM_LINK_ASSERT(link); + + if (gi->mask & GEM_HAS_ENC) + return gi->enc; + else + return 0; +} + +/** +* Set GEM maximum size +* @arg link Link object +* @arg max_size GEM maximum size +* +* @return 0 on success or a negative error code +*/ +int rtnl_link_gem_set_max_size(struct rtnl_link *link, uint16_t max_size) +{ + struct gem_info *gi = link->l_info; + + IS_GEM_LINK_ASSERT(link); + + gi->max_size = max_size; + gi->mask |= GEM_HAS_MAX_SIZE; + + return 0; +} + +/** +* Get GEM maximum size +* @arg link Link object +* +* @return GEM maximum size, 0 if not set or a negative error code. +*/ +int rtnl_link_gem_get_max_size(struct rtnl_link *link) +{ + struct gem_info *gi = link->l_info; + + IS_GEM_LINK_ASSERT(link); + + if (gi->mask & GEM_HAS_MAX_SIZE) + return gi->max_size; + else + return 0; +} + /** * Set TCONT ID * @arg link Link object diff --git a/libnl-route-3.sym b/libnl-route-3.sym index e570fca..141114a 100644 --- a/libnl-route-3.sym +++ b/libnl-route-3.sym @@ -294,8 +294,16 @@ global: rtnl_link_gem_alloc; rtnl_link_gem_get_id; rtnl_link_gem_get_index; + rtnl_link_gem_get_traffic_type; + rtnl_link_gem_get_dir; + rtnl_link_gem_get_enc; + rtnl_link_gem_get_max_size; rtnl_link_gem_set_id; rtnl_link_gem_set_index; + rtnl_link_gem_set_traffic_type; + rtnl_link_gem_set_dir; + rtnl_link_gem_set_enc; + rtnl_link_gem_set_max_size; rtnl_link_gem_get_tcont; rtnl_link_gem_set_tcont; rtnl_link_get; -- 2.17.1