1 /*
2 Copyright (c) 2013 - 2017, The Linux Foundation. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above
10       copyright notice, this list of conditions and the following
11       disclaimer in the documentation and/or other materials provided
12       with the distribution.
13     * Neither the name of The Linux Foundation nor the names of its
14       contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 #ifndef IPA_NAT_DRV_H
30 #define IPA_NAT_DRV_H
31 
32 #include "string.h"  /* memset */
33 #include "stdlib.h"  /* free, malloc */
34 #include "stdint.h"  /* uint32_t */
35 
36 /**
37  * struct ipa_nat_ipv4_rule - To hold ipv4 nat rule
38  * @target_ip: destination ip address
39  * @private_ip: private ip address
40  * @target_port: destination port
41  * @private_port: private port
42  * @protocol: protocol of rule (tcp/udp)
43  * @pdn_index: PDN index in the PDN config table
44  */
45 typedef struct {
46 	uint32_t target_ip;
47 	uint32_t private_ip;
48 	uint16_t target_port;
49 	uint16_t private_port;
50 	uint16_t public_port;
51 	uint8_t  protocol;
52 	uint8_t  pdn_index;
53 } ipa_nat_ipv4_rule;
54 
55 /**
56 * struct ipa_nat_pdn_entry - holds a PDN entry data
57 * @public_ip: PDN's public ip address
58 * @src_metadata: metadata to be used for source NAT metadata replacement
59 * @dst_metadata: metadata to be used for destination NAT metadata replacement
60 */
61 typedef struct {
62 	uint32_t public_ip;
63 	uint32_t src_metadata;
64 	uint32_t dst_metadata;
65 } ipa_nat_pdn_entry;
66 
67 /**
68  * ipa_nat_add_ipv4_tbl() - create ipv4 nat table
69  * @public_ip_addr: [in] public ipv4 address
70  * @number_of_entries: [in]  number of nat entries
71  * @table_handle: [out] Handle of new ipv4 nat table
72  *
73  * To create new ipv4 nat table
74  *
75  * Returns:	0  On Success, negative on failure
76  */
77 int ipa_nat_add_ipv4_tbl(uint32_t public_ip_addr,
78 				uint16_t number_of_entries,
79 				uint32_t *table_handle);
80 
81 /**
82  * ipa_nat_del_ipv4_tbl() - delete ipv4 table
83  * @table_handle: [in] Handle of ipv4 nat table
84  *
85  * To delete given ipv4 nat table
86  *
87  * Returns:	0  On Success, negative on failure
88  */
89 int ipa_nat_del_ipv4_tbl(uint32_t table_handle);
90 
91 /**
92  * ipa_nat_add_ipv4_rule() - to insert new ipv4 rule
93  * @table_handle: [in] handle of ipv4 nat table
94  * @rule: [in]  Pointer to new rule
95  * @rule_handle: [out] Return the handle to rule
96  *
97  * To insert new ipv4 nat rule into ipv4 nat table
98  *
99  * Returns:	0  On Success, negative on failure
100  */
101 int ipa_nat_add_ipv4_rule(uint32_t table_handle,
102 				const ipa_nat_ipv4_rule * rule,
103 				uint32_t *rule_handle);
104 
105 /**
106  * ipa_nat_del_ipv4_rule() - to delete ipv4 nat rule
107  * @table_handle: [in] handle of ipv4 nat table
108  * @rule_handle: [in] ipv4 nat rule handle
109  *
110  * To insert new ipv4 nat rule into ipv4 nat table
111  *
112  * Returns:	0  On Success, negative on failure
113  */
114 int ipa_nat_del_ipv4_rule(uint32_t table_handle,
115 				uint32_t rule_handle);
116 
117 
118 /**
119  * ipa_nat_query_timestamp() - to query timestamp
120  * @table_handle: [in] handle of ipv4 nat table
121  * @rule_handle: [in] ipv4 nat rule handle
122  * @time_stamp: [out] time stamp of rule
123  *
124  * To retrieve the timestamp that lastly the
125  * nat rule was accessed
126  *
127  * Returns:	0  On Success, negative on failure
128  */
129 int ipa_nat_query_timestamp(uint32_t  table_handle,
130 				uint32_t  rule_handle,
131 				uint32_t  *time_stamp);
132 
133 
134 /**
135 * ipa_nat_modify_pdn() - modify single PDN entry in the PDN config table
136 * @table_handle: [in] handle of ipv4 nat table
137 * @pdn_index : [in] the index of the entry to be modified
138 * @pdn_info : [in] values for the PDN entry to be changed
139 *
140 * Modify a PDN entry
141 *
142 * Returns:	0  On Success, negative on failure
143 */
144 int ipa_nat_modify_pdn(uint32_t  tbl_hdl,
145 	uint8_t pdn_index,
146 	ipa_nat_pdn_entry *pdn_info);
147 #endif /* IPA_NAT_DRV_H */