Skip to content

Commit

Permalink
netdev/ipv6: Move xxx_ipv6multicast from arch to common code
Browse files Browse the repository at this point in the history
The `xxx_ipv6multicast` function in each driver is not adapted to
multiple IPv6 addresses yet, and they're redundant, so try to take them
into common code.

Change:
1. Add MAC `g_ipv6_ethallnodes` and `g_ipv6_ethallrouters` in
   `icmpv6_devinit` and call them in `netdev_register`
2. Add multicast MAC for Neighbor Solicitation when adding any IPv6
   address, and remove them when IPv6 address is removed
3. Select `NET_MCASTGROUP` when `NET_ICMPv6` because now we need
   `d_addmac` when we have ICMPv6

Note:
We want modules outside net stack to call functions like
`netdev_ipv6_add` and never touch the related MAC address, so these MAC
functions are added as internal functions to `net/netdev/netdev.h`

Signed-off-by: Zhe Weng <[email protected]>
  • Loading branch information
wengzhe authored and xiaoxiang781216 committed Dec 16, 2023
1 parent 06e5b66 commit 5aeb154
Show file tree
Hide file tree
Showing 37 changed files with 290 additions and 2,066 deletions.
82 changes: 0 additions & 82 deletions arch/arm/src/at32/at32_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,6 @@ static inline void at32_ethgpioconfig(struct at32_ethmac_s *priv);
static int at32_ethreset(struct at32_ethmac_s *priv);
static int at32_macconfig(struct at32_ethmac_s *priv);
static void at32_macaddress(struct at32_ethmac_s *priv);
#ifdef CONFIG_NET_ICMPv6
static void at32_ipv6multicast(struct at32_ethmac_s *priv);
#endif
static int at32_macenable(struct at32_ethmac_s *priv);
static int at32_ethconfig(struct at32_ethmac_s *priv);

Expand Down Expand Up @@ -3651,79 +3648,6 @@ static void at32_macaddress(struct at32_ethmac_s *priv)
at32_putreg(regval, AT32_ETH_MACA0LR);
}

/****************************************************************************
* Function: at32_ipv6multicast
*
* Description:
* Configure the IPv6 multicast MAC address.
*
* Input Parameters:
* priv - A reference to the private driver state structure
*
* Returned Value:
* OK on success; Negated errno on failure.
*
* Assumptions:
*
****************************************************************************/

#ifdef CONFIG_NET_ICMPv6
static void at32_ipv6multicast(struct at32_ethmac_s *priv)
{
struct net_driver_s *dev;
uint16_t tmp16;
uint8_t mac[6];

/* For ICMPv6, we need to add the IPv6 multicast address
*
* For IPv6 multicast addresses, the Ethernet MAC is derived by
* the four low-order octets OR'ed with the MAC 33:33:00:00:00:00,
* so for example the IPv6 address FF02:DEAD:BEEF::1:3 would map
* to the Ethernet MAC address 33:33:00:01:00:03.
*
* NOTES: This appears correct for the ICMPv6 Router Solicitation
* Message, but the ICMPv6 Neighbor Solicitation message seems to
* use 33:33:ff:01:00:03.
*/

mac[0] = 0x33;
mac[1] = 0x33;

dev = &priv->dev;
tmp16 = dev->d_ipv6addr[6];
mac[2] = 0xff;
mac[3] = tmp16 >> 8;

tmp16 = dev->d_ipv6addr[7];
mac[4] = tmp16 & 0xff;
mac[5] = tmp16 >> 8;

ninfo("IPv6 Multicast: %02x:%02x:%02x:%02x:%02x:%02x\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

at32_addmac(dev, mac);

#ifdef CONFIG_NET_ICMPv6_AUTOCONF
/* Add the IPv6 all link-local nodes Ethernet address. This is the
* address that we expect to receive ICMPv6 Router Advertisement
* packets.
*/

at32_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet);

#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
#ifdef CONFIG_NET_ICMPv6_ROUTER
/* Add the IPv6 all link-local routers Ethernet address. This is the
* address that we expect to receive ICMPv6 Router Solicitation
* packets.
*/

at32_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet);

