1 /* 2 Copyright (c) 2013, 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 30 #include "string.h" /* memset */ 31 #include "stdlib.h" /* free, malloc */ 32 #include "stdint.h" /* uint32_t */ 33 34 /** 35 * struct ipa_nat_ipv4_rule - To hold ipv4 nat rule 36 * @target_ip: destination ip address 37 * @private_ip: private ip address 38 * @target_port: destination port 39 * @private_port: private port 40 * @protocol: protocol of rule (tcp/udp) 41 */ 42 typedef struct { 43 uint32_t target_ip; 44 uint32_t private_ip; 45 uint16_t target_port; 46 uint16_t private_port; 47 uint16_t public_port; 48 uint8_t protocol; 49 } ipa_nat_ipv4_rule; 50 51 /** 52 * ipa_nat_add_ipv4_tbl() - create ipv4 nat table 53 * @public_ip_addr: [in] public ipv4 address 54 * @number_of_entries: [in] number of nat entries 55 * @table_handle: [out] Handle of new ipv4 nat table 56 * 57 * To create new ipv4 nat table 58 * 59 * Returns: 0 On Success, negative on failure 60 */ 61 int ipa_nat_add_ipv4_tbl(uint32_t public_ip_addr, 62 uint16_t number_of_entries, 63 uint32_t *table_handle); 64 65 /** 66 * ipa_nat_del_ipv4_tbl() - delete ipv4 table 67 * @table_handle: [in] Handle of ipv4 nat table 68 * 69 * To delete given ipv4 nat table 70 * 71 * Returns: 0 On Success, negative on failure 72 */ 73 int ipa_nat_del_ipv4_tbl(uint32_t table_handle); 74 75 /** 76 * ipa_nat_add_ipv4_rule() - to insert new ipv4 rule 77 * @table_handle: [in] handle of ipv4 nat table 78 * @rule: [in] Pointer to new rule 79 * @rule_handle: [out] Return the handle to rule 80 * 81 * To insert new ipv4 nat rule into ipv4 nat table 82 * 83 * Returns: 0 On Success, negative on failure 84 */ 85 int ipa_nat_add_ipv4_rule(uint32_t table_handle, 86 const ipa_nat_ipv4_rule * rule, 87 uint32_t *rule_handle); 88 89 /** 90 * ipa_nat_del_ipv4_rule() - to delete ipv4 nat rule 91 * @table_handle: [in] handle of ipv4 nat table 92 * @rule_handle: [in] ipv4 nat rule handle 93 * 94 * To insert new ipv4 nat rule into ipv4 nat table 95 * 96 * Returns: 0 On Success, negative on failure 97 */ 98 int ipa_nat_del_ipv4_rule(uint32_t table_handle, 99 uint32_t rule_handle); 100 101 102 /** 103 * ipa_nat_query_timestamp() - to query timestamp 104 * @table_handle: [in] handle of ipv4 nat table 105 * @rule_handle: [in] ipv4 nat rule handle 106 * @time_stamp: [out] time stamp of rule 107 * 108 * To retrieve the timestamp that lastly the 109 * nat rule was accessed 110 * 111 * Returns: 0 On Success, negative on failure 112 */ 113 int ipa_nat_query_timestamp(uint32_t table_handle, 114 uint32_t rule_handle, 115 uint32_t *time_stamp); 116 117