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_COOKIE_H
17 #define FILLP_COOKIE_H
18 
19 #include "fillptypes.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 
26 #define FILLP_KEYSIZE             32u
27 /* Max allowed cookie lifetime is 20 seconds + what ever default configured bu user only */
28 #define FILLP_MAX_COOKIE_LIFETIME (20 * 1000 * 1000)
29 /* get STALE_COOKIE error from the server, client add the this preserver time and send the new connect request */
30 #define FILLP_CLIENT_COOKIE_PRESERVE_TIME (10 * 1000 * 1000)
31 
32 #define FILLP_BYTES_TO_STORE_COOKIE_GENERATION_TIME 16
33 /* Below structures are exchanged over network, so there should be no padding, so use pack 1 */
34 #pragma pack(1)
35 
36 typedef struct FillpCookieContentSt {
37     FILLP_UINT8 digest[FILLP_KEYSIZE];                            /* * HMAC-SHA256 Digest * */
38     FILLP_UCHAR arr[FILLP_BYTES_TO_STORE_COOKIE_GENERATION_TIME]; /* time of cookie generation */
39     FILLP_UINT32 lifeTime;                                        /* life time in milliseconds */
40     FILLP_UINT32 localPacketSeqNumber;                            /* local packet sequence number */
41 
42     FILLP_UINT32 remotePacketSeqNumber; /* remote packet sequence number */
43 
44     FILLP_UINT32 localMessageSeqNumber; /* local Message sequence number */
45 
46     FILLP_UINT32 remoteMessageSeqNumber; /* remote Message sequence number */
47     FILLP_UINT32 remoteSendCache;        /* client send to server cache , same as server recv cache */
48 
49     FILLP_UINT32 remoteRecvCache; /* client recv from server cache, same as server send cache */
50     /* Serever port number. local address is not required is enough to identify the serever uniquily */
51     FILLP_UINT16 srcPort;
52     FILLP_UINT16 addressType; /* Address type */
53 
54     struct sockaddr_in6 remoteSockIpv6Addr;
55 } FillpCookieContent;
56 
57 
58 typedef struct InnerfillpCookieContentCalculate {
59     FILLP_UINT8 digest[FILLP_KEYSIZE];                            /* * HMAC-SHA256 Digest * */
60     FILLP_UCHAR arr[FILLP_BYTES_TO_STORE_COOKIE_GENERATION_TIME]; /* time of cookie generation */
61     FILLP_UINT32 lifeTime;                                        /* life time in milliseconds */
62     FILLP_UINT32 localPacketSeqNumber;                            /* local packet sequence number */
63 
64     FILLP_UINT32 remotePacketSeqNumber; /* remote packet sequence number */
65 
66     FILLP_UINT32 localMessageSeqNumber; /* local Message sequence number */
67 
68     FILLP_UINT32 remoteMessageSeqNumber; /* remote Message sequence number */
69     FILLP_UINT32 remoteSendCache;        /* client send to server cache , same as server recv cache */
70 
71     FILLP_UINT32 remoteRecvCache; /* client recv from server cache, same as server send cache */
72     /* Serever port number. local address is not required is enough to identify the serever uniquily */
73     FILLP_UINT16 srcPort;
74     FILLP_UINT16 addressType; /* Address type */
75 
76     struct sockaddr_in6 remoteSockIpv6Addr;
77     struct sockaddr_in6 localSockIpv6Addr;
78 } FillpCookieContentCalculate;
79 
80 #pragma pack()
81 
82 typedef struct FillpMacInfoStruct {
83     FILLP_UINT8 currentMacKey[FILLP_KEYSIZE];
84     FILLP_UINT8 oldMacKey[FILLP_KEYSIZE];
85     FILLP_ULLONG switchOverTime;
86 } FillpMacInfo;
87 
88 void FillpMacTimerExpire(FillpMacInfo *macInfo, FILLP_LLONG curTime);
89 
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 
96 #endif /* FILLP_COOKIE_H */
97