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 uint16_t 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 uint16_t 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 uint8_t blocking; /* true if socket is blocking */
177 uint8_t type; /* socket type (stream|datagram) */
179 #ifdef IPV6_SUPPORTED
180 uint8_t 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 uint8_t 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 uint32_t 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 uint8_t 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 uint32_t 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
334 uint8_t ip6r0_nextHdr;
335 uint8_t ip6r0_hdrExtLen;
337 uint8_t ip6r0_segLeft;
338 uint32_t 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 TknUInt8 proto; /* Protocol value */
355 TknUInt8 dfBit; /* Don't fragment flag */
356 TknUInt8 tos; /* Type of Service */
357 TknUInt8 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 uint32_t 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 uint16_t arIdx; /* Current index in fd_set array */
390 uint32_t numArElems; /* Number of array elements */
391 uint8_t 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;
457 uint32_t adaptationInd;
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
499 uint8_t sackDelayFlag;
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
548 uint16_t maxInitReTx;
549 uint16_t maxInitTimeout;
550 uint16_t maxInstreams;
551 uint16_t numOstreams;
554 typedef struct cmInetSctpAssocParams
557 uint16_t assocMaxReTx;
558 uint16_t 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 S16 cmInetSocket ARGS((uint8_t type, CmInetFd *sockFd, uint8_t protocol,
612 S16 cmInetSocket ARGS((uint8_t type, CmInetFd *sockFd, uint8_t protocol));
613 #endif /* IPV6_SUPPORTED */
615 S16 cmInetSocket ARGS((uint8_t 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 S16 cmInetFlushRecvBuf ARGS((CmInetFd *sockFd,
624 #endif /* CM_INET_FLUSH_RECV_BUF*/
626 S16 cmInetBind ARGS((CmInetFd *sockFd, CmInetAddr *myAddr));
627 S16 cmInetConnect ARGS((CmInetFd *sockFd, CmInetAddr *servAddr));
628 S16 cmInetListen ARGS((CmInetFd *sockFd, S16 backLog));
629 S16 cmInetAccept ARGS((CmInetFd *sockFd, CmInetAddr *fromAddr,
630 CmInetFd *newSockFd));
631 #ifdef IPV6_OPTS_SUPPORTED
633 S16 cmInetRecvMsg ARGS((CmInetFd *sockFd, CmInetAddr *dstAddr,
634 CmInetMemInfo *info, Buffer **mPtr,
635 MsgLen *len, CmInetIpHdrParm *ipHdrParams,
636 CmInetLocalInf *localIf, S32 flags));
638 S16 cmInetRecvMsg ARGS((CmInetFd *sockFd, CmInetAddr *dstAddr,
639 CmInetMemInfo *info, Buffer **mPtr,
640 MsgLen *len, CmInetIpHdrParm *ipHdrParams,
642 #endif /* LOCAL_INTF */
645 S16 cmInetRecvMsg ARGS((CmInetFd *sockFd, CmInetAddr *dstAddr,
646 CmInetMemInfo *info, Buffer **mPtr,
647 MsgLen *len, CmInetLocalInf *localIf,
650 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 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 S16 cmInetSendMsg ARGS((CmInetFd *sockFd, CmInetAddr *dstAddr,
661 CmInetMemInfo *info, Buffer *mBuf, MsgLen *len,
662 CmInetIpHdrParm *ipHdrParams, S16 flags));
664 S16 cmInetSendMsg ARGS((CmInetFd *sockFd, CmInetAddr *dstAddr,
665 CmInetMemInfo *info, Buffer *mBuf, MsgLen *len,
667 #endif /* IPV6_OPTS_SUPPORTED */
668 S16 cmInetPeek ARGS((CmInetFd *sockFd, CmInetAddr *fromAddr,
669 CmInetMemInfo *info, MsgLen dataPos,
670 MsgLen dataLen, uint8_t *data));
671 /* cm_inet_x_001.main_26: Added new function declaration cmInetPeekNew() */
672 S16 cmInetPeekNew ARGS((CmInetFd *sockFd, CmInetAddr *fromAddr,
673 CmInetMemInfo *info, MsgLen dataPos,
674 MsgLen dataLen, uint8_t *data));
675 S16 cmInetClose ARGS((CmInetFd *sockFd));
676 S16 cmInetShutdown ARGS((CmInetFd *sockFd, S32 howTo));
677 S16 cmInetSelect ARGS((CmInetFdSet *readFdS, CmInetFdSet *writeFdS,
678 uint32_t *mSecTimeout, S16 *numFdS));
679 S16 cmInetSetOpt ARGS((CmInetFd *sockFd, uint32_t level, uint32_t type,
681 S16 cmInetGetNumRead ARGS((CmInetFd *sockFd, uint32_t *dataLen));
683 S16 cmInetGetHostByName ARGS((S8 *hostName, CmInetIpAddrTbl *addrTbl));
684 S16 cmInetGetIpNodeByName ARGS((S8 *hostName, CmInetIpAddrArr *addrArr));
685 S16 cmInetAddr ARGS((S8 *asciiAddr, CmInetIpAddr *address));
686 S16 cmInetNtoa ARGS((CmInetIpAddr address, S8 **asciiAddr));
687 S16 cmInetPton ARGS((CmInetIpAddr *address, S8 *asciiAddr));
688 #ifdef IPV6_SUPPORTED
689 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 S16 cmInetFdSetInfoInit ARGS((CmInetFdSetInfo *fdSetInfo));
696 S16 cmInetGetFd ARGS((CmInetFdSetInfo *fdSetInfo, CmInetFdSet *fdSet,
697 CmInetFdType *sockFd));
698 #endif /* WIN32 | SUNOS | SS_LINUX | SS_VW | HPOS */
700 S16 cmInetGetMemSize ARGS((S32 *size));
701 S16 cmInetInit ARGS((Void));
702 S16 cmInetDeInit ARGS((Void));
703 S16 cmInetGetSockName ARGS((CmInetFd *sockFd, CmInetAddr *locAddr));
705 S16 cmInetConvertStrToIpAddr ARGS((uint16_t len, uint8_t *val,
706 CmInetNetAddr *address));
707 S16 cmInetAsciiToIpv4 ARGS((uint8_t numBytes, uint8_t *ipv4Addr,
708 uint16_t len, uint8_t *val));
711 /* cm_inet_x_001.main_29 Poll Implementation Changes */
712 S16 cmInetPoll ARGS((CmInetPollFd *pollFdArr,uint32_t idx,S16 *numFdS,uint32_t timeout));
713 S16 cmInetPollSetFd ARGS((CmInetFd *sockFd,CmInetPollFd *pollFdArr,S16 idx, uint16_t eventMask));
714 S16 cmInetPollFdIsSet ARGS((CmInetPollFd *pollFdArr, S16 idx, uint16_t eventMask));
715 S16 cmInetPollClearFdREvent ARGS((CmInetPollFd *pollFdArr, S16 idx, uint16_t eventMask));
716 S16 cmInetPollClearFdEvent ARGS((CmInetPollFd *pollFdArr,S16 idx, uint16_t eventMask));
717 S16 cmInetPollDelFd ARGS((CmInetPollFd *pollFdArr, S16 delIdx, S16 crntIdx));
718 S16 cmInetPollInitFdArr ARGS((CmInetPollFd *pollFdArr));
719 S16 cmInetNtop ARGS((uint8_t type,Void *address,S8 *asciiAddr,uint32_t 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 S32 cmInetGetAddrInfo ARGS((const S8* node, const S8* service,
726 const CmInetAddrInfo *hints, CmInetAddrInfo **res));
727 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 S16 cmInetSctpBindx ARGS((CmInetFd *sockFd,
733 CmInetNetAddrLst *addrLst,
735 S16 cmInetSctpConnectx ARGS((CmInetFd *sockFd, CmInetNetAddr *primAddr,
736 CmInetNetAddrLst *addrLst,
738 S16 cmInetSctpPeelOff ARGS((CmInetFd *sockFd, uint32_t assocId,
739 CmInetFdType *assocFd));
740 S16 cmInetSctpSendMsg ARGS((CmInetFd *sockFd, CmInetNetAddr *dstAddr,
741 uint16_t port, CmInetMemInfo *info,
742 Buffer *mBuf, MsgLen *len, uint16_t strmId,
743 Bool unorderFlg, uint16_t ttl, uint32_t ppId,
745 S16 cmInetSctpRecvMsg ARGS((CmInetFd *sockFd, CmInetNetAddr *srcAddr,
746 uint16_t *port, CmInetMemInfo *info,
747 Buffer **mBuf, MsgLen *len,
748 CmInetSctpSndRcvInfo *sinfo, uint32_t *flag,
749 CmInetSctpNotification *ntfy));
750 S16 cmInetSctpGetPAddrs ARGS((CmInetFd *sockFd, uint32_t assocId,
751 CmInetNetAddrLst *addrlst));
752 S16 cmInetGetOpt ARGS((CmInetFd *sockFd, uint32_t level, uint32_t type,
755 /*cm_inet_x_001.main_25: Added new funcion */
756 S16 cmInetShutDownSctp ARGS((CmInetFd *sockFd));
757 /*cm_inet_x_001.main_30: Added new function */
758 S16 cmInetAbortSctpAssoc ARGS((CmInetFd *sockFd, UConnId assocId));
763 #endif /* __cplusplus */
764 #endif /* __CMINETX__ */
766 /**********************************************************************
768 **********************************************************************/