2010-07-11 17:57:11 +02:00
|
|
|
/****************************************************************************
|
2014-05-30 21:05:19 +02:00
|
|
|
* net/igmp/igmp_send.c
|
2010-07-11 17:57:11 +02:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2010-07-11 17:57:11 +02:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2010-07-11 17:57:11 +02:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2010-07-11 17:57:11 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <debug.h>
|
2010-07-13 04:29:09 +02:00
|
|
|
#include <arpa/inet.h>
|
2010-07-11 17:57:11 +02:00
|
|
|
|
2014-06-24 16:53:28 +02:00
|
|
|
#include <nuttx/net/netconfig.h>
|
2014-06-24 17:28:44 +02:00
|
|
|
#include <nuttx/net/netdev.h>
|
2014-06-26 17:32:39 +02:00
|
|
|
#include <nuttx/net/netstats.h>
|
2014-07-05 03:13:08 +02:00
|
|
|
#include <nuttx/net/ip.h>
|
2014-07-05 00:44:53 +02:00
|
|
|
#include <nuttx/net/ipopt.h>
|
2014-07-06 20:34:27 +02:00
|
|
|
#include <nuttx/net/tcp.h>
|
2014-06-24 18:14:15 +02:00
|
|
|
#include <nuttx/net/igmp.h>
|
2010-07-11 17:57:11 +02:00
|
|
|
|
2014-06-29 02:07:02 +02:00
|
|
|
#include "devif/devif.h"
|
2017-08-07 21:03:23 +02:00
|
|
|
#include "inet/inet.h"
|
2014-06-25 17:52:36 +02:00
|
|
|
#include "igmp/igmp.h"
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IGMP
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-07-13 04:29:09 +02:00
|
|
|
/* Debug */
|
|
|
|
|
|
|
|
#undef IGMP_DUMPPKT /* Define to enable packet dump */
|
|
|
|
|
|
|
|
#ifndef CONFIG_DEBUG_NET
|
|
|
|
# undef IGMP_DUMPPKT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IGMP_DUMPPKT
|
|
|
|
# define igmp_dumppkt(b,n) lib_dumpbuffer("IGMP", (FAR const uint8_t*)(b), (n))
|
|
|
|
#else
|
|
|
|
# define igmp_dumppkt(b,n)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Buffer layout */
|
|
|
|
|
|
|
|
#define RASIZE (4)
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2024-04-24 05:06:52 +02:00
|
|
|
#ifdef CONFIG_NET_IGMP_CHECKSUMS
|
2014-06-25 17:52:36 +02:00
|
|
|
static uint16_t igmp_chksum(FAR uint8_t *buffer, int buflen)
|
2010-07-11 17:57:11 +02:00
|
|
|
{
|
2015-10-08 23:10:04 +02:00
|
|
|
uint16_t sum = net_chksum((FAR uint16_t *)buffer, buflen);
|
2010-07-11 17:57:11 +02:00
|
|
|
return sum ? sum : 0xffff;
|
|
|
|
}
|
2024-04-24 05:06:52 +02:00
|
|
|
#endif
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-06-25 17:52:36 +02:00
|
|
|
* Name: igmp_send
|
2010-07-11 17:57:11 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Sends an IGMP IP packet on a network interface. This function constructs
|
|
|
|
* the IP header and calculates the IP header checksum.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2014-04-12 20:13:01 +02:00
|
|
|
* dev - The device driver structure to use in the send operation.
|
|
|
|
* group - Describes the multicast group member and identifies the
|
|
|
|
* message to be sent.
|
2010-07-11 17:57:11 +02:00
|
|
|
* destipaddr - The IP address of the recipient of the message
|
2018-11-04 17:57:21 +01:00
|
|
|
* msgid - ID of message to send
|
2010-07-11 17:57:11 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2010-07-11 17:57:11 +02:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2017-08-29 23:08:38 +02:00
|
|
|
* The network is locked.
|
2010-07-11 17:57:11 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
void igmp_send(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group,
|
2022-03-12 06:23:37 +01:00
|
|
|
FAR const in_addr_t *destipaddr, uint8_t msgid)
|
2010-07-11 17:57:11 +02:00
|
|
|
{
|
2019-08-31 20:25:30 +02:00
|
|
|
FAR struct igmp_hdr_s *igmp;
|
|
|
|
uint16_t iphdrlen;
|
2022-11-29 04:23:43 +01:00
|
|
|
struct ipv4_opt_s opt;
|
|
|
|
uint32_t tmp;
|
2019-08-31 20:25:30 +02:00
|
|
|
|
2018-11-04 17:57:21 +01:00
|
|
|
ninfo("msgid: %02x destipaddr: %08x\n", msgid, (int)*destipaddr);
|
2010-07-13 04:29:09 +02:00
|
|
|
|
2023-01-11 09:09:20 +01:00
|
|
|
/* Prepare device buffer */
|
|
|
|
|
|
|
|
if (netdev_iob_prepare(dev, false, 0) != OK)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-15 10:45:26 +01:00
|
|
|
/* Select IPv4 */
|
|
|
|
|
|
|
|
IFF_SET_IPv4(dev->d_flags);
|
|
|
|
|
2019-08-31 20:25:30 +02:00
|
|
|
/* The IGMP header immediately follows the IP header */
|
|
|
|
|
|
|
|
iphdrlen = IPv4_HDRLEN + RASIZE;
|
2022-10-26 06:35:08 +02:00
|
|
|
igmp = IPBUF(iphdrlen);
|
2019-08-31 20:25:30 +02:00
|
|
|
|
2010-07-13 05:43:06 +02:00
|
|
|
/* The total length to send is the size of the IP and IGMP headers and 4
|
2014-04-12 20:13:01 +02:00
|
|
|
* bytes for the ROUTER ALERT (and, eventually, the Ethernet header)
|
2010-07-11 17:57:11 +02:00
|
|
|
*/
|
|
|
|
|
2019-08-31 20:25:30 +02:00
|
|
|
dev->d_len = iphdrlen + IGMP_HDRLEN;
|
2010-07-11 17:57:11 +02:00
|
|
|
|
2022-11-23 12:39:40 +01:00
|
|
|
/* Update device buffer length */
|
|
|
|
|
2023-05-17 10:11:21 +02:00
|
|
|
iob_update_pktlen(dev->d_iob, dev->d_len, false);
|
2022-11-23 12:39:40 +01:00
|
|
|
|
2010-07-11 17:57:11 +02:00
|
|
|
/* The total size of the data is the size of the IGMP header */
|
|
|
|
|
2019-08-31 20:25:30 +02:00
|
|
|
dev->d_sndlen = IGMP_HDRLEN;
|
2010-07-11 17:57:11 +02:00
|
|
|
|
2019-08-31 20:25:30 +02:00
|
|
|
/* Add the router alert option to the IPv4 header (RFC 2113) */
|
2010-07-11 17:57:11 +02:00
|
|
|
|
2022-11-29 04:23:43 +01:00
|
|
|
tmp = HTONL(IPOPT_RA);
|
|
|
|
memcpy(opt.data, &tmp, sizeof(uint32_t));
|
|
|
|
opt.len = sizeof(uint32_t);
|
2010-07-11 17:57:11 +02:00
|
|
|
|
2022-11-29 04:23:43 +01:00
|
|
|
ipv4_build_header(IPv4BUF, dev->d_len, IP_PROTO_IGMP,
|
2022-12-21 05:40:42 +01:00
|
|
|
&dev->d_ipaddr, destipaddr, IGMP_TTL, 0, &opt);
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
/* Set up the IGMP message */
|
|
|
|
|
2019-08-31 20:25:30 +02:00
|
|
|
igmp->type = msgid;
|
|
|
|
igmp->maxresp = 0;
|
|
|
|
net_ipv4addr_hdrcopy(igmp->grpaddr, &group->grpaddr);
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
/* Calculate the IGMP checksum. */
|
|
|
|
|
2019-08-31 20:25:30 +02:00
|
|
|
igmp->chksum = 0;
|
2024-04-24 05:06:52 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IGMP_CHECKSUMS
|
2019-08-31 20:25:30 +02:00
|
|
|
igmp->chksum = ~igmp_chksum(&igmp->type, IGMP_HDRLEN);
|
2024-04-24 05:06:52 +02:00
|
|
|
#endif
|
2010-07-11 17:57:11 +02:00
|
|
|
|
2014-06-26 17:32:39 +02:00
|
|
|
IGMP_STATINCR(g_netstats.igmp.poll_send);
|
2015-01-24 15:26:12 +01:00
|
|
|
IGMP_STATINCR(g_netstats.ipv4.sent);
|
2010-07-11 17:57:11 +02:00
|
|
|
|
2022-11-29 04:23:43 +01:00
|
|
|
ninfo("Outgoing IGMP packet length: %d\n", dev->d_len);
|
2019-08-31 20:25:30 +02:00
|
|
|
igmp_dumppkt(RA, iphdrlen + IGMP_HDRLEN);
|
2010-07-11 17:57:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET_IGMP */
|