1/*
2  This software is available to you under a choice of one of two
3  licenses.  You may choose to be licensed under the terms of the GNU
4  General Public License (GPL) Version 2, available at
5  <http://www.fsf.org/copyleft/gpl.html>, or the OpenIB.org BSD
6  license, available in the LICENSE.TXT file accompanying this
7  software.  These details are also available at
8  <http://openib.org/license.html>.
9
10  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
11  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
12  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
13  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
14  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
15  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17  SOFTWARE.
18
19  Copyright (c) 2004 Topspin Communications.  All rights reserved.
20  Copyright (c) 2005-2006 Mellanox Technologies Ltd.  All rights reserved.
21
22  $Id$
23*/
24
25#include <netinet/in.h>
26
27/*
28 * SDP specific includes
29 */
30#include "linux/sdp_inet.h"
31
32/* --------------------------------------------------------------------- */
33/* library static and global variables                                   */
34/* --------------------------------------------------------------------- */
35
36/* max string length to store any IPv4/IPv6 address */
37#define MAX_ADDR_STR_LEN 49
38
39typedef enum
40{
41	USE_TCP = 1,
42	USE_SDP,
43	USE_BOTH,
44} use_family_t;
45
46/* some state to string functions */
47static inline char *
48__sdp_get_family_str(
49	use_family_t family )
50{
51	switch ( family ) {
52	case USE_TCP:
53		return "tcp";
54		break;
55	case USE_SDP:
56		return "sdp";
57		break;
58	case USE_BOTH:
59		return "both";
60		break;
61	}
62	return ( "unknown-family" );
63}
64
65/* data structure for holding address family mapoping rules */
66/* note we filter non relevant programs during parsing ...  */
67struct use_family_rule
68{
69	struct use_family_rule *prev, *next;
70	int match_by_addr;			  /* if 0 ignore address match        */
71	struct in_addr ipv4;			  /* IPv4 address for mapping         */
72	unsigned char prefixlen;	  /* length of CIDR prefix (ie /24)   */
73	int match_by_port;			  /* if 0 ignore port match           */
74	unsigned short sport, eport; /* start port - end port, inclusive */
75	use_family_t target_family;  /* if match - use this family       */
76	char *prog_name_expr;		  /* expression for program name      */
77};
78
79extern struct use_family_rule *__sdp_clients_family_rules_head;
80extern struct use_family_rule *__sdp_clients_family_rules_tail;
81extern struct use_family_rule *__sdp_servers_family_rules_head;
82extern struct use_family_rule *__sdp_servers_family_rules_tail;
83
84#define SDP_NETMASK(n) ((n == 0) ? 0 : ~((1UL<<(32 - n)) - 1))
85
86/* match.c */
87use_family_t __sdp_match_connect(
88	const struct sockaddr *sin,
89	const socklen_t  addrlen );
90
91use_family_t __sdp_match_listen(
92	const struct sockaddr *sin,
93	const socklen_t  addrlen );
94
95/* config.c */
96int __sdp_config_empty(
97	void );
98
99int __sdp_parse_config(
100	const char *config_file );
101
102use_family_t __sdp_match_by_program(
103	 );
104
105/* log.c */
106void __sdp_log(
107	int level,
108	char *format,
109	... );
110
111int __sdp_log_get_level(
112	void );
113
114void __sdp_log_set_min_level(
115	int level );
116
117int __sdp_log_set_log_stderr(
118	void );
119
120int __sdp_log_set_log_syslog(
121	void );
122
123int __sdp_log_set_log_file(
124	char *filename );
125
126/* port.c */
127int __sdp_sockaddr_to_sdp(
128	const struct sockaddr *addr_in,
129	socklen_t addrlen,
130	struct sockaddr_in *addr_out,
131	int *was_ipv6 );
132