Skip to content

Commit

Permalink
netlink, pasta: Turn nl_link_up() into a generic function to set link…
Browse files Browse the repository at this point in the history
… flags

In the next patches, we'll reuse it to set flags other than IFF_UP.

Signed-off-by: Stefano Brivio <[email protected]>
Reviewed-by: David Gibson <[email protected]>
  • Loading branch information
sbrivio-rh committed Aug 15, 2024
1 parent 8231ce5 commit 0c74068
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,22 +968,25 @@ int nl_link_set_mtu(int s, unsigned int ifi, int mtu)
}

/**
* nl_link_up() - Bring link up
* nl_link_set_flags() - Set link flags
* @s: Netlink socket
* @ifi: Interface index
* @set: Device flags to set
* @change: Mask of device flag changes
*
* Return: 0 on success, negative error code on failure
*/
int nl_link_up(int s, unsigned int ifi)
int nl_link_set_flags(int s, unsigned int ifi,
unsigned int set, unsigned int change)
{
struct req_t {
struct nlmsghdr nlh;
struct ifinfomsg ifm;
} req = {
.ifm.ifi_family = AF_UNSPEC,
.ifm.ifi_index = ifi,
.ifm.ifi_flags = IFF_UP,
.ifm.ifi_change = IFF_UP,
.ifm.ifi_flags = set,
.ifm.ifi_change = change,
};

return nl_do(s, &req, RTM_NEWLINK, 0, sizeof(req));
Expand Down
3 changes: 2 additions & 1 deletion netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ int nl_addr_dup(int s_src, unsigned int ifi_src,
int nl_link_get_mac(int s, unsigned int ifi, void *mac);
int nl_link_set_mac(int s, unsigned int ifi, const void *mac);
int nl_link_set_mtu(int s, unsigned int ifi, int mtu);
int nl_link_up(int s, unsigned int ifi);
int nl_link_set_flags(int s, unsigned int ifi,
unsigned int set, unsigned int change);

#endif /* NETLINK_H */
4 changes: 2 additions & 2 deletions pasta.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void pasta_ns_conf(struct ctx *c)
{
int rc = 0;

rc = nl_link_up(nl_sock_ns, 1 /* lo */);
rc = nl_link_set_flags(nl_sock_ns, 1 /* lo */, IFF_UP, IFF_UP);
if (rc < 0)
die("Couldn't bring up loopback interface in namespace: %s",
strerror(-rc));
Expand All @@ -306,7 +306,7 @@ void pasta_ns_conf(struct ctx *c)
if (c->mtu != -1)
nl_link_set_mtu(nl_sock_ns, c->pasta_ifi, c->mtu);

nl_link_up(nl_sock_ns, c->pasta_ifi);
nl_link_set_flags(nl_sock_ns, c->pasta_ifi, IFF_UP, IFF_UP);

if (c->ifi4) {
if (c->ip4.no_copy_addrs) {
Expand Down

0 comments on commit 0c74068

Please sign in to comment.