Skip to content

Commit 80375d3

Browse files
author
Emil Popov
committed
Adds placeholders for the socket options of IPv6 multicasts.
1 parent 89e1bc0 commit 80375d3

File tree

3 files changed

+89
-16
lines changed

3 files changed

+89
-16
lines changed

source/FreeRTOS_IGMP.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ void vModifyMulticastMembership( MCastGroupDesc_t * pxMulticastGroup,
737737
/* pxNetIf is NULL. For IPv4 that means "use all interfaces". For IPv6, that means "use the default multicast interface" */
738738
if( pxMulticastGroup->xMulticastGroup.xIs_IPv6 == pdTRUE )
739739
{
740+
/* ToDo: IPv6 FIX MEEEEEEEEEEEEEEEEE */
740741
}
741742
else
742743
{
@@ -747,22 +748,22 @@ void vModifyMulticastMembership( MCastGroupDesc_t * pxMulticastGroup,
747748
}
748749
}
749750

750-
/* Since we've added a multicast group to this socket, we need to prepare an IGMP report
751-
* for when we receive an IGMP query. Keep in mind that such a report might already exist.
752-
* If such an IGMP report is already present in the list, we will increment it's socket
751+
/* Since we've added a multicast group to this socket, we need to prepare an IGMP/MLD report
752+
* for when we receive an IGMP/MLD query. Keep in mind that such a report might already exist.
753+
* If such an IGMP/MLD report is already present in the list, we will increment it's socket
753754
* count and free the report we have here. In either case, the MCastGroupDesc_t that we were
754755
* passed, no longer needs to hold a reference to this IGMP report. */
755-
if( pxMulticastGroup->pxIGMPReportDesc )
756+
if( pxMulticastGroup->pxMCastReportData )
756757
{
757-
BaseType_t bReportItemConsumed = xAddIGMPReportToList( pxMulticastGroup->pxIGMPReportDesc );
758+
BaseType_t bReportItemConsumed = xAddIGMPReportToList( pxMulticastGroup->pxMCastReportData );
758759

759760
if( pdTRUE != bReportItemConsumed )
760761
{
761762
/* If adding to the list did not consume the item that we sent, that means a duplicate
762763
* was found and its socket count was incremented instead of adding the item we sent.
763764
* Free the item that was passed to us. */
764-
vPortFree( pxMulticastGroup->pxIGMPReportDesc );
765-
pxMulticastGroup->pxIGMPReportDesc = NULL;
765+
vPortFree( pxMulticastGroup->pxMCastReportData );
766+
pxMulticastGroup->pxMCastReportData = NULL;
766767
}
767768
}
768769
}

source/FreeRTOS_Sockets.c

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,7 +2966,9 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket,
29662966
case FREERTOS_SO_IP_MULTICAST_TTL:
29672967
case FREERTOS_SO_IPV6_MULTICAST_HOPS:
29682968
case FREERTOS_SO_IP_ADD_MEMBERSHIP:
2969+
case FREERTOS_SO_IPV6_ADD_MEMBERSHIP:
29692970
case FREERTOS_SO_IP_DROP_MEMBERSHIP:
2971+
case FREERTOS_SO_IPV6_DROP_MEMBERSHIP:
29702972
xReturn = prvSetMulticastSocketOption( xSocket, lLevel, lOptionName, pvOptionValue, uxOptionLength );
29712973
break;
29722974
#endif /* (ipconfigSUPPORT_IP_MULTICAST != 0) */
@@ -6461,15 +6463,15 @@ void * pvSocketGetSocketID( const ConstSocket_t xSocket )
64616463

