1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FILLP_NET_H 17 #define FILLP_NET_H 18 19 #include "pcb.h" 20 #include "fillp.h" 21 #include "sysio.h" 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 enum FtConnState { 27 CONN_STATE_IDLE = 0, /* Alloced but not do connect */ 28 CONN_STATE_LISTENING = 1, /* Listen socket */ 29 CONN_STATE_CONNECTING = 2, /* Do connecting, four handshake not finished yet */ 30 CONN_STATE_CONNECTED = 3, /* netConn already connected */ 31 CONN_STATE_CLOSING = 4, /* send disconn request out */ 32 CONN_STATE_CLOSED = 5, /* connection already closed */ 33 CONN_STATE_BUTT = 0xff 34 }; 35 36 struct SockOsSocket { 37 /* osListNode is used to get the ft socket index based on address indexing 38 so this must be first member of the structure. if need to be changed please 39 handle SockOsListEntry first */ 40 struct HlistNode osListNode; /* This has to be the First member of the structure */ 41 SysIoSock *ioSock; 42 FILLP_INT reference; 43 FILLP_INT addrType; 44 }; 45 46 #define OS_SOCK_OPS_FUNC_VALID(_osSock, _ops_func) \ 47 (((_osSock) != FILLP_NULL_PTR) && \ 48 ((_osSock)->ioSock != FILLP_NULL_PTR) && \ 49 ((_osSock)->ioSock->ops != FILLP_NULL_PTR) && \ 50 ((_osSock)->ioSock->ops->_ops_func != FILLP_NULL_PTR)) 51 52 #ifndef UDP_MAX_SEG 53 #define UDP_MAX_SEG 44u 54 #endif 55 56 struct FtNetconn { 57 struct SpungePcb *pcb; 58 void *sock; 59 struct SockOsSocket *osSocket[MAX_SPUNGEINSTANCE_NUM]; 60 61 FILLP_LLONG connTimeout; 62 63 FILLP_UINT32 closeSet : 1; /* Application calls close() function */ 64 FILLP_UINT32 shutdownRdSet : 1; /* Application called shutdown(sock, RD) */ 65 FILLP_UINT32 shutdownWrSet : 1; /* Application called shutdown(sock, WR) */ 66 FILLP_UINT32 peerRdSet : 1; /* Peer notify that it won't read anything */ 67 FILLP_UINT32 peerWrSet : 1; /* Peer notify that it won't send anything */ 68 FILLP_UINT32 sendBufRunOut : 1; /* Send buffer has run out */ 69 FILLP_UINT32 flagsReverse : 26; 70 FILLP_UINT8 state; 71 FILLP_UINT8 clientFourHandshakeState; 72 FILLP_UINT8 peerFcAlgs; /* bit0: alg1, bit1: alg2 ... */ 73 FILLP_UINT8 padd[1]; 74 FILLP_UINT32 peerCharacters; 75 FILLP_INT lastErr; 76 FILLP_ULLONG calcRttDuringConnect; 77 FILLP_UINT32 peerPktSize; 78 #ifdef FILLP_LINUX 79 size_t iovCount; 80 struct iovec sendIov[UDP_MAX_SEG]; 81 #endif 82 83 #ifdef FILLP_MGT_MSG_LOG 84 FILLP_BOOL extParameterExisted[FILLP_PKT_EXT_BUTT]; 85 #endif 86 }; 87 88 #define NETCONN_GET_OSSOCK(_conn, _instIdx) ((_conn)->osSocket[(_instIdx)]) 89 90 FILLP_INT FillpErrToErrno(FILLP_INT err); 91 void FillpNetconnSetSafeErr(struct FtNetconn *conn, FILLP_INT err); 92 93 void FillpNetconnSetState(struct FtNetconn *conn, FILLP_UINT8 state); 94 95 #define NETCONN_GET_STATE(_conn) ((_conn)->state) 96 97 struct FtNetconn *FillpNetconnAlloc(FILLP_UINT16 domain, struct SpungeInstance *inst); 98 99 void NetconnSetSendCacheSize(struct FtNetconn *conn, FILLP_UINT32 cacheSize); 100 void NetconnSetRecvCacheSize(struct FtNetconn *conn, FILLP_UINT32 cacheSize); 101 void NetconnSetPktSize(struct FtNetconn *conn, FILLP_UINT32 pktSize); 102 void NetconnSetOpersiteRate(struct FtNetconn *conn, FILLP_UINT32 rate); 103 void NetconnSetSlowStart(struct FtNetconn *conn, FILLP_BOOL slowStart); 104 void NetconnSetPackInterval(struct FtNetconn *conn, FILLP_UINT32 interval); 105 void NetconnSetLocalPort(struct FtNetconn *conn, FILLP_INT port); 106 void NetconnSetAddrType(struct FtNetconn *conn, FILLP_UINT16 addrType); 107 void NetconnSetDirectlySend(struct FtNetconn *conn, FILLP_INT directlySend); 108 void NetconnSetConnectTimeout(struct FtNetconn *conn, FILLP_LLONG timeoutUs); 109 110 FILLP_BOOL NetconnIsConnectTimeout(struct FtNetconn *conn); 111 112 void NetconnSetSock(struct FtSocket *sock, struct FtNetconn *conn); 113 void FillpNetconnDestroy(struct FtNetconn *conn); 114 115 void FillpHandleConnConfirmAckInput(struct FtSocket *sock, struct FtNetconn *conn, 116 struct FillpPcb *pcb, FILLP_CONST struct NetBuf *p); 117 118 void FillpInitNewconnBySock(struct FtNetconn *conn, FILLP_CONST struct FtSocket *sock); 119 void FillpConnConfirmInput(struct FillpPcb *pcb, FILLP_CONST struct NetBuf *p, struct SpungeInstance *inst); 120 121 122 #ifdef __cplusplus 123 } 124 #endif 125 126 #endif /* FILLP_NET_H */ 127