Skip to content

Commit 69526c6

Browse files
committed
macsec: merge branch 'macsec-sci-endianness'
Revert API change regarding endianness of MACSec's 'sci' argument. During 3.2.29 development, that was changed. Restore the released 3.2.28 behavior. http://lists.infradead.org/pipermail/libnl/2016-December/002264.html
2 parents 02cccc6 + 36777ba commit 69526c6

File tree

1 file changed

+67
-5
lines changed

1 file changed

+67
-5
lines changed

lib/route/link/macsec.c

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
* Copyright (c) 2016 Sabrina Dubroca <[email protected]>
1010
*/
1111

12+
/**
13+
* @ingroup link
14+
* @defgroup macsec MACsec
15+
* MACsec link module
16+
*
17+
* @details
18+
* \b Link Type Name: "macsec"
19+
*
20+
* @route_doc{link_macsec, MACsec Documentation}
21+
*
22+
* @{
23+
*/
1224
#include <netlink-private/netlink.h>
1325
#include <netlink/netlink.h>
1426
#include <netlink/attr.h>
@@ -20,6 +32,7 @@
2032

2133
#include <linux/if_macsec.h>
2234

35+
/** @cond SKIP */
2336
#define MACSEC_ATTR_SCI (1 << 0)
2437
#define MACSEC_ATTR_ICV_LEN (1 << 1)
2538
#define MACSEC_ATTR_CIPHER_SUITE (1 << 2)
@@ -49,6 +62,10 @@ struct macsec_info {
4962
uint32_t ce_mask;
5063
};
5164