64626464
case FREERTOS_SO_IP_ADD_MEMBERSHIP:
64636465
{
6466+
struct freertos_ip_mreq * pMReq = ( struct freertos_ip_mreq * ) pvOptionValue;
6467+
64646468
if( ( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_UDP ) ||
64656469
( uxOptionLength != sizeof( struct freertos_ip_mreq ) ) ||
64666470
( pxSocket->bits.bIsIPv6 != pdFALSE ) )
64676471
{
64686472
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
64696473
}
64706474

6471-
struct freertos_ip_mreq * pMReq = ( struct freertos_ip_mreq * ) pvOptionValue;
6472-
64736475
if( pdFALSE == xIsIPv4Multicast( pMReq->imr_multiaddr.s_addr ) )
64746476
{
64756477
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
@@ -6513,7 +6515,7 @@ void * pvSocketGetSocketID( const ConstSocket_t xSocket )
65136515

65146516
/* Pass the IGMP report descriptor inside the multicast group descriptor,
65156517
* so we can easily pass it to the IP task in one message. */
6516-
pxMCG->pxIGMPReportDesc = pxMRD;
6518+
pxMCG->pxMCastReportData = pxMRD;
65176519

65186520
IPStackEvent_t xSockOptsEvent = { eSocketOptAddMembership, ( void * ) pxMCG };
65196521

@@ -6532,20 +6534,26 @@ void * pvSocketGetSocketID( const ConstSocket_t xSocket )
65326534

65336535
case FREERTOS_SO_IP_DROP_MEMBERSHIP:
65346536
{
6537+
struct freertos_ip_mreq * pMReq = ( struct freertos_ip_mreq * ) pvOptionValue;
6538+
65356539
if( ( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_UDP ) ||
65366540
( uxOptionLength != sizeof( struct freertos_ip_mreq ) ) ||
65376541
( pxSocket->bits.bIsIPv6 != pdFALSE ) )
65386542
{
65396543
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
65406544
}
65416545

6542-
struct freertos_ip_mreq * pMReq = ( struct freertos_ip_mreq * ) pvOptionValue;
6543-
65446546
if( pdFALSE == xIsIPv4Multicast( pMReq->imr_multiaddr.s_addr ) )
65456547
{
65466548
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
65476549
}
65486550

6551+
if( pxSocket->u.xUDP.xMulticastAddress.ulIP_IPv4 != pMReq->imr_multiaddr.s_addr )
6552+
{
6553+
/* The socket was is not subscribed to this multicast group. */
6554+
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
6555+
}
6556+
65496557
/* Allocate some RAM to remember the multicast group that is being registered */
65506558
MCastGroupDesc_t * pxMCG = ( MCastGroupDesc_t * ) pvPortMalloc( sizeof( MCastGroupDesc_t ) );
65516559

@@ -6563,7 +6571,7 @@ void * pvSocketGetSocketID( const ConstSocket_t xSocket )
65636571
pxMCG->pxSocket = pxSocket;
65646572

65656573
/* When dropping memberships, we don't need an IGMP report descriptor. */
6566-
pxMCG->pxIGMPReportDesc = NULL;
6574+
pxMCG->pxMCastReportData = NULL;
65676575

65686576
IPStackEvent_t xSockOptsEvent = { eSocketOptDropMembership, ( void * ) pxMCG };
65696577

@@ -6579,6 +6587,70 @@ void * pvSocketGetSocketID( const ConstSocket_t xSocket )
65796587
}
65806588
break;
65816589

6590+
case FREERTOS_SO_IPV6_ADD_MEMBERSHIP:
6591+
{
6592+
struct freertos_ipv6_mreq * pMReq = ( struct freertos_ipv6_mreq * ) pvOptionValue;
6593+
6594+
if( ( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_UDP ) ||
6595+
( uxOptionLength != sizeof( struct freertos_ipv6_mreq ) ) ||
6596+
( pxSocket->bits.bIsIPv6 != pdTRUE ) )
6597+
{
6598+
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
6599+
}
6600+
6601+
if( pdFALSE == xIsIPv6AllowedMulticast( &( pMReq->ipv6mr_multiaddr.s6_addr ) ) )
6602+
{
6603+
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
6604+
}
6605+
6606+
/* Allocate some RAM to remember the multicast group that is being registered */
6607+
MCastGroupDesc_t * pxMCG = ( MCastGroupDesc_t * ) pvPortMalloc( sizeof( MCastGroupDesc_t ) );
6608+
MCastReportData_t * pxMRD = ( MCastReportData_t * ) pvPortMalloc( sizeof( MCastReportData_t ) );
6609+
6610+
if( NULL == pxMCG )
6611+
{
6612+
xReturn = -pdFREERTOS_ERRNO_ENOMEM;
6613+
break;
6614+
}
6615+
6616+
if( NULL == pxMRD )
6617+
{
6618+
xReturn = -pdFREERTOS_ERRNO_ENOMEM;
6619+
vPortFree( pxMCG );
6620+
pxMCG = NULL;
6621+
break;
6622+
}
6623+
6624+
/* ToDo: .... working on it .... */
6625+
}
6626+
break;
6627+
6628+
case FREERTOS_SO_IPV6_DROP_MEMBERSHIP:
6629+
{
6630+
struct freertos_ipv6_mreq * pMReq = ( struct freertos_ipv6_mreq * ) pvOptionValue;
6631+
6632+
if( ( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_UDP ) ||
6633+
( uxOptionLength != sizeof( struct freertos_ipv6_mreq ) ) ||
6634+
( pxSocket->bits.bIsIPv6 != pdTRUE ) )
6635+
{
6636+
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
6637+
}
6638+
6639+
if( pdFALSE == xIsIPv6AllowedMulticast( &( pMReq->ipv6mr_multiaddr.s6_addr ) ) )
6640+
{
6641+
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
6642+
}
6643+
6644+
if( memcmp( pxSocket->u.xUDP.xMulticastAddress.xIP_IPv6.ucBytes, pMReq->ipv6mr_multiaddr.s6_addr.ucBytes, ipSIZE_OF_IPv6_ADDRESS ) != 0 )
6645+
{
6646+
/* The socket was is not subscribed to this multicast group. */
6647+
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
6648+
}
6649+
6650+
/* ToDo: .... working on it .... */
6651+
}
6652+
break;
6653+
65826654
default:
65836655
/* This function doesn't handle any other options. */
65846656
xReturn = -pdFREERTOS_ERRNO_ENOPROTOOPT;

source/include/FreeRTOS_IP_Utils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@
7979
/** @brief The structure to hold a "descriptor" for a multicast group that a socket has registered to. */
8080
typedef struct xMCastGroupDesc
8181
{
82-
IPv46_Address_t xMulticastGroup; /**< Holds the IPv4/IPv6 multicast group address */
83-
struct freertos_ip_mreq mreq; /**< Struct for storing the original mreq structure that was sent to setsockopts() */
82+
IPv46_Address_t xMulticastGroup; /**< Holds the IPv4/IPv6 multicast group address */
83+
struct freertos_ip_mreq mreq; /**< Struct for storing the original mreq structure that was sent to setsockopts() */
8484
FreeRTOS_Socket_t * pxSocket;
85-
MCastReportData_t * pxIGMPReportDesc; /**< Optional. used to hold the allocated IGMP report descriptor while passing from user code to the IP Task. */
85+
MCastReportData_t * pxMCastReportData; /**< Used to hold the allocated IGMP report descriptor while passing from user code to the IP Task. */
8686
} MCastGroupDesc_t;
8787
#endif /* ( ipconfigSUPPORT_IP_MULTICAST == 1 ) */
8888

0 commit comments

Comments
 (0)