Skip to content

Commit f13a042

Browse files
MainKtobiwac
authored andcommitted
netlink/route: Support modifying IFLA_ADDRESS with RTM_NEWLINK
Allows setting link-layer address (MAC) by specifying the IFLA_ADDRESS attribute on RTM_NEWLINK requests. Reviewed by: melifaro, obiwac, mckusick (mentor) Approved by: melifaro, obiwac, mckusick (mentor) Sponsored by: Google LLC (GSoC) Differential Revision: https://reviews.freebsd.org/D51922
1 parent 3068d70 commit f13a042

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

sys/netlink/route/iface.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ static const struct nlattr_parser nla_p_linfo[] = {
403403
NL_DECLARE_ATTR_PARSER(linfo_parser, nla_p_linfo);
404404

405405
static const struct nlattr_parser nla_p_if[] = {
406+
{ .type = IFLA_ADDRESS, .off = _OUT(ifla_address), .cb = nlattr_get_nla },
406407
{ .type = IFLA_IFNAME, .off = _OUT(ifla_ifname), .cb = nlattr_get_string },
407408
{ .type = IFLA_MTU, .off = _OUT(ifla_mtu), .cb = nlattr_get_uint32 },
408409
{ .type = IFLA_LINK, .off = _OUT(ifla_link), .cb = nlattr_get_uint32 },

sys/netlink/route/iface_drivers.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ _nl_modify_ifp_generic(struct ifnet *ifp, struct nl_parsed_link *lattrs,
105105
}
106106
}
107107

108+
if (lattrs->ifla_address != NULL) {
109+
if (nlp_has_priv(npt->nlp, PRIV_NET_SETIFMAC)) {
110+
error = if_setlladdr(ifp,
111+
NLA_DATA(lattrs->ifla_address),
112+
NLA_DATA_LEN(lattrs->ifla_address));
113+
if (error != 0) {
114+
nlmsg_report_err_msg(npt,
115+
"setting IFLA_ADDRESS failed with error code: %d",
116+
error);
117+
return (error);
118+
}
119+
} else {
120+
nlmsg_report_err_msg(npt,
121+
"Not enough privileges to set IFLA_ADDRESS");
122+
return (EPERM);
123+
}
124+
}
125+
108126
return (0);
109127
}
110128

sys/netlink/route/route_var.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct nl_parsed_link {
6969
char *ifla_cloner;
7070
char *ifla_ifalias;
7171
struct nlattr *ifla_idata;
72+
struct nlattr *ifla_address;
7273
unsigned short ifi_type;
7374
int ifi_index;
7475
uint32_t ifla_link;

0 commit comments

Comments
 (0)