Skip to content

Commit

Permalink
link: hsr: add API for HSR operational mode
Browse files Browse the repository at this point in the history
      rtnl_hsr_get_op_mode()
      rtnl_hsr_set_op_mode()

HSR operational modes:
      H (HSR_OP_MODE_H) [0]
      N (HSR_OP_MODE_N) [1]
      T (HSR_OP_MODE_T) [2]
      U (HSR_OP_MODE_U) [3]

Signed-off-by: Volodymyr Bendiuga <[email protected]>
  • Loading branch information
voldymyr committed Jan 24, 2024
1 parent 044c76d commit 100dbee
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/linux-private/linux/if_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,13 @@ enum {
HSR_PROTOCOL_MAX,
};

enum {
HSR_OP_MODE_H,
HSR_OP_MODE_N,
HSR_OP_MODE_T,
HSR_OP_MODE_U,
};

enum {
IFLA_HSR_UNSPEC,
IFLA_HSR_SLAVE1,
Expand All @@ -1127,6 +1134,7 @@ enum {
* HSR. For example PRP.
*/
IFLA_HSR_EFT, /* Entry Forget Time */
IFLA_HSR_MODE, /* HSR Mode (H, N, T, U) */
__IFLA_HSR_MAX,
};

Expand Down
3 changes: 3 additions & 0 deletions include/netlink/route/link/hsr.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ extern "C" {
extern int rtnl_hsr_get_eft(struct rtnl_link *link, uint32_t *eft);
extern int rtnl_hsr_set_eft(struct rtnl_link *link, uint32_t eft);

extern int rtnl_hsr_get_op_mode(struct rtnl_link *link, uint32_t *mode);
extern int rtnl_hsr_set_op_mode(struct rtnl_link *link, uint32_t mode);

#ifdef __cplusplus
}
#endif
Expand Down
47 changes: 47 additions & 0 deletions lib/route/link/hsr.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define HSR_ATTR_SUPERVISION_ADDR (1 << 5)
#define HSR_ATTR_SEQ_NR (1 << 6)
#define HSR_ATTR_EFT (1 << 7)
#define HSR_ATTR_HSR_OP_MODE (1 << 8)

struct hsr_info {
uint32_t hi_slave1;
Expand All @@ -44,6 +45,7 @@ struct hsr_info {
unsigned char *hi_sv_addr;
uint16_t hi_seq_nr;
uint32_t hi_eft;
uint32_t hi_hsr_mode;
uint32_t hi_mask;
};

Expand All @@ -56,6 +58,7 @@ static struct nla_policy hsr_policy[IFLA_HSR_MAX+1] = {
[IFLA_HSR_SEQ_NR] = { .type = NLA_U16 },
[IFLA_HSR_PROTOCOL] = { .type = NLA_U8 },
[IFLA_HSR_EFT] = { .type = NLA_U32 },
[IFLA_HSR_MODE] = { .type = NLA_U32 },
};


Expand Down Expand Up @@ -153,6 +156,11 @@ static int hsr_parse(struct rtnl_link *link, struct nlattr *data,
info->hi_mask |= HSR_ATTR_EFT;
}

if (tb[IFLA_HSR_MODE]) {
info->hi_hsr_mode = nla_get_u32(tb[IFLA_HSR_MODE]);
info->hi_mask |= HSR_ATTR_HSR_OP_MODE;
}

out:
return err;
}
Expand Down Expand Up @@ -183,6 +191,9 @@ static int hsr_put_attrs(struct nl_msg *msg, struct rtnl_link *link)
if (info->hi_mask & HSR_ATTR_EFT)
NLA_PUT_U32(msg, IFLA_HSR_EFT, info->hi_eft);

if (info->hi_mask & HSR_ATTR_HSR_OP_MODE)
NLA_PUT_U32(msg, IFLA_HSR_MODE, info->hi_hsr_mode);

nla_nest_end(msg, data);

return 0;
Expand Down Expand Up @@ -474,6 +485,42 @@ int rtnl_hsr_set_eft(struct rtnl_link *link, uint32_t eft)
return 0;
}

/**
* Get Operational Mode for HSR link
* @arg link HSR link
* @arg mode operational mode
*
* @return 0 on success or a negative error code otherwise.
*/
int rtnl_hsr_get_op_mode(struct rtnl_link *link, uint32_t *mode)
{
struct hsr_info *info = link->l_info;

IS_HSR_LINK_ASSERT(link);

*mode = info->hi_hsr_mode;

return 0;
}

/**
* Set Operational mode for an HSR link
* @arg link HSR link
* @arg mode Opmode HSR_OP_MODE_H, _N, _T, _U (0 - (H), 1 - (N), 2 - (T), 3 - (U))
*
* @return 0 on success or negative error code in case of an error
*/
int rtnl_hsr_set_op_mode(struct rtnl_link *link, uint32_t mode)
{
struct hsr_info *info = link->l_info;

IS_HSR_LINK_ASSERT(link);

info->hi_hsr_mode = mode;
info->hi_mask |= HSR_ATTR_HSR_OP_MODE;

return 0;
}

/**
* Allocate link object of type HSR
Expand Down
2 changes: 2 additions & 0 deletions libnl-route-3.sym
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,8 @@ global:
rtnl_hsr_set_proto;
rtnl_hsr_get_eft;
rtnl_hsr_set_eft;
rtnl_hsr_get_op_mode;
rtnl_hsr_set_op_mode;
rtnl_link_interlink_alloc;
rtnl_link_interlink_add;
rtnl_link_is_interlink;
Expand Down

0 comments on commit 100dbee

Please sign in to comment.