summaryrefslogtreecommitdiffstats
path: root/common/VIL/alg/lib_sip_alg.h
blob: b320a4f420b5a85d971d63098285b3608f53ecdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
// Copyright (c) 2017 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/

#ifndef __INCLUDE_LIB_ALG_H__
#define __INCLUDE_LIB_ALG_H__

#include "rte_ether.h"

uint16_t sip_session_number;/* SIP session count */
#define IS_STRING_SAME(pStr, strId) (bcmp((pStr), strId, strlen(strId)) == 0)
#define TAG_TO_DATAPOS(str) (strlen(str) + 1)
#define SKIP_SPACES(pStr)		\
{					\
	while (*(char *)(pStr) == ' ')	\
	(char *)(pStr)++;		\
}

enum pkt_dir {PRIVATE, PUBLIC};

/* enum for  SIP Call direction - NAT ALG */
enum sip_alg_call_direction {
	SIP_CALL_INCOMING, /* Incoming call public to private */
	SIP_CALL_OUTGOING /* Outgoing call private to public */
};

/* enum of  SIP port type - NAT ALG */
enum sip_alg_port_type {
	SIP_UDP, /* SIP SDP port 5460 */
	SIP_RTP, /* RTP port number */
	SIP_RTCP /* RTCP port number */
};

/*
 * Data structure for NAT SIP ALG table key
 * Key - IP address & L4 port number.
 */
struct sip_alg_key {
	/*
	 *  IP address based on direction.
	 *  outgoing - public IP, incoming - destinatio IP of pkt
	 */
	uint32_t ip_address;
	uint16_t l4port; /* SIP SDP, RTP, RTCP port number */
	uint8_t filler1;
	uint8_t filler2;
};

/*
 * Data structure for NAT SIP ALG table entry.
 * Placeholder for storing SIP ALG entries.
 */
struct sip_alg_table_entry {
	uint32_t ip_address;
	/*
	 * IP address based on direction.
	 * outgoing - public IP, incoming - destinatio IP of pkt
	 */
	uint16_t l4port; /* SIP UDP (5061), RTP, RTCP port number */
	uint8_t sip_alg_call_direction;
	/* Call incoming (pub to prv) or outgoing (prv to pub) */
	uint8_t sip_alg_call_id[100];/* unique identfier for a SIP call */
	uint8_t l4port_type;/* SIP_UDP or RTP or RTCP */
	uint8_t filler1;
	uint16_t filler2;
	uint32_t filler3;
} __rte_cache_aligned;


/* Function declarations */

/**
 * To initalize SIP ALG library and should be called-
 * - before other SIP ALG library funcitons
 * @param params
 * pipeline parameter structure pointer
 * @param app
 * pipeline application conext structure pointer
 * @return
 * void return
 */
void lib_sip_alg_init(void);

/**
 * Main SIP ALG DPI function for processing SIP ALG functionlity
 * @param pkt
 * mbuf packet pointer
 * @param pkt_direction
 * Indicates whether pkt is from PRIVATE or PUBLIC direction
 * @param modIp
 * NAPT tranlated IP address based on direction
 * @param modL4Port
 * NAPT translated L4 port based on direction
 * @param pubIP
 * Original IP address before translation
 * @param pubL4Port
 * Original L4 port before translation
 * @param modRtpPort
 * RTP port
 * @param modRtcpPort
 * RTCP port
 * @return
 * 0 means success, -1 means failure
 */
int sip_alg_dpi(struct rte_mbuf *pkt, enum pkt_dir pkt_direction,
		uint32_t modIp, uint16_t modL4Port,
		uint32_t pubIp, uint16_t pubL4Port,
		uint16_t modRtpPort, uint16_t modRtcpPort);

/**
 * To get audio ports from SIP Packet
 * @param pkt
 * mbuf packet pointer
 * @param rtpPort
 * rtp port in parameter
 * @param rtcpPort
 * rtcp port in parameter
 * @return
 * 0 means success, -1 means failre
 */
int natSipAlgGetAudioPorts(
	struct rte_mbuf *pkt,
	uint16_t *rtpPort,
	uint16_t *rtcp_port);
int natSipAlgMsgFieldPos(
	char *pData,
	const char *pIdStr,
	int *pos,
	int searchLen);
int natSipAlgMsgFieldPosFindCrlf(
	char *pData,
	const char *pIdStr,
	int *pPos,
	int searchLen);
int natSipAlgMsgFieldPosFindSpace(
	char *pData,
	const char *pIdStr,
	int *pPos,
	int searchLen);
int remove_sip_alg_entry(
	uint32_t ipaddr,
	uint16_t portid);

#endif