#endif /* CONFIG_NET_ICMPv6_ROUTER */
}
#endif /* CONFIG_NET_ICMPv6 */

/****************************************************************************
* Function: at32_macenable
*
Expand All @@ -3748,12 +3672,6 @@ static int at32_macenable(struct at32_ethmac_s *priv)

at32_macaddress(priv);

#ifdef CONFIG_NET_ICMPv6
/* Set up the IPv6 multicast address */

at32_ipv6multicast(priv);
#endif

/* Enable transmit state machine of the MAC for transmission on the MII */

regval = at32_getreg(AT32_ETH_MACCR);
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/imx6/imx_enet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ static int imx_addmac(struct net_driver_s *dev, const uint8_t *mac)

temp = imx_enet_getreg32(priv, registeraddress);
temp |= 1 << hashindex;
imx_rt_enet_putreg32(priv, temp, registeraddress);
imx_enet_putreg32(priv, temp, registeraddress);

return OK;
}
Expand Down
82 changes: 0 additions & 82 deletions arch/arm/src/lpc17xx_40xx/lpc17_40_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,6 @@ static void lpc17_40_txtimeout_expiry(wdparm_t arg);

/* NuttX callback functions */

#ifdef CONFIG_NET_ICMPv6
static void lpc17_40_ipv6multicast(struct lpc17_40_driver_s *priv);
#endif
static int lpc17_40_ifup(struct net_driver_s *dev);
static int lpc17_40_ifdown(struct net_driver_s *dev);

Expand Down Expand Up @@ -1358,79 +1355,6 @@ static void lpc17_40_txtimeout_expiry(wdparm_t arg)
}
}

/****************************************************************************
* Function: lpc17_40_ipv6multicast
*
* Description:
* Configure the IPv6 multicast MAC address.
*
* Input Parameters:
* priv - A reference to the private driver state structure
*
* Returned Value:
* OK on success; Negated errno on failure.
*
* Assumptions:
*
****************************************************************************/

#ifdef CONFIG_NET_ICMPv6
static void lpc17_40_ipv6multicast(struct lpc17_40_driver_s *priv)
{
struct net_driver_s *dev;
uint16_t tmp16;
uint8_t mac[6];

/* For ICMPv6, we need to add the IPv6 multicast address
*
* For IPv6 multicast addresses, the Ethernet MAC is derived by
* the four low-order octets OR'ed with the MAC 33:33:00:00:00:00,
* so for example the IPv6 address FF02:DEAD:BEEF::1:3 would map
* to the Ethernet MAC address 33:33:00:01:00:03.
*
* NOTES: This appears correct for the ICMPv6 Router Solicitation
* Message, but the ICMPv6 Neighbor Solicitation message seems to
* use 33:33:ff:01:00:03.
*/

mac[0] = 0x33;
mac[1] = 0x33;

dev = &priv->lp_dev;
tmp16 = dev->d_ipv6addr[6];
mac[2] = 0xff;
mac[3] = tmp16 >> 8;

tmp16 = dev->d_ipv6addr[7];
mac[4] = tmp16 & 0xff;
mac[5] = tmp16 >> 8;

ninfo("IPv6 Multicast: %02x:%02x:%02x:%02x:%02x:%02x\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

lpc17_40_addmac(dev, mac);

#ifdef CONFIG_NET_ICMPv6_AUTOCONF
/* Add the IPv6 all link-local nodes Ethernet address. This is the
* address that we expect to receive ICMPv6 Router Advertisement
* packets.
*/

lpc17_40_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet);

#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
#ifdef CONFIG_NET_ICMPv6_ROUTER
/* Add the IPv6 all link-local routers Ethernet address. This is the
* address that we expect to receive ICMPv6 Router Solicitation
* packets.
*/

lpc17_40_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet);

#endif /* CONFIG_NET_ICMPv6_ROUTER */
}
#endif /* CONFIG_NET_ICMPv6 */

/****************************************************************************
* Function: lpc17_40_ifup
*
Expand Down Expand Up @@ -1486,12 +1410,6 @@ static int lpc17_40_ifup(struct net_driver_s *dev)
(uint32_t)priv->lp_dev.d_mac.ether.ether_addr_octet[0];
lpc17_40_putreg(regval, LPC17_40_ETH_SA2);

#ifdef CONFIG_NET_ICMPv6
/* Set up the IPv6 multicast address */

