Squashed commit of the following:

net/netdev:  Add implementation of if_nametoindex() and if indextoname().
    net/pkt:  Raw AF_PACKET sockets now depend on CONFIG_NETDEV_IFINDEX.
    net/procfs:  Tweak to handle traversal of interfaces if CONFIG_NETDEV_IFINDEX is not defined.
    net/netdev.h:  Update netdev_findbyaddr() to use the assigned device index.
    Trivial typo fix
    net/netdev:  Add support for assigned an interface index to a device when it is regisgtered.
This commit is contained in:
Gregory Nutt
2018-06-25 12:08:10 -06:00
parent 68418262a5
commit 7c1394d814
12 changed files with 396 additions and 78 deletions
+1
View File
@@ -9,6 +9,7 @@ config NET_PKT
bool "Socket packet socket support"
default n
depends on NET_ETHERNET || EXPERIMENTAL
select NETDEV_IFINDEX
---help---
Enable or disable support for packet sockets.
+20 -17
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* net/socket/pkt_sockif.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2017-2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -47,10 +47,13 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/net/net.h>
#include <netpacket/packet.h>
#include <socket/socket.h>
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
#include "netdev/netdev.h"
#include <socket/socket.h>
#include "pkt/pkt.h"
#ifdef CONFIG_NET_PKT
@@ -342,16 +345,6 @@ static int pkt_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
static int pkt_bind(FAR struct socket *psock, FAR const struct sockaddr *addr,
socklen_t addrlen)
{
#if 0
char hwaddr[6] = /* our MAC for debugging */
{
0x00, 0xa1, 0xb1, 0xc1, 0xd1, 0xe1
};
#endif
char hwaddr[6] = /* MAC from ifconfig */
{
0x00, 0xe0, 0xde, 0xad, 0xbe, 0xef
};
int ifindex;
/* Verify that a valid address has been provided */
@@ -368,21 +361,31 @@ static int pkt_bind(FAR struct socket *psock, FAR const struct sockaddr *addr,
if (psock->s_type == SOCK_RAW)
{
FAR struct pkt_conn_s *conn = (FAR struct pkt_conn_s *)psock->s_conn;
FAR struct net_driver_s *dev;
/* Look at the addr and identify network interface */
ifindex = ((struct sockaddr_ll*)addr)->sll_ifindex;
#if 0
/* Get the MAC address of that interface */
memcpy(hwaddr, g_netdevices->d_mac.ether, 6);
#endif
dev = netdev_findbyindex(ifindex);
if (dev == NULL)
{
return -EADDRNOTAVAIL;
}
/* Only Ethernet is supported */
if (d_lltype != NET_LL_ETHERNET)
{
return -EAFNOSUPPORT;
}
/* Put ifindex and mac address into connection */
conn->ifindex = ifindex;
memcpy(conn->lmac, hwaddr, 6);
memcpy(conn->lmac, dev->d_mac.ether.ether_addr_octet, 6);
/* Mark the socket bound */