2 // Copyright (c) 2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #ifndef __INCLUDE_LIB_ALG_H__
18 #define __INCLUDE_LIB_ALG_H__
20 #include "rte_ether.h"
22 uint16_t sip_session_number;/* SIP session count */
23 #define IS_STRING_SAME(pStr, strId) (bcmp((pStr), strId, strlen(strId)) == 0)
24 #define TAG_TO_DATAPOS(str) (strlen(str) + 1)
25 #define SKIP_SPACES(pStr) \
27 while (*(char *)(pStr) == ' ') \
31 enum pkt_dir {PRIVATE, PUBLIC};
33 /* enum for SIP Call direction - NAT ALG */
34 enum sip_alg_call_direction {
35 SIP_CALL_INCOMING, /* Incoming call public to private */
36 SIP_CALL_OUTGOING /* Outgoing call private to public */
39 /* enum of SIP port type - NAT ALG */
40 enum sip_alg_port_type {
41 SIP_UDP, /* SIP SDP port 5460 */
42 SIP_RTP, /* RTP port number */
43 SIP_RTCP /* RTCP port number */
47 * Data structure for NAT SIP ALG table key
48 * Key - IP address & L4 port number.
52 * IP address based on direction.
53 * outgoing - public IP, incoming - destinatio IP of pkt
56 uint16_t l4port; /* SIP SDP, RTP, RTCP port number */
62 * Data structure for NAT SIP ALG table entry.
63 * Placeholder for storing SIP ALG entries.
65 struct sip_alg_table_entry {
68 * IP address based on direction.
69 * outgoing - public IP, incoming - destinatio IP of pkt
71 uint16_t l4port; /* SIP UDP (5061), RTP, RTCP port number */
72 uint8_t sip_alg_call_direction;
73 /* Call incoming (pub to prv) or outgoing (prv to pub) */
74 uint8_t sip_alg_call_id[100];/* unique identfier for a SIP call */
75 uint8_t l4port_type;/* SIP_UDP or RTP or RTCP */
79 } __rte_cache_aligned;
82 /* Function declarations */
85 * To initalize SIP ALG library and should be called-
86 * - before other SIP ALG library funcitons
88 * pipeline parameter structure pointer
90 * pipeline application conext structure pointer
94 void lib_sip_alg_init(void);
97 * Main SIP ALG DPI function for processing SIP ALG functionlity
100 * @param pkt_direction
101 * Indicates whether pkt is from PRIVATE or PUBLIC direction
103 * NAPT tranlated IP address based on direction
105 * NAPT translated L4 port based on direction
107 * Original IP address before translation
109 * Original L4 port before translation
115 * 0 means success, -1 means failure
117 int sip_alg_dpi(struct rte_mbuf *pkt, enum pkt_dir pkt_direction,
118 uint32_t modIp, uint16_t modL4Port,
119 uint32_t pubIp, uint16_t pubL4Port,
120 uint16_t modRtpPort, uint16_t modRtcpPort);
123 * To get audio ports from SIP Packet
125 * mbuf packet pointer
127 * rtp port in parameter
129 * rtcp port in parameter
131 * 0 means success, -1 means failre
133 int natSipAlgGetAudioPorts(
134 struct rte_mbuf *pkt,
136 uint16_t *rtcp_port);
137 int natSipAlgMsgFieldPos(
142 int natSipAlgMsgFieldPosFindCrlf(
147 int natSipAlgMsgFieldPosFindSpace(
152 int remove_sip_alg_entry(