Skip to content

Commit a2037b2

Browse files
schwabecron2
authored andcommitted
DCO Linux: Fix setting DCO ifmode failing on big endian archs
The problem is that SITNL_ADDATTR is not forcing type safety and on big endian architcutre passing a smaller size than the underlying integer type of data causes only the more significant byte(s) to be passed instead. A proper fix would be to add specific methods for common integer types like SITNL_ADDATTR_u8, SITNL_ADDATTR_u16, SITNL_ADDATTR_u32 like netlink library does with NLA_PUT_U32, NLA_PUT_U16, NLA_PUT_U8. Change-Id: I560f45fb0011180be8ca2b0e7fbc63030fa10f35 Github: closes OpenVPN/ovpn-dco#96 Signed-off-by: Arne Schwabe <arne@rfc2549.org> Acked-by: Antonio Quartulli <antonio@mandelbit.com> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1547 Message-Id: <20260219110954.21471-1-gert@greenie.muc.de> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35752.html Signed-off-by: Gert Doering <gert@greenie.muc.de> (cherry picked from commit b3e0e86)
1 parent 7ec8cbe commit a2037b2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/openvpn/networking_sitnl.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,15 @@ net_iface_new(openvpn_net_ctx_t *ctx, const char *iface, const char *type,
13561356
{
13571357
dco_context_t *dco = arg;
13581358
struct rtattr *data = SITNL_NEST(&req.n, sizeof(req), IFLA_INFO_DATA);
1359-
SITNL_ADDATTR(&req.n, sizeof(req), IFLA_OVPN_MODE, &dco->ifmode,
1359+
1360+
/* the netlink format is uint8_t for this and using something
1361+
* other than uint8_t here (enum underlying type is undefined but
1362+
* commonly int) causes the values to be 0 when passed
1363+
* on big endian arch as we only take the (biggest endian) byte
1364+
* directly at the address
1365+
*/
1366+
uint8_t ifmode = (uint8_t)dco->ifmode;
1367+
SITNL_ADDATTR(&req.n, sizeof(req), IFLA_OVPN_MODE, &ifmode,
13601368
sizeof(uint8_t));
13611369
SITNL_NEST_END(&req.n, data);
13621370
}

0 commit comments

Comments
 (0)