1219820Sjeff/* 2219820Sjeff This software is available to you under a choice of one of two 3219820Sjeff licenses. You may choose to be licensed under the terms of the GNU 4219820Sjeff General Public License (GPL) Version 2, available at 5219820Sjeff <http://www.fsf.org/copyleft/gpl.html>, or the OpenIB.org BSD 6219820Sjeff license, available in the LICENSE.TXT file accompanying this 7219820Sjeff software. These details are also available at 8219820Sjeff <http://openib.org/license.html>. 9219820Sjeff 10219820Sjeff THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 11219820Sjeff EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 12219820Sjeff MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 13219820Sjeff NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 14219820Sjeff BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 15219820Sjeff ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 16219820Sjeff CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17219820Sjeff SOFTWARE. 18219820Sjeff 19219820Sjeff Copyright (c) 2004 Topspin Communications. All rights reserved. 20219820Sjeff Copyright (c) 2005-2006 Mellanox Technologies Ltd. All rights reserved. 21219820Sjeff 22219820Sjeff $Id$ 23219820Sjeff*/ 24219820Sjeff 25219820Sjeff#include <netinet/in.h> 26219820Sjeff 27219820Sjeff/* 28219820Sjeff * SDP specific includes 29219820Sjeff */ 30219820Sjeff#include "linux/sdp_inet.h" 31219820Sjeff 32219820Sjeff/* --------------------------------------------------------------------- */ 33219820Sjeff/* library static and global variables */ 34219820Sjeff/* --------------------------------------------------------------------- */ 35219820Sjeff 36219820Sjeff/* max string length to store any IPv4/IPv6 address */ 37219820Sjeff#define MAX_ADDR_STR_LEN 49 38219820Sjeff 39219820Sjefftypedef enum 40219820Sjeff{ 41219820Sjeff USE_TCP = 1, 42219820Sjeff USE_SDP, 43219820Sjeff USE_BOTH, 44219820Sjeff} use_family_t; 45219820Sjeff 46219820Sjeff/* some state to string functions */ 47219820Sjeffstatic inline char * 48219820Sjeff__sdp_get_family_str( 49219820Sjeff use_family_t family ) 50219820Sjeff{ 51219820Sjeff switch ( family ) { 52219820Sjeff case USE_TCP: 53219820Sjeff return "tcp"; 54219820Sjeff break; 55219820Sjeff case USE_SDP: 56219820Sjeff return "sdp"; 57219820Sjeff break; 58219820Sjeff case USE_BOTH: 59219820Sjeff return "both"; 60219820Sjeff break; 61219820Sjeff } 62219820Sjeff return ( "unknown-family" ); 63219820Sjeff} 64219820Sjeff 65219820Sjeff/* data structure for holding address family mapoping rules */ 66219820Sjeff/* note we filter non relevant programs during parsing ... */ 67219820Sjeffstruct use_family_rule 68219820Sjeff{ 69219820Sjeff struct use_family_rule *prev, *next; 70219820Sjeff int match_by_addr; /* if 0 ignore address match */ 71219820Sjeff struct in_addr ipv4; /* IPv4 address for mapping */ 72219820Sjeff unsigned char prefixlen; /* length of CIDR prefix (ie /24) */ 73219820Sjeff int match_by_port; /* if 0 ignore port match */ 74219820Sjeff unsigned short sport, eport; /* start port - end port, inclusive */ 75219820Sjeff use_family_t target_family; /* if match - use this family */ 76219820Sjeff char *prog_name_expr; /* expression for program name */ 77219820Sjeff}; 78219820Sjeff 79219820Sjeffextern struct use_family_rule *__sdp_clients_family_rules_head; 80219820Sjeffextern struct use_family_rule *__sdp_clients_family_rules_tail; 81219820Sjeffextern struct use_family_rule *__sdp_servers_family_rules_head; 82219820Sjeffextern struct use_family_rule *__sdp_servers_family_rules_tail; 83219820Sjeff 84219820Sjeff#define SDP_NETMASK(n) ((n == 0) ? 0 : ~((1UL<<(32 - n)) - 1)) 85219820Sjeff 86219820Sjeff/* match.c */ 87219820Sjeffuse_family_t __sdp_match_connect( 88219820Sjeff const struct sockaddr *sin, 89219820Sjeff const socklen_t addrlen ); 90219820Sjeff 91219820Sjeffuse_family_t __sdp_match_listen( 92219820Sjeff const struct sockaddr *sin, 93219820Sjeff const socklen_t addrlen ); 94219820Sjeff 95219820Sjeff/* config.c */ 96219820Sjeffint __sdp_config_empty( 97219820Sjeff void ); 98219820Sjeff 99219820Sjeffint __sdp_parse_config( 100219820Sjeff const char *config_file ); 101219820Sjeff 102219820Sjeffuse_family_t __sdp_match_by_program( 103219820Sjeff ); 104219820Sjeff 105219820Sjeff/* log.c */ 106219820Sjeffvoid __sdp_log( 107219820Sjeff int level, 108219820Sjeff char *format, 109219820Sjeff ... ); 110219820Sjeff 111219820Sjeffint __sdp_log_get_level( 112219820Sjeff void ); 113219820Sjeff 114219820Sjeffvoid __sdp_log_set_min_level( 115219820Sjeff int level ); 116219820Sjeff 117219820Sjeffint __sdp_log_set_log_stderr( 118219820Sjeff void ); 119219820Sjeff 120219820Sjeffint __sdp_log_set_log_syslog( 121219820Sjeff void ); 122219820Sjeff 123219820Sjeffint __sdp_log_set_log_file( 124219820Sjeff char *filename ); 125219820Sjeff 126219820Sjeff/* port.c */ 127219820Sjeffint __sdp_sockaddr_to_sdp( 128219820Sjeff const struct sockaddr *addr_in, 129219820Sjeff socklen_t addrlen, 130219820Sjeff struct sockaddr_in *addr_out, 131219820Sjeff int *was_ipv6 ); 132