Skip to content

Commit

Permalink
Merge pull request torvalds#436 from libos-nuse/feature-lkl_ifname_to…
Browse files Browse the repository at this point in the history
…_ifindex

lkl-upstream: add lkl_ifname_to_ifindex()
  • Loading branch information
thehajime authored Jun 12, 2018
2 parents f74e30f + 2aa468e commit 8dcf543
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tools/lkl/include/lkl.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,14 @@ int lkl_set_ipv6_gateway(void* addr);
int lkl_if_set_ipv6_gateway(int ifindex, void *addr,
unsigned int netmask_len, void *gw_addr);

/**
* lkl_ifname_to_ifindex - obtain ifindex of an interface by name
*
* @name - string of an interface
* @returns - return an integer of ifindex if no error
*/
int lkl_ifname_to_ifindex(const char *name);

/**
* lkl_netdev - host network device handle, defined in lkl_host.h.
*/
Expand Down
18 changes: 18 additions & 0 deletions tools/lkl/lib/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ static inline int ifindex_to_name(int sock, struct lkl_ifreq *ifr, int ifindex)
return lkl_sys_ioctl(sock, LKL_SIOCGIFNAME, (long)ifr);
}

int lkl_ifname_to_ifindex(const char *name)
{
struct lkl_ifreq ifr;
int fd, ret;

fd = lkl_sys_socket(LKL_AF_INET, LKL_SOCK_DGRAM, 0);
if (fd < 0)
return fd;

strcpy(ifr.lkl_ifr_name, name);

ret = lkl_sys_ioctl(fd, LKL_SIOCGIFINDEX, (long)&ifr);
if (ret < 0)
return ret;

return ifr.lkl_ifr_ifindex;
}

int lkl_if_up(int ifindex)
{
struct lkl_ifreq ifr;
Expand Down

0 comments on commit 8dcf543

Please sign in to comment.