65+
#define DEFAULT_ICV_LEN 16
66+
67+
/** @endcond */
68+
5269
static struct nla_policy macsec_policy[IFLA_MACSEC_MAX+1] = {
5370
[IFLA_MACSEC_SCI] = { .type = NLA_U64 },
5471
[IFLA_MACSEC_ICV_LEN] = { .type = NLA_U8 },
@@ -64,8 +81,16 @@ static struct nla_policy macsec_policy[IFLA_MACSEC_MAX+1] = {
6481
[IFLA_MACSEC_VALIDATION] = { .type = NLA_U8 },
6582
};
6683

67-
#define DEFAULT_ICV_LEN 16
84+
/**
85+
* @name MACsec Object
86+
* @{
87+
*/
6888

89+
/**
90+
* Allocate link object of type MACsec
91+
*
92+
* @return Allocated link object or NULL.
93+
*/
6994
static int macsec_alloc(struct rtnl_link *link)
7095
{
7196
struct macsec_info *info;
@@ -104,7 +129,7 @@ static int macsec_parse(struct rtnl_link *link, struct nlattr *data,
104129
info = link->l_info;
105130

106131
if (tb[IFLA_MACSEC_SCI]) {
107-
info->sci = ntohll(nla_get_u64(tb[IFLA_MACSEC_SCI]));
132+
info->sci = nla_get_u64(tb[IFLA_MACSEC_SCI]);
108133
info->ce_mask |= MACSEC_ATTR_SCI;
109134
}
110135

@@ -195,7 +220,9 @@ static char *replay_protect_str(char *buf, uint8_t replay_protect, uint8_t windo
195220
return buf;
196221
}
197222

223+
/** @cond SKIP */
198224
#define PRINT_FLAG(buf, i, field, c) ({ if (i->field == 1) *buf++ = c; })
225+
/** @endcond */
199226
static char *flags_str(char *buf, unsigned char len, struct macsec_info *info)
200227
{
201228
char *tmp = buf;
@@ -234,7 +261,7 @@ static void macsec_dump_line(struct rtnl_link *link, struct nl_dump_params *p)
234261
struct macsec_info *info = link->l_info;
235262
char tmp[128];
236263

237-
nl_dump(p, "sci %016llx <%s>", info->sci, flags_str(tmp, sizeof(tmp), info));
264+
nl_dump(p, "sci %016llx <%s>", ntohll(info->sci), flags_str(tmp, sizeof(tmp), info));
238265
}
239266

240267
static void macsec_dump_details(struct rtnl_link *link, struct nl_dump_params *p)
@@ -243,7 +270,7 @@ static void macsec_dump_details(struct rtnl_link *link, struct nl_dump_params *p
243270
char tmp[128];
244271

245272
nl_dump(p, " sci %016llx protect %s encoding_sa %d encrypt %s send_sci %s validate %s %s\n",
246-
info->sci, values_on_off[info->protect], info->encoding_sa, values_on_off[info->encrypt], values_on_off[info->send_sci],
273+
ntohll(info->sci), values_on_off[info->protect], info->encoding_sa, values_on_off[info->encrypt], values_on_off[info->send_sci],
247274
VALIDATE_STR[info->validate],
248275
replay_protect_str(tmp, info->replay_protect, info->window));
249276
nl_dump(p, " cipher suite: %016llx, icv_len %d\n",
@@ -277,7 +304,7 @@ static int macsec_put_attrs(struct nl_msg *msg, struct rtnl_link *link)
277304
return -NLE_MSGSIZE;
278305

279306
if (info->ce_mask & MACSEC_ATTR_SCI)
280-
NLA_PUT_U64(msg, IFLA_MACSEC_SCI, htonll(info->sci));
307+
NLA_PUT_U64(msg, IFLA_MACSEC_SCI, info->sci);
281308
else if (info->ce_mask & MACSEC_ATTR_PORT)
282309
NLA_PUT_U16(msg, IFLA_MACSEC_PORT, htons(info->port));
283310

@@ -387,11 +414,13 @@ static void __exit macsec_exit(void)
387414
rtnl_link_unregister_info(&macsec_info_ops);
388415
}
389416

417+
/** @cond SKIP */
390418
#define IS_MACSEC_LINK_ASSERT(link) \
391419
if ((link)->l_info_ops != &macsec_info_ops) { \
392420
APPBUG("Link is not a MACsec link. set type \"macsec\" first."); \
393421
return -NLE_OPNOTSUPP; \
394422
}
423+
/** @endcond */
395424

396425
struct rtnl_link *rtnl_link_macsec_alloc(void)
397426
{
@@ -408,6 +437,13 @@ struct rtnl_link *rtnl_link_macsec_alloc(void)
408437
return link;
409438
}
410439

440+
/**
441+
* Set SCI
442+
* @arg link Link object
443+
* @arg sci Secure Channel Identifier in network byte order
444+
*
445+
* @return 0 on success or a negative error code.
446+
*/
411447
int rtnl_link_macsec_set_sci(struct rtnl_link *link, uint64_t sci)
412448
{
413449
struct macsec_info *info = link->l_info;
@@ -420,6 +456,14 @@ int rtnl_link_macsec_set_sci(struct rtnl_link *link, uint64_t sci)
420456
return 0;
421457
}
422458

459+
/**
460+
* Get SCI
461+
* @arg link Link object
462+
* @arg sci On return points to the Secure Channel Identifier
463+
* in network byte order
464+
*
465+
* @return 0 on success or a negative error code.
466+
*/
423467
int rtnl_link_macsec_get_sci(struct rtnl_link *link, uint64_t *sci)
424468
{
425469
struct macsec_info *info = link->l_info;
@@ -435,6 +479,13 @@ int rtnl_link_macsec_get_sci(struct rtnl_link *link, uint64_t *sci)
435479
return 0;
436480
}
437481

482+
/**
483+
* Set port identifier
484+
* @arg link Link object
485+
* @arg port Port identifier in host byte order
486+
*
487+
* @return 0 on success or a negative error code.
488+
*/
438489
int rtnl_link_macsec_set_port(struct rtnl_link *link, uint16_t port)
439490
{
440491
struct macsec_info *info = link->l_info;
@@ -447,6 +498,13 @@ int rtnl_link_macsec_set_port(struct rtnl_link *link, uint16_t port)
447498
return 0;
448499
}
449500

501+
/**
502+
* Get port identifier
503+
* @arg link Link object
504+
* @arg port On return points to the port identifier in host byte order
505+
*
506+
* @return 0 on success or a negative error code.
507+
*/
450508
int rtnl_link_macsec_get_port(struct rtnl_link *link, uint16_t *port)
451509
{
452510
struct macsec_info *info = link->l_info;
@@ -785,3 +843,7 @@ int rtnl_link_macsec_get_scb(struct rtnl_link *link, uint8_t *scb)
785843

786844
return 0;
787845
}
846+
847+
/** @} */
848+
849+
/** @} */

0 commit comments

Comments
 (0)