lpc17_40_ipv6multicast(priv);
#endif

/* Initialize Ethernet interface for the PHY setup */

lpc17_40_macmode(priv->lp_mode);
Expand Down
82 changes: 0 additions & 82 deletions arch/arm/src/lpc43xx/lpc43_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,9 +643,6 @@ static inline void lpc43_ethgpioconfig(struct lpc43_ethmac_s *priv);
static void lpc43_ethreset(struct lpc43_ethmac_s *priv);
static int lpc43_macconfig(struct lpc43_ethmac_s *priv);
static void lpc43_macaddress(struct lpc43_ethmac_s *priv);
#ifdef CONFIG_NET_ICMPv6
static void lpc43_ipv6multicast(struct lpc43_ethmac_s *priv);
#endif
static int lpc43_macenable(struct lpc43_ethmac_s *priv);
static int lpc43_ethconfig(struct lpc43_ethmac_s *priv);

Expand Down Expand Up @@ -3417,79 +3414,6 @@ static void lpc43_macaddress(struct lpc43_ethmac_s *priv)
lpc43_putreg(regval, LPC43_ETH_MACA0LO);
}

/****************************************************************************
* Function: lpc43_ipv6multicast
*
* Description:
* Configure the IPv6 multicast MAC address.
*
* Input Parameters:
* priv - A reference to the private driver state structure
*
* Returned Value:
* OK on success; Negated errno on failure.
*
* Assumptions:
*
****************************************************************************/

#ifdef CONFIG_NET_ICMPv6
static void lpc43_ipv6multicast(struct lpc43_ethmac_s *priv)
{
struct net_driver_s *dev;
uint16_t tmp16;
uint8_t mac[6];

/* For ICMPv6, we need to add the IPv6 multicast address
*
* For IPv6 multicast addresses, the Ethernet MAC is derived by
* the four low-order octets OR'ed with the MAC 33:33:00:00:00:00,
* so for example the IPv6 address FF02:DEAD:BEEF::1:3 would map
* to the Ethernet MAC address 33:33:00:01:00:03.
*
* NOTES: This appears correct for the ICMPv6 Router Solicitation
* Message, but the ICMPv6 Neighbor Solicitation message seems to
* use 33:33:ff:01:00:03.
*/

mac[0] = 0x33;
mac[1] = 0x33;

dev = &priv->dev;
tmp16 = dev->d_ipv6addr[6];
mac[2] = 0xff;
mac[3] = tmp16 >> 8;

tmp16 = dev->d_ipv6addr[7];
mac[4] = tmp16 & 0xff;
mac[5] = tmp16 >> 8;

ninfo("IPv6 Multicast: %02x:%02x:%02x:%02x:%02x:%02x\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

lpc43_addmac(dev, mac);

#ifdef CONFIG_NET_ICMPv6_AUTOCONF
/* Add the IPv6 all link-local nodes Ethernet address. This is the
* address that we expect to receive ICMPv6 Router Advertisement
* packets.
*/

lpc43_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet);

#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
#ifdef CONFIG_NET_ICMPv6_ROUTER
/* Add the IPv6 all link-local routers Ethernet address. This is the
* address that we expect to receive ICMPv6 Router Solicitation
* packets.
*/

lpc43_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet);

#endif /* CONFIG_NET_ICMPv6_ROUTER */
}
#endif /* CONFIG_NET_ICMPv6 */

/****************************************************************************
* Function: lpc43_macenable
*
Expand All @@ -3514,12 +3438,6 @@ static int lpc43_macenable(struct lpc43_ethmac_s *priv)

lpc43_macaddress(priv);

#ifdef CONFIG_NET_ICMPv6
/* Set up the IPv6 multicast address */

lpc43_ipv6multicast(priv);
#endif

/* Enable transmit state machine of the MAC for transmission on the MII */

regval = lpc43_getreg(LPC43_ETH_MACCR);
Expand Down
Loading

0 comments on commit 5aeb154

Please sign in to comment.