1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /********************************************************************20**
21 Name: common Internet socket library
25 Desc: common library for Internet sockets
29 *********************************************************************21*/
33 * This software may be combined with the following TRILLIUM
36 * part no. description
37 * -------- ----------------------------------------------
38 * 1000151 TCAP over TCP/IP
41 /* cm_inet_x_001.main_29: SS_4GMX_LCORE changes */
50 #endif /* __cplusplus */
62 /* cm_inet_x_001.main_28: Added #define IN */
74 #include <sys/select.h>
77 #include <sys/types.h>
81 #include <sys/socket.h>
82 #include <netinet/in.h>
87 #if (defined(SUNOS) || defined(HPOS))
88 #include <netinet/icmp6.h>
89 #endif /* SUNOS || HPOS */
90 #endif /* IPV6_SUPPORTED */
92 /* cm_inet_x_001.main_27 : Added header file inclusion */
93 #if (defined(SS_VW) && defined(SS_VW6_7))
94 #include <ipcom_inet.h>
95 #include <ipcom_sock6.h>
96 #include <netinet/icmp6.h>
99 /* cm_inet_x_001.main_21:Added wrapper function for getaddrinfo and freeaddrinfo */
100 #if (!defined(SS_VW) && !defined(SS_PS) && !defined(WIN32))
104 /* Redifining the CmInetIpAddr & CmInetIpAddr6 */
105 typedef CmIpAddr CmInetIpAddr; /* 4 byte IP address */
106 #ifdef IPV6_SUPPORTED
107 typedef CmIpAddr6 CmInetIpAddr6; /* 16 byte IPV6 address */
108 #endif /* IPV6_SUPPORTED */
110 typedef struct cmInetIpAddrTbl
112 U16 count; /* Number of addresses in table */
113 CmInetIpAddr netAddr[CM_INET_IPV4_NUM_ADDR]; /* Address table */
116 typedef CmInetIpAddrTbl CmInetIpv4AddrArr;
118 #ifdef IPV6_SUPPORTED
119 typedef struct cmInetIpv6AddrArr
121 U16 count; /* Number of addresses in array */
122 CmInetIpAddr6 netAddr[CM_INET_IPV6_NUM_ADDR]; /* Address array */
124 #endif /* IPV6_SUPPORTED */
126 typedef struct cmInetIpAddrArr
131 CmInetIpv4AddrArr ipv4AddrArr;
132 #ifdef IPV6_SUPPORTED
133 CmInetIpv6AddrArr ipv6AddrArr;
134 #endif /* IPV6_SUPPORTED */
140 /* Adding a type for socket Address */
141 typedef struct cmInetCmnSockAddr
147 struct sockaddr_in addr;
148 #ifdef IPV6_SUPPORTED
149 struct sockaddr_in6 addr6;
156 /* Adding a type for socket descriptors */
158 typedef SOCKET CmInetFdType;
160 #if (defined(SUNOS) || defined(HPOS))
161 typedef S32 CmInetFdType;
164 typedef S32 CmInetFdType;
166 typedef S16 CmInetFdType;
167 #endif /* SS_LINUX */
168 #endif /* SUNOS || HPOS */
170 /* cm_inet_x_001.main_29 Poll Implementation Changes */
171 typedef struct pollfd CmInetPollFd;
173 typedef struct cmInetFd /* trillium socket file descriptor */
175 CmInetFdType fd; /* socket descriptor */
176 U8 blocking; /* true if socket is blocking */
177 U8 type; /* socket type (stream|datagram) */
179 #ifdef IPV6_SUPPORTED
180 U8 protType; /* indicates whether IPv4 or IPv6 socket */
181 #endif /* IPV6_SUPPORTED */
184 typedef fd_set CmInetFdSet; /* socket file descriptor set */
186 #ifdef IPV6_SUPPORTED
188 typedef struct cmInetIpv4Addr
191 CmInetIpAddr address;
195 typedef struct cmInetIpv6Addr
198 CmInetIpAddr6 ipv6NetAddr;
201 typedef struct CmInetAddr /* Internet address */
203 U8 type; /* type of address present in the union */
206 CmInetIpv4Addr ipv4Addr; /* IPV4 Address */
207 CmInetIpv6Addr ipv6Addr; /* IPV6 Address */
211 typedef struct cmInetMCastInf6 /* multicast interface information */
213 CmInetIpAddr6 mCastAddr; /* multicast address */
214 U32 localInf; /* local interface */
218 typedef struct cmInetAddr1
221 CmInetIpAddr address;
223 typedef CmInetAddr CmInetIpv4Addr;
224 #endif /* IPV6_SUPPORTED */
226 typedef struct cmInetMemInfo /* memory information */
228 Region region; /* memory region */
229 Pool pool; /* memory pool */
232 typedef struct cmInetMCastInf /* multicast information */
234 CmInetIpAddr mCastAddr; /* multicast class D address */
235 CmInetIpAddr localAddr; /* local interface address */
238 /* this is the same structure as cmNetAddr in cm_tpt.x
239 used here for cmInetConvertStrToIpAddr */
240 typedef struct cmInetNetAddr
242 U8 type; /* type of network address */
245 CmInetIpAddr ipv4NetAddr; /* IP network address */
246 #ifdef IPV6_SUPPORTED
247 CmInetIpAddr6 ipv6NetAddr; /* IPv6 network address */
248 #endif /* IPV6_SUPPORTED */
252 /*cm_inet_x_001.main_23 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
254 typedef struct cmInetNetAddrLst
257 CmInetNetAddr addrs[CM_INET_NUM_NET_ADDR];
262 /* used to pass local interface (on which packet was received) to upper user */
263 typedef struct cmInetLocalInf
265 Bool intfPrsnt; /* bool to indicate if this is a valid loc intf */
266 U32 localIf; /* interface index IPv4(32 bit) or IPv6(32 bit) */
267 CmInetNetAddr localIfAddr; /* interface address */
269 #endif /* LOCAL_INTF */
271 #ifdef IPV6_SUPPORTED
272 #if (defined(SUNOS) || defined(HPOS) || defined(SS_VW))
273 typedef struct icmp6_filter CmInetIcmp6Filter;
274 #endif /* SUNOS || HPOS */
275 #endif /* IPV6_SUPPORTED */
277 /* New data structures needed to support 3 types of IPV6 extension
278 * headers - HBH, Destination Option & Route Header */
279 #ifdef IPV6_SUPPORTED
280 #ifdef IPV6_OPTS_SUPPORTED
282 /* structure to hold TLV of each HBH option */
283 typedef struct cmInetIpv6HBHHdr
290 /* structure to hold TLV of each Destination option */
291 typedef struct cmInetIpv6DestOptsHdr
296 } CmInetIpv6DestOptsHdr;
298 /* structure to hold IPV6 addresses of the Route header */
299 typedef struct cmInetIpv6RtHdr
303 CmInetIpAddr6 *ipv6Addrs;
306 /* array of all HBH options */
307 typedef struct cmInetIpv6HBHHdrArr
310 CmInetIpv6HBHHdr *hbhOpts;
311 } CmInetIpv6HBHHdrArr;
313 /* array of all Destination options */
314 typedef struct cmInetIpv6DestOptsArr
317 CmInetIpv6DestOptsHdr *destOpts;
318 } CmInetIpv6DestOptsArr;
320 /* structure having 3 substructures for 3 types of ext headers */
321 typedef struct cmInetIpv6ExtHdr
324 CmInetIpv6HBHHdrArr hbhOptsArr;
326 CmInetIpv6DestOptsArr destOptsArr;
328 CmInetIpv6RtHdr rtOptsArr;
331 /* structure for type 0 Route Header */
332 typedef struct cmInetIpv6RtHdr0
338 U32 ip6r0_resrvAndSLmap; /* first byte reserved, last 3 srtict/loose map */
340 #endif /* IPV6_OPTS_SUPPORTED */
342 typedef struct cmInetIpv6HdrParm
345 CmInetNetAddr srcAddr6;/* used to set src addr on sending pkt(IPv6) */
346 #ifdef IPV6_OPTS_SUPPORTED
347 CmInetIpv6ExtHdr ipv6ExtHdr;
348 #endif /* IPV6_OPTS_SUPPORTED */
350 #endif /* IPV6_SUPPORTED */
352 typedef struct cmInetIpv4HdrParm
354 TknU8 proto; /* Protocol value */
355 TknU8 dfBit; /* Don't fragment flag */
356 TknU8 tos; /* Type of Service */
357 TknU8 ttl; /* Time to Live */
358 /* added new field */
359 #ifdef IPV4_OPTS_SUPPORTED
360 TknStr64 ipv4HdrOpt; /* IPV4 hdr opt */
361 #endif /* IPV4_OPTS_SUPPORTED */
363 typedef struct cmInetIpHdrParm
368 CmInetIpv4HdrParm hdrParmIpv4; /* IPv4 header parameters */
369 #ifdef IPV6_SUPPORTED
370 CmInetIpv6HdrParm ipv6HdrParm;
371 #endif /* IPV6_SUPPORTED */
375 /* New data structures to peek into the file descriptor set. */
376 /* fdSetInfo structure */
378 typedef struct cmInetFdSetInfo
380 Bool initDone; /* Initialisation done */
381 U32 numFds; /* Number of file descriptors scanned */
384 #if (defined(SUNOS) || defined(SS_LINUX) || defined(SS_VW) || defined(HPOS))
385 typedef struct cmInetFdSetInfo
387 Bool initDone; /* Initialisation done */
388 Bool bigEndian; /* Big endian architecture */
389 U16 arIdx; /* Current index in fd_set array */
390 U32 numArElems; /* Number of array elements */
391 U8 ar[256]; /* Array of bit positions */
393 #endif /* SUNOS || SS_LINUX || SS_VW */
396 /*cm_inet_x_001.main_23 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
398 typedef struct cmInetSctpSndRcvInfo
409 } CmInetSctpSndRcvInfo;
411 typedef struct cmInetSctpNotification
447 CmInetSctpSndRcvInfo info;
466 }CmInetSctpNotification;
468 typedef struct cmInetSockLinger
474 typedef struct cmInetSctpSockEvent
477 Bool associationEvent;
479 Bool sendFailureEvent;
482 Bool partialDeliveryEvent;
483 Bool adaptationLayerEvent;
484 } CmInetSctpSockEvent;
486 typedef struct cmInetSctpPeerAddrParams
502 } CmInetSctpPeerAddrParams;
504 typedef struct cmInetSctpPrimAddr
511 typedef struct cmInetSctpPeerAddrInfo
521 }CmInetSctpPeerAddrInfo;
523 typedef struct cmInetSctpStatus
533 CmInetSctpPeerAddrInfo primary;
536 /*cm_inet_x_001.main_24 Updated for the support of configurable RTO parameters,
537 HBeat value Max retransmissions (Init, Path, Association)*/
538 typedef struct cmInetSctpRtoInfo
546 typedef struct cmInetSctpInitMsg
554 typedef struct cmInetSctpAssocParams
558 U16 numberOfPeerDest;
562 }CmInetSctpAssocParams;
566 /* added a new type CmInetSockAddr */
569 typedef struct iovec CmInetIovec;
571 typedef iovec_t CmInetIovec;
572 #endif /* SS_LINUX */
573 typedef struct sockaddr CmInetSockAddr;
576 typedef struct iovec CmInetIovec;
577 typedef struct sockaddr CmInetSockAddr;
580 typedef struct iovec CmInetIovec;
581 typedef struct sockaddr CmInetSockAddr;
584 typedef struct sockaddr CmInetSockAddr;
587 typedef struct iovec CmInetIovec;
588 typedef struct sockaddr_in CmInetSockAddr;
596 typedef struct sockaddr_in6 CmInet6SockAddr;
597 typedef struct sockaddr_in CmInet4SockAddr;
600 /* addrInfo structure */
601 #if (!defined(SS_VW) && !defined(SS_PS) && !defined(WIN32))
602 typedef struct addrinfo CmInetAddrInfo;
603 #endif /* SS_VW | SS_PS | WIN32*/
605 /* socket function prototypes */
608 #ifdef IPV6_SUPPORTED
609 EXTERN S16 cmInetSocket ARGS((U8 type, CmInetFd *sockFd, U8 protocol,
612 EXTERN S16 cmInetSocket ARGS((U8 type, CmInetFd *sockFd, U8 protocol));
613 #endif /* IPV6_SUPPORTED */
615 EXTERN S16 cmInetSocket ARGS((U8 type, CmInetFd *sockFd));
616 #endif /* CM_INET2 */
618 /* cm_inet_x_001.main_22 1. Added new interface - cmInetFlushRecvBuf()
619 to flush the data from socket receive buffer. */
620 #ifdef CM_INET_FLUSH_RECV_BUF
621 EXTERN S16 cmInetFlushRecvBuf ARGS((CmInetFd *sockFd,
624 #endif /* CM_INET_FLUSH_RECV_BUF*/
626 EXTERN S16 cmInetBind ARGS((CmInetFd *sockFd, CmInetAddr *myAddr));
627 EXTERN S16 cmInetConnect ARGS((CmInetFd *sockFd, CmInetAddr *servAddr));
628 EXTERN S16 cmInetListen ARGS((CmInetFd *sockFd, S16 backLog));
629 EXTERN S16 cmInetAccept ARGS((CmInetFd *sockFd, CmInetAddr *fromAddr,
630 CmInetFd *newSockFd));
631 #ifdef IPV6_OPTS_SUPPORTED
633 EXTERN S16 cmInetRecvMsg ARGS((CmInetFd *sockFd, CmInetAddr *dstAddr,
634 CmInetMemInfo *info, Buffer **mPtr,
635 MsgLen *len, CmInetIpHdrParm *ipHdrParams,
636 CmInetLocalInf *localIf, S32 flags));
638 EXTERN S16 cmInetRecvMsg ARGS((CmInetFd *sockFd, CmInetAddr *dstAddr,
639 CmInetMemInfo *info, Buffer **mPtr,
640 MsgLen *len, CmInetIpHdrParm *ipHdrParams,
642 #endif /* LOCAL_INTF */
645 EXTERN S16 cmInetRecvMsg ARGS((CmInetFd *sockFd, CmInetAddr *dstAddr,
646 CmInetMemInfo *info, Buffer **mPtr,
647 MsgLen *len, CmInetLocalInf *localIf,
650 EXTERN S16 cmInetRecvMsg ARGS((CmInetFd *sockFd, CmInetAddr *dstAddr,
651 CmInetMemInfo *info, Buffer **mPtr,
652 MsgLen *len, S32 flags));
653 #endif /* LOCAL_INTF */
654 #endif /* IPV6_OPTS_SUPPORTED */
655 EXTERN S16 cmInetSendDscpMsg ARGS((CmInetFd *sockFd, CmInetAddr *dstAddr,
656 CmInetMemInfo *info, Buffer *mBuf, MsgLen *len,
657 CmInetIpHdrParm *ipHdrParams, S16 flags));
659 #ifdef IPV6_OPTS_SUPPORTED
660 EXTERN S16 cmInetSendMsg ARGS((CmInetFd *sockFd, CmInetAddr *dstAddr,
661 CmInetMemInfo *info, Buffer *mBuf, MsgLen *len,
662 CmInetIpHdrParm *ipHdrParams, S16 flags));
664 EXTERN S16 cmInetSendMsg ARGS((CmInetFd *sockFd, CmInetAddr *dstAddr,
665 CmInetMemInfo *info, Buffer *mBuf, MsgLen *len,
667 #endif /* IPV6_OPTS_SUPPORTED */
668 EXTERN S16 cmInetPeek ARGS((CmInetFd *sockFd, CmInetAddr *fromAddr,
669 CmInetMemInfo *info, MsgLen dataPos,
670 MsgLen dataLen, U8 *data));
671 /* cm_inet_x_001.main_26: Added new function declaration cmInetPeekNew() */
672 EXTERN S16 cmInetPeekNew ARGS((CmInetFd *sockFd, CmInetAddr *fromAddr,
673 CmInetMemInfo *info, MsgLen dataPos,
674 MsgLen dataLen, U8 *data));
675 EXTERN S16 cmInetClose ARGS((CmInetFd *sockFd));
676 EXTERN S16 cmInetShutdown ARGS((CmInetFd *sockFd, S32 howTo));
677 EXTERN S16 cmInetSelect ARGS((CmInetFdSet *readFdS, CmInetFdSet *writeFdS,
678 U32 *mSecTimeout, S16 *numFdS));
679 EXTERN S16 cmInetSetOpt ARGS((CmInetFd *sockFd, U32 level, U32 type,
681 EXTERN S16 cmInetGetNumRead ARGS((CmInetFd *sockFd, U32 *dataLen));
683 EXTERN S16 cmInetGetHostByName ARGS((S8 *hostName, CmInetIpAddrTbl *addrTbl));
684 EXTERN S16 cmInetGetIpNodeByName ARGS((S8 *hostName, CmInetIpAddrArr *addrArr));
685 EXTERN S16 cmInetAddr ARGS((S8 *asciiAddr, CmInetIpAddr *address));
686 EXTERN S16 cmInetNtoa ARGS((CmInetIpAddr address, S8 **asciiAddr));
687 EXTERN S16 cmInetPton ARGS((CmInetIpAddr *address, S8 *asciiAddr));
688 #ifdef IPV6_SUPPORTED
689 EXTERN S16 cmInetPton6 ARGS((CmInetIpAddr6 *address6, S8 *asciiAddr));
690 #endif /* IPV6_SUPPORTED */
692 /* Function prototypes to peek into file descriptor set. */
693 #if (defined(WIN32) || defined(SUNOS) || defined(SS_LINUX) || defined(SS_VW) \
695 EXTERN S16 cmInetFdSetInfoInit ARGS((CmInetFdSetInfo *fdSetInfo));
696 EXTERN S16 cmInetGetFd ARGS((CmInetFdSetInfo *fdSetInfo, CmInetFdSet *fdSet,
697 CmInetFdType *sockFd));
698 #endif /* WIN32 | SUNOS | SS_LINUX | SS_VW | HPOS */
700 EXTERN S16 cmInetGetMemSize ARGS((S32 *size));
701 EXTERN S16 cmInetInit ARGS((Void));
702 EXTERN S16 cmInetDeInit ARGS((Void));
703 EXTERN S16 cmInetGetSockName ARGS((CmInetFd *sockFd, CmInetAddr *locAddr));
705 EXTERN S16 cmInetConvertStrToIpAddr ARGS((U16 len, U8 *val,
706 CmInetNetAddr *address));
707 EXTERN S16 cmInetAsciiToIpv4 ARGS((U8 numBytes, U8 *ipv4Addr,
711 /* cm_inet_x_001.main_29 Poll Implementation Changes */
712 EXTERN S16 cmInetPoll ARGS((CmInetPollFd *pollFdArr,U32 idx,S16 *numFdS,U32 timeout));
713 EXTERN S16 cmInetPollSetFd ARGS((CmInetFd *sockFd,CmInetPollFd *pollFdArr,S16 idx, U16 eventMask));
714 EXTERN S16 cmInetPollFdIsSet ARGS((CmInetPollFd *pollFdArr, S16 idx, U16 eventMask));
715 EXTERN S16 cmInetPollClearFdREvent ARGS((CmInetPollFd *pollFdArr, S16 idx, U16 eventMask));
716 EXTERN S16 cmInetPollClearFdEvent ARGS((CmInetPollFd *pollFdArr,S16 idx, U16 eventMask));
717 EXTERN S16 cmInetPollDelFd ARGS((CmInetPollFd *pollFdArr, S16 delIdx, S16 crntIdx));
718 EXTERN S16 cmInetPollInitFdArr ARGS((CmInetPollFd *pollFdArr));
719 EXTERN S16 cmInetNtop ARGS((U8 type,Void *address,S8 *asciiAddr,U32 len));
723 /* cm_inet_x_001.main_21:Added wrapper function for getaddrinfo and freeaddrinfo */
724 #if (!defined(SS_VW) && !defined(SS_PS) && !defined(WIN32))
725 EXTERN S32 cmInetGetAddrInfo ARGS((CONSTANT S8* node, CONSTANT S8* service,
726 CONSTANT CmInetAddrInfo *hints, CmInetAddrInfo **res));
727 EXTERN Void cmInetFreeAddrInfo ARGS((CmInetAddrInfo *res));
728 #endif /* SS_VW | SS_PS | WIN32 */
730 /*cm_inet_x_001.main_23 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
732 EXTERN S16 cmInetSctpBindx ARGS((CmInetFd *sockFd,
733 CmInetNetAddrLst *addrLst,
735 EXTERN S16 cmInetSctpConnectx ARGS((CmInetFd *sockFd, CmInetNetAddr *primAddr,
736 CmInetNetAddrLst *addrLst,
738 EXTERN S16 cmInetSctpPeelOff ARGS((CmInetFd *sockFd, U32 assocId,
739 CmInetFdType *assocFd));
740 EXTERN S16 cmInetSctpSendMsg ARGS((CmInetFd *sockFd, CmInetNetAddr *dstAddr,
741 U16 port, CmInetMemInfo *info,
742 Buffer *mBuf, MsgLen *len, U16 strmId,
743 Bool unorderFlg, U16 ttl, U32 ppId,
745 EXTERN S16 cmInetSctpRecvMsg ARGS((CmInetFd *sockFd, CmInetNetAddr *srcAddr,
746 U16 *port, CmInetMemInfo *info,
747 Buffer **mBuf, MsgLen *len,
748 CmInetSctpSndRcvInfo *sinfo, U32 *flag,
749 CmInetSctpNotification *ntfy));
750 EXTERN S16 cmInetSctpGetPAddrs ARGS((CmInetFd *sockFd, U32 assocId,
751 CmInetNetAddrLst *addrlst));
752 EXTERN S16 cmInetGetOpt ARGS((CmInetFd *sockFd, U32 level, U32 type,
755 /*cm_inet_x_001.main_25: Added new funcion */
756 EXTERN S16 cmInetShutDownSctp ARGS((CmInetFd *sockFd));
757 /*cm_inet_x_001.main_30: Added new function */
758 EXTERN S16 cmInetAbortSctpAssoc ARGS((CmInetFd *sockFd, UConnId assocId));
763 #endif /* __cplusplus */
764 #endif /* __CMINETX__ */
766 /**********************************************************************
768 **********************************************************************/