Commit 4e9b9a7f authored by Robert Lubos's avatar Robert Lubos Committed by Carles Cufi
Browse files

drivers: net: loopback: Register loopback IP address to the interface



Regsiter loopback IPv4/IPv6 to the loopback interface during
interface initialization.

Signed-off-by: default avatarRobert Lubos <robert.lubos@nordicsemi.no>
parent 6f46124d
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -33,9 +33,31 @@ int loopback_dev_init(const struct device *dev)

static void loopback_init(struct net_if *iface)
{
	struct net_if_addr *ifaddr;

	/* RFC 7042, s.2.1.1. address to use in documentation */
	net_if_set_link_addr(iface, "\x00\x00\x5e\x00\x53\xff", 6,
			     NET_LINK_DUMMY);

	if (IS_ENABLED(CONFIG_NET_IPV4)) {
		struct in_addr ipv4_loopback = INADDR_LOOPBACK_INIT;

		ifaddr = net_if_ipv4_addr_add(iface, &ipv4_loopback,
					      NET_ADDR_AUTOCONF, 0);
		if (!ifaddr) {
			LOG_ERR("Failed to register IPv4 loopback address");
		}
	}

	if (IS_ENABLED(CONFIG_NET_IPV6)) {
		struct in6_addr ipv6_loopback = IN6ADDR_LOOPBACK_INIT;

		ifaddr = net_if_ipv6_addr_add(iface, &ipv6_loopback,
					      NET_ADDR_AUTOCONF, 0);
		if (!ifaddr) {
			LOG_ERR("Failed to register IPv6 loopback address");
		}
	}
}

static int loopback_send(const struct device *dev, struct net_pkt *pkt)
+2 −0
Original line number Diff line number Diff line
@@ -390,6 +390,8 @@ extern const struct in6_addr in6addr_loopback;
#define INADDR_ANY 0
#define INADDR_ANY_INIT { { { INADDR_ANY } } }

#define INADDR_LOOPBACK_INIT  { { { 127, 0, 0, 1 } } }

/** @endcond */

enum net_ip_mtu {
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ config NET_IF_MAX_IPV4_COUNT
config NET_IF_UNICAST_IPV4_ADDR_COUNT
	int "Max number of unicast IPv4 addresses per network interface"
	default 2 if NET_IPV4_AUTO
	default 2 if NET_LOOPBACK
	default 1

config NET_IF_MCAST_IPV4_ADDR_COUNT
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ config NET_IF_MAX_IPV6_COUNT
config NET_IF_UNICAST_IPV6_ADDR_COUNT
	int "Max number of unicast IPv6 addresses per network interface"
	default 6 if NET_L2_OPENTHREAD
	default 3 if NET_LOOPBACK
	default 2

config NET_IF_MCAST_IPV6_ADDR_COUNT