Update libsdp to the latest 1.1.108-0.17.ga6958ef.

The only relevant change here is the support for IPv6 in the config
file.  The previous version of this supported IPv6 but not in the
config.  The change for that ended up removing __sdp_sockaddr_to_sdp
which the IPV4 config code required; the IPv6 fix resolved the lack of
that symbol.

Note that the ChangeLog was lacking entries for which we already had the
changes for, which itself was an upstream bug.

Obtained from:	https://www.openfabrics.org/downloads/libsdp/libsdp-1.1.108-0.17.ga6958ef.tar.gz
Sponsored by:	EMC / Isilon Storage Division
This commit is contained in:
Bryan Drewery 2016-03-04 22:37:31 +00:00
parent 1465ae5d7f
commit fc064a5e78
14 changed files with 1101 additions and 374 deletions

View File

@ -1,3 +1,24 @@
2011-04-28 10:25:22 +0300 Amir Vadai <amirv@mellanox.co.il>
* 8cc6058 libsdp: Use logroate on /var/log/libsdp.log
2011-01-17 15:44:30 +0200 Amir Vadai <amirv@mellanox.co.il>
* d7fdb72 libsdp: removed a debug print
2011-01-12 11:24:57 +0200 Amir Vadai <amirv@mellanox.co.il>
* 63e0cf1 libsdp: recompiled yacc files
2011-01-10 17:29:14 +0200 Amir Vadai <amirv@mellanox.co.il>
* 54de044 libsdp: Add IPv6 support to configuration file
2011-01-05 09:52:05 +0200 Amir Vadai <amirv@mellanox.co.il>
* e57ee9c libsdp: Do not set-user-ID on default.
2011-01-03 11:33:44 +0200 Amir Vadai <amirv@mellanox.co.il>
* 18447bb libsdp: Do not block other socket types
2011-01-02 12:29:13 +0200 Amir Vadai <amirv@mellanox.co.il>
* e9d2c10 libsdp: Fix bad errno value
2010-12-26 18:14:02 +0200 Amir Vadai <amirv@mellanox.co.il>
* 9c2ad15 libsdp: full ipv6 support

View File

@ -1,6 +1,6 @@
SUBDIRS = src
EXTRA_DIST = libsdp.spec.in libsdp.conf
EXTRA_DIST = libsdp.spec.in libsdp.conf scripts/libsdp.logrotate
dist-hook: libsdp.spec
cp libsdp.spec $(distdir)

View File

@ -99,11 +99,13 @@ use both client * *:*
# <address|*> means:
# Either the local address the server is bind to or the remote server
# address the client connects to. Syntax for address matching is:
# <IPv4 address>[/<prefix_length>]|*
# IPv4 address = [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ each sub number < 255
# prefix_length = [0-9]+ and with value <= 32. A prefix_length of 24
# matches the subnet mask 255.255.255.0 . A prefix_length of 32
# requires matching of the exact IP.
# <IPv4/IPv6 address>[/<prefix_length>]|*
# IP address = IPv4 in dotted-quad format, "ddd.ddd.ddd.ddd" or IPv6 network
# address in any allowed IPv6 address format.
# prefix_length = Number of bits to match. A prefix_length of 16 matches the
# subnet mask 255.255.0.0 in IPv4, or ffff::0 in IPv6.
# A prefix_length of 32 for IPv4 or 128 for IPv6 requires
# matching of the exact IP.
#
# <port range> is:
# start-port[-end-port] where port numbers are >0 and < 65536
@ -117,6 +119,10 @@ use both client * *:*
# family role program address:port[-range]
# use sdp connect * 192.168.1.0/24:*
#
# Use SDP by clients connecting to machines that belongs to subnet 1234:5678::*
# family role program address:port[-range]
# use sdp connect * 1234:5678::0/64:*
#
# Use SDP by ttcp when it connects to port 5001 of any machine
# family role program address:port[-range]
# use sdp listen ttcp *:5001

View File

@ -17,7 +17,7 @@ and without recompiling the application.
%package devel
Summary: Development files for the libsdp
Group: System Environment/Libraries
Requires: %{name} = %{version}-%{release}
Requires: %{name} = %{version}-%{release}, logrotate
%description devel
Development files of libsdp that may be linked directly to an
@ -31,23 +31,29 @@ application, which may be useful for debugging.
make
%install
etc=$RPM_BUILD_ROOT%{_sysconfdir}
make DESTDIR=${RPM_BUILD_ROOT} install
# remove unpackaged files from the buildroot
rm -f $RPM_BUILD_ROOT%{_libdir}/*.la
mkdir -p $etc/logrotate.d
install -m 644 scripts/libsdp.logrotate $etc/logrotate.d/libsdp
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(6644,root,root)
# For set-user-ID/set-group-ID ELF binaries, only libraries in the standard search directories that are also set-user-ID
# To do so, change line below to: %defattr(6644,root,root)
%defattr(0644,root,root)
%{_libdir}/libsdp*.so*
%defattr(0644,root,root)
%config(noreplace) %{_sysconfdir}/libsdp.conf
%config(noreplace) %{_includedir}/linux/sdp_inet.h
%doc README NEWS ChangeLog COPYING
%config(noreplace) %{_sysconfdir}/logrotate.d/libsdp
%files devel
%defattr(6644,root,root,-)
%defattr(0644,root,root,-)
%{_libdir}/libsdp*.so
%changelog

View File

@ -0,0 +1,6 @@
/var/log/libsdp.log {
missingok
notifempty
copytruncate
compress
}

View File

@ -88,7 +88,8 @@
FILENAME = 269,
NAME = 270,
LEVEL = 271,
LINE = 272
LINE = 272,
SUBNET = 273
};
#endif
/* Tokens. */
@ -107,6 +108,7 @@
#define NAME 270
#define LEVEL 271
#define LINE 272
#define SUBNET 273
@ -147,16 +149,49 @@ int __sdp_config_empty(
(__sdp_servers_family_rules_head == NULL) );
}
/* define the address by 4 integers */
static void __sdp_set_ipv4_addr(short a0, short a1, short a2, short a3)
static void __sdp_set_ip_addr(char *addr)
{
char buf[16];
sprintf(buf,"%d.%d.%d.%d", a0, a1, a2, a3);
if (!inet_aton(buf, &( __sdp_rule.ipv4 )))
{
parse_err = 1;
yyerror("provided address is not legal");
}
int rc;
char *addrlen;
struct sockaddr_in *addr4 = (struct sockaddr_in *)(&__sdp_rule.ip);
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)(&__sdp_rule.ip);
int prefixlen = 0;
addrlen = strrchr(addr, '/');
if (addrlen) {
prefixlen = atoi(addrlen + 1);
*addrlen = '\0';
}
rc = inet_pton(AF_INET, addr, &addr4->sin_addr);
if (rc > 0) {
addr4->sin_family = AF_INET;
__sdp_rule.prefixlen = prefixlen ?: 32;
return;
}
rc = inet_pton(AF_INET6, addr, &addr6->sin6_addr);
if (rc > 0) {
addr6->sin6_family = AF_INET6;
__sdp_rule.prefixlen = prefixlen ?: 128;
return;
}
parse_err = 1;
yyerror("provided address is not legal");
}
static const char *addr2str(struct sockaddr_storage *src)
{
static char dst[INET6_ADDRSTRLEN];
int af = src->ss_family;
const struct sockaddr_in *addr4 = (const struct sockaddr_in *)src;
const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)src;
if (af == AF_INET6)
return inet_ntop(af, &addr6->sin6_addr, dst, INET6_ADDRSTRLEN);
return inet_ntop(af, &addr4->sin_addr, dst, INET6_ADDRSTRLEN);
}
static void __sdp_set_prog_name_expr(char *prog_name_expr)
@ -184,11 +219,8 @@ static void __sdp_dump_config_state() {
__sdp_get_role_str( current_role ),
__sdp_rule.prog_name_expr);
if (__sdp_rule.match_by_addr) {
if ( __sdp_rule.prefixlen != 32 )
sprintf(buf+strlen(buf), " %s/%d",
inet_ntoa( __sdp_rule.ipv4 ), __sdp_rule.prefixlen);
else
sprintf(buf+strlen(buf), " %s", inet_ntoa( __sdp_rule.ipv4 ));
addr2str(&__sdp_rule.ip), __sdp_rule.prefixlen);
} else {
sprintf(buf+strlen(buf), " *");
}
@ -260,13 +292,13 @@ static void __sdp_add_rule() {
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
#line 167 "./config_parser.y"
#line 197 "./config_parser.y"
{
int ival;
char *sval;
}
/* Line 193 of yacc.c. */
#line 270 "y.tab.c"
#line 302 "y.tab.c"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
@ -276,13 +308,13 @@ typedef union YYSTYPE
/* Copy the second part of user declarations. */
#line 192 "./config_parser.y"
#line 223 "./config_parser.y"
long __sdp_config_line_num;
/* Line 216 of yacc.c. */
#line 286 "y.tab.c"
#line 318 "y.tab.c"
#ifdef short
# undef short
@ -497,20 +529,20 @@ union yyalloc
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 7
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST 36
#define YYLAST 31
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 23
#define YYNTOKENS 22
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS 17
#define YYNNTS 16
/* YYNRULES -- Number of rules. */
#define YYNRULES 33
#define YYNRULES 31
/* YYNRULES -- Number of states. */
#define YYNSTATES 53
#define YYNSTATES 44
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
#define YYUNDEFTOK 2
#define YYMAXUTOK 272
#define YYMAXUTOK 273
#define YYTRANSLATE(YYX) \
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
@ -522,8 +554,8 @@ static const yytype_uint8 yytranslate[] =
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 19, 2, 2, 22, 21, 20, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 18, 2,
2, 2, 20, 2, 2, 21, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 19, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
@ -545,7 +577,7 @@ static const yytype_uint8 yytranslate[] =
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17
15, 16, 17, 18
};
#if YYDEBUG
@ -555,32 +587,31 @@ static const yytype_uint8 yyprhs[] =
{
0, 0, 3, 5, 8, 9, 11, 14, 15, 18,
20, 22, 26, 27, 30, 33, 36, 39, 43, 46,
55, 57, 59, 61, 63, 65, 67, 69, 71, 75,
77, 85, 87, 91
55, 57, 59, 61, 63, 65, 67, 69, 71, 73,
75, 79
};
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const yytype_int8 yyrhs[] =
{
26, 0, -1, 17, -1, 24, 17, -1, -1, 24,
-1, 25, 27, -1, -1, 27, 28, -1, 29, -1,
33, -1, 10, 30, 24, -1, -1, 30, 31, -1,
30, 32, -1, 11, 12, -1, 11, 13, -1, 11,
14, 15, -1, 16, 9, -1, 3, 34, 35, 36,
37, 18, 39, 24, -1, 6, -1, 7, -1, 8,
-1, 5, -1, 4, -1, 15, -1, 19, -1, 38,
-1, 38, 20, 9, -1, 19, -1, 9, 21, 9,
21, 9, 21, 9, -1, 9, -1, 9, 22, 9,
-1, 19, -1
25, 0, -1, 17, -1, 23, 17, -1, -1, 23,
-1, 24, 26, -1, -1, 26, 27, -1, 28, -1,
32, -1, 10, 29, 23, -1, -1, 29, 30, -1,
29, 31, -1, 11, 12, -1, 11, 13, -1, 11,
14, 15, -1, 16, 9, -1, 3, 33, 34, 35,
36, 19, 37, 23, -1, 6, -1, 7, -1, 8,
-1, 5, -1, 4, -1, 15, -1, 20, -1, 18,
-1, 20, -1, 9, -1, 9, 21, 9, -1, 20,
-1
};
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
0, 198, 198, 199, 201, 202, 205, 208, 209, 213,
214, 218, 221, 222, 223, 227, 228, 229, 233, 237,
241, 242, 243, 247, 248, 252, 253, 257, 258, 259,
263, 267, 268, 269
0, 229, 229, 230, 232, 233, 236, 239, 240, 244,
245, 249, 252, 253, 254, 258, 259, 260, 264, 268,
272, 273, 274, 278, 279, 283, 284, 288, 289, 293,
294, 295
};
#endif
@ -593,10 +624,10 @@ static const char *const yytname[] =
"\"server or listen\"", "\"tcp\"", "\"sdp\"", "\"both\"",
"\"integer value\"", "\"log statement\"", "\"destination\"",
"\"stderr\"", "\"syslog\"", "\"file\"", "\"a name\"", "\"min-level\"",
"\"new line\"", "':'", "'*'", "'/'", "'.'", "'-'", "$accept", "NL",
"\"new line\"", "\"ip address\"", "':'", "'*'", "'-'", "$accept", "NL",
"ONL", "config", "statements", "statement", "log_statement", "log_opts",
"log_dest", "verbosity", "socket_statement", "family", "role", "program",
"address", "ipv4", "ports", 0
"address", "ports", 0
};
#endif
@ -606,18 +637,18 @@ static const char *const yytname[] =
static const yytype_uint16 yytoknum[] =
{
0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 58, 42,
47, 46, 45
265, 266, 267, 268, 269, 270, 271, 272, 273, 58,
42, 45
};
# endif
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] =
{
0, 23, 24, 24, 25, 25, 26, 27, 27, 28,
28, 29, 30, 30, 30, 31, 31, 31, 32, 33,
34, 34, 34, 35, 35, 36, 36, 37, 37, 37,
38, 39, 39, 39
0, 22, 23, 23, 24, 24, 25, 26, 26, 27,
27, 28, 29, 29, 29, 30, 30, 30, 31, 32,
33, 33, 33, 34, 34, 35, 35, 36, 36, 37,
37, 37
};
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
@ -625,8 +656,8 @@ static const yytype_uint8 yyr2[] =
{
0, 2, 1, 2, 0, 1, 2, 0, 2, 1,
1, 3, 0, 2, 2, 2, 2, 3, 2, 8,
1, 1, 1, 1, 1, 1, 1, 1, 3, 1,
7, 1, 3, 1
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3, 1
};
/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
@ -637,16 +668,15 @@ static const yytype_uint8 yydefact[] =
4, 2, 5, 7, 0, 3, 6, 1, 0, 12,
8, 9, 10, 20, 21, 22, 0, 0, 24, 23,
0, 0, 0, 11, 13, 14, 25, 26, 0, 15,
16, 0, 18, 0, 29, 0, 27, 17, 0, 0,
0, 0, 31, 33, 0, 28, 0, 0, 19, 0,
32, 0, 30
16, 0, 18, 27, 28, 0, 17, 0, 29, 31,
0, 0, 19, 30
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] =
{
-1, 2, 3, 4, 6, 10, 11, 17, 24, 25,
12, 16, 20, 28, 35, 36, 44
12, 16, 20, 28, 35, 40
};
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
@ -654,19 +684,18 @@ static const yytype_int8 yydefgoto[] =
#define YYPACT_NINF -18
static const yytype_int8 yypact[] =
{
-13, -18, 4, -18, 22, -18, 0, -18, 9, -18,
-18, -18, -18, -18, -18, -18, 2, -3, -18, -18,
-10, 6, 14, 4, -18, -18, -18, -18, -8, -18,
-18, 10, -18, 3, -18, 8, 11, -18, 19, -7,
20, 12, 13, -18, -13, -18, 21, 23, 4, 15,
-18, 25, -18
-10, -18, 5, -18, 21, -18, -1, -18, 7, -18,
-18, -18, -18, -18, -18, -18, 15, -6, -18, -18,
-12, 4, 16, 5, -18, -18, -18, -18, -14, -18,
-18, 9, -18, -18, -18, 8, -18, -8, 10, -18,
-10, 17, 5, -18
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] =
{
-18, -17, -18, -18, -18, -18, -18, -18, -18, -18,
-18, -18, -18, -18, -18, -18, -18
-18, -18, -18, -18, -18, -18
};
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
@ -676,30 +705,29 @@ static const yytype_int8 yypgoto[] =
#define YYTABLE_NINF -1
static const yytype_uint8 yytable[] =
{
23, 33, 42, 8, 1, 26, 18, 19, 21, 27,
9, 34, 43, 22, 1, 13, 14, 15, 29, 30,
31, 5, 7, 32, 38, 37, 39, 48, 41, 45,
49, 40, 50, 46, 52, 47, 51
23, 38, 8, 26, 33, 21, 34, 1, 27, 9,
22, 1, 39, 13, 14, 15, 29, 30, 31, 18,
19, 7, 5, 42, 36, 32, 43, 37, 0, 0,
0, 41
};
static const yytype_uint8 yycheck[] =
static const yytype_int8 yycheck[] =
{
17, 9, 9, 3, 17, 15, 4, 5, 11, 19,
10, 19, 19, 16, 17, 6, 7, 8, 12, 13,
14, 17, 0, 9, 21, 15, 18, 44, 9, 9,
9, 20, 9, 21, 9, 22, 21
17, 9, 3, 15, 18, 11, 20, 17, 20, 10,
16, 17, 20, 6, 7, 8, 12, 13, 14, 4,
5, 0, 17, 40, 15, 9, 9, 19, -1, -1,
-1, 21
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] =
{
0, 17, 24, 25, 26, 17, 27, 0, 3, 10,
28, 29, 33, 6, 7, 8, 34, 30, 4, 5,
35, 11, 16, 24, 31, 32, 15, 19, 36, 12,
13, 14, 9, 9, 19, 37, 38, 15, 21, 18,
20, 9, 9, 19, 39, 9, 21, 22, 24, 9,
9, 21, 9
0, 17, 23, 24, 25, 17, 26, 0, 3, 10,
27, 28, 32, 6, 7, 8, 33, 29, 4, 5,
34, 11, 16, 23, 30, 31, 15, 20, 35, 12,
13, 14, 9, 18, 20, 36, 15, 19, 9, 20,
37, 21, 23, 9
};
#define yyerrok (yyerrstatus = 0)
@ -1514,103 +1542,93 @@ yyparse ()
switch (yyn)
{
case 15:
#line 227 "./config_parser.y"
#line 258 "./config_parser.y"
{ __sdp_log_set_log_stderr(); }
break;
case 16:
#line 228 "./config_parser.y"
#line 259 "./config_parser.y"
{ __sdp_log_set_log_syslog(); }
break;
case 17:
#line 229 "./config_parser.y"
#line 260 "./config_parser.y"
{ __sdp_log_set_log_file((yyvsp[(3) - (3)].sval)); }
break;
case 18:
#line 233 "./config_parser.y"
#line 264 "./config_parser.y"
{ __sdp_log_set_min_level((yyvsp[(2) - (2)].ival)); }
break;
case 19:
#line 237 "./config_parser.y"
#line 268 "./config_parser.y"
{ __sdp_add_rule(); }
break;
case 20:
#line 241 "./config_parser.y"
#line 272 "./config_parser.y"
{ __sdp_rule.target_family = USE_TCP; }
break;
case 21:
#line 242 "./config_parser.y"
#line 273 "./config_parser.y"
{ __sdp_rule.target_family = USE_SDP; }
break;
case 22:
#line 243 "./config_parser.y"
#line 274 "./config_parser.y"
{ __sdp_rule.target_family = USE_BOTH; }
break;
case 23:
#line 247 "./config_parser.y"
#line 278 "./config_parser.y"
{ current_role = 1; }
break;
case 24:
#line 248 "./config_parser.y"
#line 279 "./config_parser.y"
{ current_role = 2; }
break;
case 25:
#line 252 "./config_parser.y"
#line 283 "./config_parser.y"
{ __sdp_set_prog_name_expr((yyvsp[(1) - (1)].sval)); }
break;
case 26:
#line 253 "./config_parser.y"
#line 284 "./config_parser.y"
{ __sdp_set_prog_name_expr("*"); }
break;
case 27:
#line 257 "./config_parser.y"
{ __sdp_rule.match_by_addr = 1; __sdp_rule.prefixlen = 32; }
#line 288 "./config_parser.y"
{ __sdp_rule.match_by_addr = 1; __sdp_set_ip_addr((yyvsp[(1) - (1)].sval)); }
break;
case 28:
#line 258 "./config_parser.y"
{ __sdp_rule.match_by_addr = 1; __sdp_rule.prefixlen = (yyvsp[(3) - (3)].ival); }
break;
case 29:
#line 259 "./config_parser.y"
#line 289 "./config_parser.y"
{ __sdp_rule.match_by_addr = 0; __sdp_rule.prefixlen = 32; }
break;
case 30:
#line 263 "./config_parser.y"
{ __sdp_set_ipv4_addr((yyvsp[(1) - (7)].ival),(yyvsp[(3) - (7)].ival),(yyvsp[(5) - (7)].ival),(yyvsp[(7) - (7)].ival)); }
break;
case 31:
#line 267 "./config_parser.y"
case 29:
#line 293 "./config_parser.y"
{ __sdp_rule.match_by_port = 1; __sdp_rule.sport= (yyvsp[(1) - (1)].ival); __sdp_rule.eport= (yyvsp[(1) - (1)].ival); }
break;
case 32:
#line 268 "./config_parser.y"
case 30:
#line 294 "./config_parser.y"
{ __sdp_rule.match_by_port = 1; __sdp_rule.sport= (yyvsp[(1) - (3)].ival); __sdp_rule.eport= (yyvsp[(3) - (3)].ival); }
break;
case 33:
#line 269 "./config_parser.y"
case 31:
#line 295 "./config_parser.y"
{ __sdp_rule.match_by_port = 0; __sdp_rule.sport= 0 ; __sdp_rule.eport= 0; }
break;
/* Line 1267 of yacc.c. */
#line 1614 "y.tab.c"
#line 1632 "y.tab.c"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@ -1824,7 +1842,7 @@ yyparse ()
}
#line 272 "./config_parser.y"
#line 298 "./config_parser.y"
int yyerror(char *msg)

View File

@ -53,7 +53,8 @@
FILENAME = 269,
NAME = 270,
LEVEL = 271,
LINE = 272
LINE = 272,
SUBNET = 273
};
#endif
/* Tokens. */
@ -72,19 +73,20 @@
#define NAME 270
#define LEVEL 271
#define LINE 272
#define SUBNET 273
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
#line 167 "./config_parser.y"
#line 197 "./config_parser.y"
{
int ival;
char *sval;
}
/* Line 1529 of yacc.c. */
#line 88 "y.tab.h"
#line 90 "y.tab.h"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1

View File

@ -0,0 +1,359 @@
/*
* Copyright (c) 2006 Mellanox Technologies Ltd. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* $Id: config_parser.y 1.5 2005/06/29 11:39:27 eitan Exp $
*/
/*
*/
%{
/* header section */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "libsdp.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define YYERROR_VERBOSE 1
extern int yyerror(char *msg);
extern int yylex(void);
static int parse_err = 0;
struct use_family_rule *__sdp_clients_family_rules_head = NULL;
struct use_family_rule *__sdp_clients_family_rules_tail = NULL;
struct use_family_rule *__sdp_servers_family_rules_head = NULL;
struct use_family_rule *__sdp_servers_family_rules_tail = NULL;
/* some globals to store intermidiate parser state */
static struct use_family_rule __sdp_rule;
static int current_role = 0;
int __sdp_config_empty(
void
)
{
return ( (__sdp_clients_family_rules_head == NULL) &&
(__sdp_servers_family_rules_head == NULL) );
}
static void __sdp_set_ip_addr(char *addr)
{
int rc;
char *addrlen;
struct sockaddr_in *addr4 = (struct sockaddr_in *)(&__sdp_rule.ip);
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)(&__sdp_rule.ip);
int prefixlen = 0;
addrlen = strrchr(addr, '/');
if (addrlen) {
prefixlen = atoi(addrlen + 1);
*addrlen = '\0';
}
rc = inet_pton(AF_INET, addr, &addr4->sin_addr);
if (rc > 0) {
addr4->sin_family = AF_INET;
__sdp_rule.prefixlen = prefixlen ?: 32;
return;
}
rc = inet_pton(AF_INET6, addr, &addr6->sin6_addr);
if (rc > 0) {
addr6->sin6_family = AF_INET6;
__sdp_rule.prefixlen = prefixlen ?: 128;
return;
}
parse_err = 1;
yyerror("provided address is not legal");
}
static const char *addr2str(struct sockaddr_storage *src)
{
static char dst[INET6_ADDRSTRLEN];
int af = src->ss_family;
const struct sockaddr_in *addr4 = (const struct sockaddr_in *)src;
const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)src;
if (af == AF_INET6)
return inet_ntop(af, &addr6->sin6_addr, dst, INET6_ADDRSTRLEN);
return inet_ntop(af, &addr4->sin_addr, dst, INET6_ADDRSTRLEN);
}
static void __sdp_set_prog_name_expr(char *prog_name_expr)
{
__sdp_rule.prog_name_expr = strdup(prog_name_expr);
if (!__sdp_rule.prog_name_expr) {
yyerror("fail to allocate program name expression");
}
}
static char *__sdp_get_role_str(int role)
{
if (role == 1) return("server");
if (role == 2) return("client");
return("unknown role");
}
extern int __sdp_min_level;
/* dump the current state in readable format */
static void __sdp_dump_config_state() {
char buf[1024];
sprintf(buf, "CONFIG: use %s %s %s",
__sdp_get_family_str(__sdp_rule.target_family),
__sdp_get_role_str( current_role ),
__sdp_rule.prog_name_expr);
if (__sdp_rule.match_by_addr) {
sprintf(buf+strlen(buf), " %s/%d",
addr2str(&__sdp_rule.ip), __sdp_rule.prefixlen);
} else {
sprintf(buf+strlen(buf), " *");
}
if (__sdp_rule.match_by_port) {
sprintf(buf+strlen(buf), ":%d",__sdp_rule.sport);
if (__sdp_rule.eport > __sdp_rule.sport)
sprintf(buf+strlen(buf), "-%d",__sdp_rule.eport);
}
else
sprintf(buf+strlen(buf), ":*");
sprintf(buf+strlen(buf), "\n");
__sdp_log(1, buf);
}
/* use the above state for making a new rule */
static void __sdp_add_rule() {
struct use_family_rule **p_tail, **p_head, *rule;
if (__sdp_min_level <= 1) __sdp_dump_config_state();
if ( current_role == 1 ) {
p_tail = &__sdp_servers_family_rules_tail;
p_head = &__sdp_servers_family_rules_head;
} else if ( current_role == 2 ) {
p_tail = &__sdp_clients_family_rules_tail;
p_head = &__sdp_clients_family_rules_head;
} else {
yyerror("ignoring unknown role");
parse_err = 1;
return;
}
rule = (struct use_family_rule *)malloc(sizeof(*rule));
if (!rule) {
yyerror("fail to allocate new rule");
parse_err = 1;
return;
}
memset(rule, 0, sizeof(*rule));
*rule = __sdp_rule;
rule->prev = *p_tail;
if (!(*p_head)) {
*p_head = rule;
} else {
(*p_tail)->next = rule;
} /* if */
*p_tail = rule;
}
%}
%union {
int ival;
char *sval;
}
%token USE "use"
%token CLIENT "client or connect"
%token SERVER "server or listen"
%token TCP "tcp"
%token SDP "sdp"
%token BOTH "both"
%token INT "integer value"
%token LOG "log statement"
%token DEST "destination"
%token STDERR "stderr"
%token SYSLOG "syslog"
%token FILENAME "file"
%token NAME "a name"
%token LEVEL "min-level"
%token LINE "new line"
%token SUBNET "ip address"
%type <sval> NAME SUBNET
%type <ival> INT LOG DEST STDERR SYSLOG FILENAME USE TCP SDP BOTH CLIENT SERVER LEVEL LINE
%debug
%error-verbose
%start config
%{
long __sdp_config_line_num;
%}
%%
NL:
LINE
| NL LINE;
ONL:
| NL;
config:
ONL statements
;
statements:
| statements statement
;
statement:
log_statement
| socket_statement
;
log_statement:
LOG log_opts NL
;
log_opts:
| log_opts log_dest
| log_opts verbosity
;
log_dest:
DEST STDERR { __sdp_log_set_log_stderr(); }
| DEST SYSLOG { __sdp_log_set_log_syslog(); }
| DEST FILENAME NAME { __sdp_log_set_log_file($3); }
;
verbosity:
LEVEL INT { __sdp_log_set_min_level($2); }
;
socket_statement:
USE family role program address ':' ports NL { __sdp_add_rule(); }
;
family:
TCP { __sdp_rule.target_family = USE_TCP; }
| SDP { __sdp_rule.target_family = USE_SDP; }
| BOTH { __sdp_rule.target_family = USE_BOTH; }
;
role:
SERVER { current_role = 1; }
| CLIENT { current_role = 2; }
;
program:
NAME { __sdp_set_prog_name_expr($1); }
| '*' { __sdp_set_prog_name_expr("*"); }
;
address:
SUBNET { __sdp_rule.match_by_addr = 1; __sdp_set_ip_addr($1); }
| '*' { __sdp_rule.match_by_addr = 0; __sdp_rule.prefixlen = 32; }
;
ports:
INT { __sdp_rule.match_by_port = 1; __sdp_rule.sport= $1; __sdp_rule.eport= $1; }
| INT '-' INT { __sdp_rule.match_by_port = 1; __sdp_rule.sport= $1; __sdp_rule.eport= $3; }
| '*' { __sdp_rule.match_by_port = 0; __sdp_rule.sport= 0 ; __sdp_rule.eport= 0; }
;
%%
int yyerror(char *msg)
{
/* replace the $undefined and $end if exists */
char *orig_msg = (char*)malloc(strlen(msg)+25);
char *final_msg = (char*)malloc(strlen(msg)+25);
strcpy(orig_msg, msg);
char *word = strtok(orig_msg, " ");
final_msg[0] = '\0';
while (word != NULL) {
if (!strncmp(word, "$undefined", 10)) {
strcat(final_msg, "unrecognized-token ");
} else if (!strncmp(word, "$end",4)) {
strcat(final_msg, "end-of-file ");
} else {
strcat(final_msg, word);
strcat(final_msg, " ");
}
word = strtok(NULL, " ");
}
__sdp_log(9, "Error (line:%ld) : %s\n", __sdp_config_line_num, final_msg);
parse_err = 1;
free(orig_msg);
free(final_msg);
return 1;
}
#include <unistd.h>
#include <errno.h>
/* parse apollo route dump file */
int __sdp_parse_config (const char *fileName) {
extern FILE * libsdp_yyin;
/* open the file */
if (access(fileName, R_OK)) {
printf("libsdp Error: No access to open File:%s %s\n",
fileName, strerror(errno));
return(1);
}
libsdp_yyin = fopen(fileName,"r");
if (!libsdp_yyin) {
printf("libsdp Error: Fail to open File:%s\n", fileName);
return(1);
}
parse_err = 0;
__sdp_config_line_num = 1;
/* parse it */
yyparse();
fclose(libsdp_yyin);
return(parse_err);
}

View File

@ -309,28 +309,32 @@ static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
*yy_cp = '\0'; \
yy_c_buf_p = yy_cp;
#define YY_NUM_RULES 20
#define YY_END_OF_BUFFER 21
static yyconst short int yy_accept[171] =
#define YY_NUM_RULES 21
#define YY_END_OF_BUFFER 22
static yyconst short int yy_accept[195] =
{ 0,
0, 0, 0, 0, 21, 19, 18, 16, 17, 2,
2, 19, 19, 19, 19, 19, 19, 19, 19, 19,
18, 1, 15, 15, 2, 2, 15, 15, 15, 15,
15, 15, 15, 15, 15, 1, 18, 17, 2, 0,
0, 0, 0, 0, 22, 20, 19, 17, 18, 20,
3, 3, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 19, 1, 16, 16, 16, 3, 3,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 1, 19, 18, 0, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 18, 1, 1, 15, 15, 2, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 1, 0, 0, 0, 0, 0, 0,
3, 0, 11, 0, 0, 0, 10, 9, 1, 15,
15, 15, 15, 15, 15, 3, 15, 11, 15, 15,
0, 0, 0, 0, 19, 1, 1, 16, 16, 16,
16, 16, 16, 3, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 1,
0, 2, 2, 0, 0, 0, 0, 0, 0, 4,
0, 12, 0, 0, 0, 11, 10, 1, 16, 2,
2, 16, 16, 16, 16, 16, 16, 4, 16, 12,
16, 16, 16, 11, 10, 0, 13, 0, 0, 0,
9, 0, 0, 0, 0, 0, 16, 13, 16, 16,
16, 9, 16, 16, 16, 16, 16, 0, 0, 0,
0, 0, 0, 0, 0, 16, 16, 16, 16, 16,
16, 16, 16, 14, 0, 0, 15, 0, 7, 8,
14, 16, 16, 15, 16, 7, 8, 0, 0, 16,
16, 0, 0, 16, 16, 0, 6, 16, 6, 0,
16, 5, 5, 0
15, 10, 9, 12, 0, 0, 0, 8, 0, 0,
0, 0, 0, 12, 15, 15, 15, 8, 15, 15,
15, 15, 15, 0, 0, 0, 0, 0, 0, 0,
0, 15, 15, 15, 15, 15, 15, 15, 15, 13,
0, 0, 14, 0, 6, 7, 13, 15, 15, 14,
15, 6, 7, 0, 0, 15, 15, 0, 0, 15,
15, 0, 5, 15, 5, 0, 15, 4, 4, 0
} ;
static yyconst int yy_ec[256] =
@ -339,16 +343,16 @@ static yyconst int yy_ec[256] =
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 1, 1, 4, 1, 1, 1, 1, 1,
1, 1, 1, 1, 5, 1, 1, 6, 7, 7,
7, 7, 7, 7, 7, 7, 7, 1, 1, 1,
1, 5, 1, 1, 6, 7, 8, 9, 10, 10,
10, 10, 10, 10, 10, 10, 10, 11, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 8, 9, 10, 11,
1, 1, 1, 1, 1, 1, 12, 13, 14, 15,
12, 13, 14, 15, 16, 1, 1, 17, 18, 19,
20, 21, 1, 22, 23, 24, 25, 26, 1, 1,
27, 1, 1, 1, 1, 1, 1, 1, 1, 1,
16, 17, 18, 19, 20, 1, 1, 21, 22, 23,
24, 25, 1, 26, 27, 28, 29, 30, 1, 1,
31, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -365,119 +369,146 @@ static yyconst int yy_ec[256] =
1, 1, 1, 1, 1
} ;
static yyconst int yy_meta[28] =
static yyconst int yy_meta[32] =
{ 0,
1, 2, 3, 1, 1, 1, 1, 1, 1, 1,
1, 2, 3, 1, 1, 1, 4, 1, 4, 4,
4, 4, 4, 4, 4, 4, 4, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1
1
} ;
static yyconst short int yy_base[177] =
static yyconst short int yy_base[202] =
{ 0,
0, 26, 30, 56, 214, 215, 211, 215, 0, 215,
55, 192, 46, 199, 194, 48, 193, 58, 198, 184,
63, 0, 0, 204, 0, 65, 185, 56, 192, 187,
58, 186, 68, 191, 177, 197, 196, 0, 77, 173,
180, 176, 171, 176, 169, 177, 171, 168, 166, 176,
163, 164, 172, 73, 0, 0, 0, 181, 80, 158,
165, 161, 156, 161, 154, 162, 156, 153, 151, 161,
148, 149, 157, 166, 152, 154, 146, 140, 151, 138,
215, 156, 215, 134, 147, 141, 215, 215, 0, 142,
144, 136, 130, 141, 128, 0, 146, 0, 124, 137,
0, 30, 34, 64, 295, 296, 292, 296, 0, 60,
62, 65, 68, 0, 269, 56, 276, 271, 58, 270,
68, 275, 261, 83, 0, 0, 285, 93, 78, 82,
275, 86, 87, 104, 105, 106, 98, 265, 104, 270,
256, 280, 279, 0, 269, 0, 114, 128, 120, 271,
250, 257, 253, 248, 253, 246, 254, 248, 245, 243,
253, 240, 241, 249, 132, 0, 0, 0, 262, 0,
132, 132, 139, 142, 252, 234, 241, 237, 146, 238,
231, 239, 233, 230, 228, 238, 225, 226, 234, 247,
136, 296, 0, 229, 231, 223, 217, 228, 215, 296,
131, 0, 0, 215, 128, 134, 129, 215, 132, 126,
130, 119, 120, 0, 120, 126, 121, 0, 124, 118,
122, 111, 112, 107, 120, 110, 109, 115, 104, 103,
110, 99, 112, 102, 101, 107, 96, 95, 102, 215,
91, 106, 215, 87, 215, 215, 0, 88, 103, 0,
84, 0, 0, 85, 96, 83, 94, 78, 76, 75,
73, 69, 215, 68, 0, 62, 40, 215, 0, 215,
95, 97, 28, 99, 101, 103
236, 296, 211, 224, 218, 296, 296, 0, 149, 0,
153, 219, 221, 213, 207, 218, 205, 0, 226, 0,
201, 214, 208, 0, 0, 157, 296, 205, 211, 206,
296, 209, 203, 207, 196, 197, 160, 0, 197, 203,
198, 0, 201, 195, 199, 188, 189, 184, 197, 187,
186, 192, 181, 180, 187, 176, 189, 179, 178, 184,
173, 172, 178, 296, 164, 176, 296, 154, 296, 296,
0, 155, 168, 0, 146, 0, 0, 144, 155, 140,
147, 136, 134, 111, 106, 77, 296, 64, 0, 58,
49, 296, 0, 296, 173, 29, 177, 181, 185, 189,
193
} ;
static yyconst short int yy_def[177] =
static yyconst short int yy_def[202] =
{ 0,
170, 1, 170, 3, 170, 170, 170, 170, 171, 170,
170, 170, 170, 170, 170, 170, 170, 170, 170, 170,
170, 172, 173, 174, 173, 173, 173, 173, 173, 173,
173, 173, 173, 173, 173, 175, 170, 171, 170, 170,
170, 170, 170, 170, 170, 170, 170, 170, 170, 170,
170, 170, 170, 170, 176, 172, 173, 174, 173, 173,
173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
173, 173, 173, 175, 170, 170, 170, 170, 170, 170,
170, 170, 170, 170, 170, 170, 170, 170, 176, 173,
173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
194, 1, 194, 3, 194, 194, 194, 194, 195, 196,
196, 11, 11, 11, 11, 11, 11, 11, 194, 194,
194, 194, 194, 194, 197, 198, 199, 198, 28, 28,
28, 28, 28, 28, 28, 28, 198, 198, 198, 198,
198, 200, 194, 195, 13, 11, 194, 13, 11, 11,
194, 194, 194, 11, 194, 194, 194, 194, 194, 194,
194, 194, 194, 194, 194, 201, 197, 198, 199, 28,
28, 198, 28, 28, 28, 198, 198, 198, 28, 198,
198, 198, 198, 198, 198, 198, 198, 198, 198, 200,
194, 194, 11, 194, 194, 194, 194, 194, 194, 194,
173, 173, 173, 170, 170, 170, 170, 170, 170, 170,
170, 170, 170, 173, 173, 173, 173, 173, 173, 173,
173, 173, 173, 170, 170, 170, 170, 170, 170, 170,
170, 173, 173, 173, 173, 173, 173, 173, 173, 170,
170, 170, 170, 170, 170, 170, 173, 173, 173, 173,
173, 173, 173, 170, 170, 173, 173, 170, 170, 173,
173, 170, 170, 173, 173, 170, 173, 170, 173, 0,
170, 170, 170, 170, 170, 170
194, 194, 194, 194, 194, 194, 194, 201, 198, 198,
28, 198, 198, 198, 198, 198, 198, 198, 198, 198,
198, 198, 198, 198, 198, 194, 194, 194, 194, 194,
194, 194, 194, 194, 194, 194, 198, 198, 198, 198,
198, 198, 198, 198, 198, 198, 198, 194, 194, 194,
194, 194, 194, 194, 194, 198, 198, 198, 198, 198,
198, 198, 198, 194, 194, 194, 194, 194, 194, 194,
198, 198, 198, 198, 198, 198, 198, 194, 194, 198,
198, 194, 194, 198, 198, 194, 194, 198, 198, 194,
198, 194, 198, 0, 194, 194, 194, 194, 194, 194,
194
} ;
static yyconst short int yy_nxt[243] =
static yyconst short int yy_nxt[328] =
{ 0,
6, 7, 8, 9, 6, 10, 11, 6, 12, 13,
14, 6, 15, 6, 6, 6, 16, 17, 6, 6,
6, 6, 18, 19, 20, 6, 6, 21, 57, 22,
23, 7, 8, 24, 23, 25, 26, 23, 27, 28,
29, 23, 30, 23, 23, 23, 31, 32, 23, 23,
23, 23, 33, 34, 35, 23, 23, 21, 169, 36,
39, 39, 41, 45, 54, 42, 55, 46, 48, 49,
59, 59, 61, 65, 54, 62, 55, 66, 68, 69,
168, 50, 39, 39, 51, 59, 59, 167, 166, 165,
164, 70, 163, 162, 71, 38, 38, 56, 56, 58,
6, 7, 8, 9, 6, 6, 10, 6, 11, 12,
13, 14, 15, 16, 17, 14, 18, 6, 6, 6,
19, 20, 6, 6, 6, 6, 21, 22, 23, 6,
6, 24, 46, 25, 26, 7, 8, 27, 26, 26,
28, 26, 29, 30, 31, 32, 33, 34, 35, 32,
36, 26, 26, 26, 37, 38, 26, 26, 26, 26,
39, 40, 41, 26, 26, 24, 45, 42, 45, 47,
45, 193, 48, 49, 49, 194, 52, 56, 50, 53,
192, 57, 59, 60, 65, 72, 66, 191, 73, 72,
74, 74, 73, 72, 72, 61, 73, 73, 62, 70,
58, 74, 74, 89, 89, 161, 160, 159, 158, 157,
156, 147, 155, 154, 140, 153, 152, 150, 151, 150,
149, 148, 147, 146, 145, 143, 144, 143, 142, 141,
140, 139, 138, 137, 136, 135, 134, 133, 132, 131,
130, 129, 128, 127, 126, 125, 124, 123, 122, 121,
120, 119, 118, 117, 116, 115, 114, 113, 112, 111,
110, 109, 108, 107, 106, 105, 104, 56, 103, 102,
101, 100, 99, 98, 97, 96, 95, 94, 93, 92,
91, 90, 38, 88, 87, 86, 85, 84, 83, 82,
81, 80, 79, 78, 77, 76, 75, 37, 56, 73,
190, 71, 71, 70, 71, 71, 71, 71, 71, 71,
76, 72, 72, 72, 73, 73, 73, 81, 84, 85,
79, 82, 91, 91, 77, 80, 189, 78, 49, 49,
188, 86, 92, 65, 87, 66, 93, 93, 45, 72,
109, 109, 73, 110, 91, 91, 126, 111, 111, 72,
74, 74, 73, 72, 187, 186, 73, 109, 109, 137,
72, 92, 185, 73, 110, 92, 92, 184, 110, 110,
183, 182, 115, 44, 44, 181, 44, 67, 67, 180,
67, 68, 171, 179, 68, 69, 69, 178, 69, 90,
90, 164, 90, 108, 108, 177, 108, 176, 174, 175,
72, 67, 64, 63, 60, 38, 53, 52, 47, 44,
43, 40, 37, 170, 5, 170, 170, 170, 170, 170,
170, 170, 170, 170, 170, 170, 170, 170, 170, 170,
170, 170, 170, 170, 170, 170, 170, 170, 170, 170,
170, 170
174, 173, 172, 171, 170, 169, 167, 168, 167, 166,
165, 164, 163, 162, 161, 160, 159, 158, 157, 156,
155, 154, 153, 152, 151, 150, 149, 148, 147, 146,
145, 144, 143, 142, 141, 140, 139, 138, 136, 135,
134, 133, 132, 131, 130, 129, 128, 127, 67, 125,
124, 123, 122, 121, 120, 119, 118, 117, 116, 114,
113, 112, 73, 44, 107, 106, 105, 104, 103, 102,
101, 100, 99, 98, 97, 96, 95, 94, 194, 45,
43, 67, 89, 88, 83, 75, 44, 64, 63, 58,
55, 54, 51, 43, 194, 5, 194, 194, 194, 194,
194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
194, 194, 194, 194, 194, 194, 194
} ;
static yyconst short int yy_chk[243] =
static yyconst short int yy_chk[328] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 2, 173, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 196, 2, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 4, 167, 4,
11, 11, 13, 16, 21, 13, 21, 16, 18, 18,
26, 26, 28, 31, 54, 28, 54, 31, 33, 33,
166, 18, 39, 39, 18, 59, 59, 164, 162, 161,
160, 33, 159, 158, 33, 171, 171, 172, 172, 174,
3, 3, 3, 3, 3, 4, 10, 4, 11, 11,
10, 191, 11, 12, 12, 13, 16, 19, 13, 16,
190, 19, 21, 21, 24, 29, 24, 188, 29, 30,
30, 30, 30, 32, 33, 21, 32, 33, 21, 28,
174, 175, 175, 176, 176, 157, 156, 155, 154, 151,
149, 148, 144, 142, 141, 139, 138, 137, 136, 135,
134, 133, 132, 131, 130, 129, 128, 127, 126, 125,
124, 123, 122, 121, 120, 119, 117, 116, 115, 113,
112, 111, 110, 109, 107, 106, 105, 101, 100, 99,
97, 95, 94, 93, 92, 91, 90, 86, 85, 84,
82, 80, 79, 78, 77, 76, 75, 74, 73, 72,
71, 70, 69, 68, 67, 66, 65, 64, 63, 62,
61, 60, 58, 53, 52, 51, 50, 49, 48, 47,
46, 45, 44, 43, 42, 41, 40, 37, 36, 35,
186, 28, 28, 28, 28, 28, 28, 28, 28, 28,
33, 34, 35, 36, 34, 35, 36, 37, 39, 39,
35, 37, 47, 47, 34, 36, 185, 34, 49, 49,
184, 39, 48, 65, 39, 65, 48, 48, 48, 71,
72, 72, 71, 73, 91, 91, 91, 73, 73, 74,
74, 74, 74, 79, 183, 182, 79, 109, 109, 109,
111, 126, 181, 111, 137, 126, 126, 180, 137, 137,
179, 178, 79, 195, 195, 175, 195, 197, 197, 173,
197, 198, 172, 168, 198, 199, 199, 166, 199, 200,
200, 165, 200, 201, 201, 163, 201, 162, 161, 160,
34, 32, 30, 29, 27, 24, 20, 19, 17, 15,
14, 12, 7, 5, 170, 170, 170, 170, 170, 170,
170, 170, 170, 170, 170, 170, 170, 170, 170, 170,
170, 170, 170, 170, 170, 170, 170, 170, 170, 170,
170, 170
159, 158, 157, 156, 155, 154, 153, 152, 151, 150,
149, 148, 147, 146, 145, 144, 143, 141, 140, 139,
136, 135, 134, 133, 132, 130, 129, 128, 123, 122,
121, 119, 117, 116, 115, 114, 113, 112, 105, 104,
103, 101, 99, 98, 97, 96, 95, 94, 90, 89,
88, 87, 86, 85, 84, 83, 82, 81, 80, 78,
77, 76, 75, 69, 64, 63, 62, 61, 60, 59,
58, 57, 56, 55, 54, 53, 52, 51, 50, 45,
43, 42, 41, 40, 38, 31, 27, 23, 22, 20,
18, 17, 15, 7, 5, 194, 194, 194, 194, 194,
194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
194, 194, 194, 194, 194, 194, 194
} ;
static yy_state_type yy_last_accepting_state;
@ -546,7 +577,7 @@ char *yytext;
extern long __sdp_config_line_num;
#define CANNAME 1
#line 550 "lex.libsdp_yy.c"
#line 581 "lex.libsdp_yy.c"
/* Macros after this point can all be overridden by user definitions in
* section 1.
@ -703,7 +734,7 @@ YY_DECL
#line 55 "./config_scanner.l"
#line 707 "lex.libsdp_yy.c"
#line 738 "lex.libsdp_yy.c"
if ( yy_init )
{
@ -755,13 +786,13 @@ YY_DECL
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 171 )
if ( yy_current_state >= 195 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
while ( yy_base[yy_current_state] != 215 );
while ( yy_base[yy_current_state] != 296 );
yy_find_action:
yy_act = yy_accept[yy_current_state];
@ -793,8 +824,24 @@ YY_RULE_SETUP
{}
YY_BREAK
case 2:
*yy_cp = yy_hold_char; /* undo effects of setting up yytext */
yy_c_buf_p = yy_cp -= 2;
YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP
#line 59 "./config_scanner.l"
{
yylval.ival = SUBNET;
#ifdef DEBUG
printf("SUBNET: %s\n", yytext);
#endif
yylval.sval = (char *)malloc(strlen(yytext) + 1);
strcpy(yylval.sval, yytext);
return SUBNET;
}
YY_BREAK
case 3:
YY_RULE_SETUP
#line 69 "./config_scanner.l"
{
yylval.ival = atoi(yytext);
#ifdef DEBUG
@ -803,9 +850,9 @@ YY_RULE_SETUP
return INT;
}
YY_BREAK
case 3:
case 4:
YY_RULE_SETUP
#line 67 "./config_scanner.l"
#line 77 "./config_scanner.l"
{
yylval.ival = LOG;
#ifdef DEBUG
@ -814,9 +861,9 @@ YY_RULE_SETUP
return LOG;
}
YY_BREAK
case 4:
case 5:
YY_RULE_SETUP
#line 75 "./config_scanner.l"
#line 85 "./config_scanner.l"
{
yylval.ival = DEST;
#ifdef DEBUG
@ -825,9 +872,9 @@ YY_RULE_SETUP
return DEST;
}
YY_BREAK
case 5:
case 6:
YY_RULE_SETUP
#line 83 "./config_scanner.l"
#line 93 "./config_scanner.l"
{
yylval.ival = LEVEL;
#ifdef DEBUG
@ -836,9 +883,9 @@ YY_RULE_SETUP
return LEVEL;
}
YY_BREAK
case 6:
case 7:
YY_RULE_SETUP
#line 91 "./config_scanner.l"
#line 101 "./config_scanner.l"
{
yylval.ival = STDERR;
#ifdef DEBUG
@ -847,9 +894,9 @@ YY_RULE_SETUP
return STDERR;
}
YY_BREAK
case 7:
case 8:
YY_RULE_SETUP
#line 99 "./config_scanner.l"
#line 109 "./config_scanner.l"
{
yylval.ival = SYSLOG;
#ifdef DEBUG
@ -858,9 +905,9 @@ YY_RULE_SETUP
return SYSLOG;
}
YY_BREAK
case 8:
case 9:
YY_RULE_SETUP
#line 107 "./config_scanner.l"
#line 117 "./config_scanner.l"
{
yylval.ival = FILENAME;
#ifdef DEBUG
@ -870,9 +917,9 @@ YY_RULE_SETUP
return FILENAME;
}
YY_BREAK
case 9:
case 10:
YY_RULE_SETUP
#line 116 "./config_scanner.l"
#line 126 "./config_scanner.l"
{
yylval.ival = USE;
#ifdef DEBUG
@ -881,9 +928,9 @@ YY_RULE_SETUP
return USE;
}
YY_BREAK
case 10:
case 11:
YY_RULE_SETUP
#line 124 "./config_scanner.l"
#line 134 "./config_scanner.l"
{
yylval.ival = TCP;
#ifdef DEBUG
@ -892,9 +939,9 @@ YY_RULE_SETUP
return TCP;
}
YY_BREAK
case 11:
case 12:
YY_RULE_SETUP
#line 132 "./config_scanner.l"
#line 142 "./config_scanner.l"
{
yylval.ival = SDP;
#ifdef DEBUG
@ -903,9 +950,9 @@ YY_RULE_SETUP
return SDP;
}
YY_BREAK
case 12:
case 13:
YY_RULE_SETUP
#line 140 "./config_scanner.l"
#line 150 "./config_scanner.l"
{
yylval.ival = BOTH;
#ifdef DEBUG
@ -914,9 +961,9 @@ YY_RULE_SETUP
return BOTH;
}
YY_BREAK
case 13:
case 14:
YY_RULE_SETUP
#line 148 "./config_scanner.l"
#line 158 "./config_scanner.l"
{
yylval.ival = CLIENT;
#ifdef DEBUG
@ -926,9 +973,9 @@ YY_RULE_SETUP
return CLIENT;
}
YY_BREAK
case 14:
case 15:
YY_RULE_SETUP
#line 157 "./config_scanner.l"
#line 167 "./config_scanner.l"
{
yylval.ival = SERVER;
#ifdef DEBUG
@ -938,9 +985,9 @@ YY_RULE_SETUP
return SERVER;
}
YY_BREAK
case 15:
case 16:
YY_RULE_SETUP
#line 166 "./config_scanner.l"
#line 176 "./config_scanner.l"
{
yylval.sval = (char *)malloc(strlen(yytext) + 1);
strcpy(yylval.sval, yytext);
@ -951,9 +998,9 @@ YY_RULE_SETUP
return (NAME);
}
YY_BREAK
case 16:
case 17:
YY_RULE_SETUP
#line 176 "./config_scanner.l"
#line 186 "./config_scanner.l"
{
__sdp_config_line_num++;
#ifdef DEBUG
@ -963,21 +1010,21 @@ YY_RULE_SETUP
return(LINE);
}
YY_BREAK
case 17:
case 18:
YY_RULE_SETUP
#line 185 "./config_scanner.l"
#line 195 "./config_scanner.l"
{
__sdp_config_line_num++;
}
YY_BREAK
case 18:
YY_RULE_SETUP
#line 189 "./config_scanner.l"
{}
YY_BREAK
case 19:
YY_RULE_SETUP
#line 191 "./config_scanner.l"
#line 199 "./config_scanner.l"
{}
YY_BREAK
case 20:
YY_RULE_SETUP
#line 201 "./config_scanner.l"
{
#ifdef DEBUG
printf("CHAR:%c\n",yytext[0]);
@ -985,12 +1032,12 @@ YY_RULE_SETUP
return(yytext[0]);
}
YY_BREAK
case 20:
case 21:
YY_RULE_SETUP
#line 198 "./config_scanner.l"
#line 208 "./config_scanner.l"
ECHO;
YY_BREAK
#line 994 "lex.libsdp_yy.c"
#line 1041 "lex.libsdp_yy.c"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(CANNAME):
yyterminate();
@ -1284,7 +1331,7 @@ static yy_state_type yy_get_previous_state()
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 171 )
if ( yy_current_state >= 195 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@ -1319,11 +1366,11 @@ yy_state_type yy_current_state;
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 171 )
if ( yy_current_state >= 195 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 170);
yy_is_jam = (yy_current_state == 194);
return yy_is_jam ? 0 : yy_current_state;
}
@ -1875,7 +1922,7 @@ int main()
return 0;
}
#endif
#line 198 "./config_scanner.l"
#line 208 "./config_scanner.l"
int yywrap ()

View File

@ -0,0 +1,214 @@
/*
* Copyright (c) 2006 Mellanox Technologies Ltd. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* $Id: ibnl_scanner.ll,v 1.4 2005/02/23 21:08:37 eitan Exp $
*/
%{
/* #define DEBUG 1 */
#define yyparse libsdp_yyparse
#define yylex libsdp_yylex
#define yyerror libsdp_yyerror
#define yylval libsdp_yylval
#define yychar libsdp_yychar
#define yydebug libsdp_yydebug
#define yynerrs libsdp_yynerrs
#define yywrap libsdp_yywrap
#include <string.h>
#include <stdio.h>
#include "config_parser.h"
extern long __sdp_config_line_num;
%}
%s CANNAME
%%
^[ \t]*#.* {}
::|[0-9a-f:\.]*[0-9a-f](\/[0-9]+)?/:[0-9*] {
yylval.ival = SUBNET;
#ifdef DEBUG
printf("SUBNET: %s\n", yytext);
#endif
yylval.sval = (char *)malloc(strlen(yytext) + 1);
strcpy(yylval.sval, yytext);
return SUBNET;
}
([1-9][0-9]*|0) {
yylval.ival = atoi(yytext);
#ifdef DEBUG
printf("INT:%d\n",yylval.ival);
#endif
return INT;
}
log {
yylval.ival = LOG;
#ifdef DEBUG
printf("LOG\n");
#endif
return LOG;
}
destination {
yylval.ival = DEST;
#ifdef DEBUG
printf("DEST\n");
#endif
return DEST;
}
min-level {
yylval.ival = LEVEL;
#ifdef DEBUG
printf("LEVEL\n");
#endif
return LEVEL;
}
stderr {
yylval.ival = STDERR;
#ifdef DEBUG
printf("STDERR\n");
#endif
return STDERR;
}
syslog {
yylval.ival = SYSLOG;
#ifdef DEBUG
printf("SYSLOG\n");
#endif
return SYSLOG;
}
file {
yylval.ival = FILENAME;
#ifdef DEBUG
printf("FILENAME\n");
#endif
BEGIN(CANNAME);
return FILENAME;
}
use {
yylval.ival = USE;
#ifdef DEBUG
printf("USE\n");
#endif
return USE;
}
tcp {
yylval.ival = TCP;
#ifdef DEBUG
printf("TCP\n");
#endif
return TCP;
}
sdp {
yylval.ival = SDP;
#ifdef DEBUG
printf("SDP\n");
#endif
return SDP;
}
both {
yylval.ival = BOTH;
#ifdef DEBUG
printf("BOTH\n");
#endif
return BOTH;
}
client|connect {
yylval.ival = CLIENT;
#ifdef DEBUG
printf("CLIENT\n");
#endif
BEGIN(CANNAME);
return CLIENT;
}
server|listen {
yylval.ival = SERVER;
#ifdef DEBUG
printf("SERVER\n");
#endif
BEGIN(CANNAME);
return SERVER;
}
<CANNAME>[^ \t\n]+ {
yylval.sval = (char *)malloc(strlen(yytext) + 1);
strcpy(yylval.sval, yytext);
#ifdef DEBUG
printf("NAME:%s\n",yylval.sval);
#endif
BEGIN(0);
return (NAME);
}
\n {
__sdp_config_line_num++;
#ifdef DEBUG
printf("LINE\n");
#endif
yylval.ival = LINE;
return(LINE);
}
[#][^\n]* {
__sdp_config_line_num++;
}
[ \t]+ {}
. {
#ifdef DEBUG
printf("CHAR:%c\n",yytext[0]);
#endif
return(yytext[0]);
}
%%
int yywrap ()
{
return (1);
}

View File

@ -67,13 +67,13 @@ __sdp_get_family_str(
struct use_family_rule
{
struct use_family_rule *prev, *next;
int match_by_addr; /* if 0 ignore address match */
struct in_addr ipv4; /* IPv4 address for mapping */
unsigned char prefixlen; /* length of CIDR prefix (ie /24) */
int match_by_port; /* if 0 ignore port match */
unsigned short sport, eport; /* start port - end port, inclusive */
use_family_t target_family; /* if match - use this family */
char *prog_name_expr; /* expression for program name */
int match_by_addr; /* if 0 ignore address match */
struct sockaddr_storage ip; /* IPv4/6 address for mapping */
unsigned char prefixlen; /* length of CIDR prefix (ie /24) */
int match_by_port; /* if 0 ignore port match */
unsigned short sport, eport; /* start port - end port, inclusive */
use_family_t target_family; /* if match - use this family */
char *prog_name_expr; /* expression for program name */
};
extern struct use_family_rule *__sdp_clients_family_rules_head;
@ -122,10 +122,3 @@ int __sdp_log_set_log_syslog(
int __sdp_log_set_log_file(
char *filename );
/* port.c */
int __sdp_sockaddr_to_sdp(
const struct sockaddr *addr_in,
socklen_t addrlen,
struct sockaddr_in *addr_out,
int *was_ipv6 );

View File

@ -38,6 +38,13 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#ifdef __linux__
#include <linux/types.h>
#elif defined(__FreeBSD__)
#define s6_addr32 __u6_addr.__u6_addr32
#define __be32 uint32_t
#endif
/*
* SDP specific includes
@ -62,11 +69,14 @@ get_rule_str(
/* TODO: handle IPv6 in rule */
if ( rule->match_by_addr ) {
if ( rule->prefixlen != 32 )
sprintf( addr_buf, "%s/%d", inet_ntoa( rule->ipv4 ),
rule->prefixlen );
else
sprintf( addr_buf, "%s", inet_ntoa( rule->ipv4 ) );
char tmp[INET6_ADDRSTRLEN] = "BAD ADDRESS";
if (rule->ip.ss_family == AF_INET)
inet_ntop(AF_INET, &((struct sockaddr_in *)&rule->ip)->sin_addr, tmp, sizeof(tmp));
else if (rule->ip.ss_family == AF_INET6)
inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&rule->ip)->sin6_addr, tmp, sizeof(tmp));
sprintf( addr_buf, "%s/%d", tmp, rule->prefixlen);
} else {
strcpy( addr_buf, "*" );
}
@ -82,15 +92,57 @@ get_rule_str(
snprintf( buf, len, "use %s %s %s:%s", target, prog, addr_buf, ports_buf );
}
static inline int __ipv6_prefix_equal(const __be32 *a1, const __be32 *a2,
unsigned int prefixlen)
{
unsigned pdw, pbi;
/* check complete u32 in prefix */
pdw = prefixlen >> 5;
if (pdw && memcmp(a1, a2, pdw << 2))
return 0;
/* check incomplete u32 in prefix */
pbi = prefixlen & 0x1f;
if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
return 0;
return 1;
}
static inline int ipv6_prefix_equal(const struct in6_addr *a1,
const struct in6_addr *a2,
unsigned int prefixlen)
{
return __ipv6_prefix_equal(a1->s6_addr32, a2->s6_addr32,
prefixlen);
}
/* return 0 if the addresses match */
static inline int
match_ipv4_addr(
match_addr(
struct use_family_rule *rule,
const struct sockaddr_in *sin )
const struct sockaddr *addr_in )
{
return ( rule->ipv4.s_addr !=
( sin->sin_addr.
s_addr & htonl( SDP_NETMASK( rule->prefixlen ) ) ) );
const struct sockaddr_in *sin = ( const struct sockaddr_in * )addr_in;
const struct sockaddr_in6 *sin6 = ( const struct sockaddr_in6 * )addr_in;
const struct sockaddr_in *rule_sin = ( const struct sockaddr_in * )(&rule->ip);
const struct sockaddr_in6 *rule_sin6 = ( const struct sockaddr_in6 * )(&rule->ip);
if (rule_sin->sin_family == AF_INET && !rule_sin->sin_addr.s_addr)
return 0;
if (addr_in->sa_family != rule->ip.ss_family)
return -1;
if (addr_in->sa_family == AF_INET) {
return ( rule_sin->sin_addr.s_addr !=
( sin->sin_addr.s_addr &
htonl( SDP_NETMASK( rule->prefixlen ) ) ) );
}
/* IPv6 */
return !ipv6_prefix_equal(&sin6->sin6_addr, &rule_sin6->sin6_addr, rule->prefixlen);
}
static int
@ -101,7 +153,6 @@ match_ip_addr_and_port(
{
const struct sockaddr_in *sin = ( const struct sockaddr_in * )addr_in;
const struct sockaddr_in6 *sin6 = ( const struct sockaddr_in6 * )addr_in;
struct sockaddr_in tmp_sin;
unsigned short port;
int match = 1;
char addr_buf[MAX_ADDR_STR_LEN];
@ -110,14 +161,12 @@ match_ip_addr_and_port(
if ( __sdp_log_get_level( ) <= 3 ) {
if ( sin6->sin6_family == AF_INET6 ) {
addr_str =
inet_ntop( AF_INET6, ( void * )&( sin6->sin6_addr ), addr_buf,
MAX_ADDR_STR_LEN );
addr_str = inet_ntop( AF_INET6, ( void * )&( sin6->sin6_addr ),
addr_buf, MAX_ADDR_STR_LEN );
port = ntohs( sin6->sin6_port );
} else {
addr_str =
inet_ntop( AF_INET, ( void * )&( sin->sin_addr ), addr_buf,
MAX_ADDR_STR_LEN );
addr_str = inet_ntop( AF_INET, ( void * )&( sin->sin_addr ),
addr_buf, MAX_ADDR_STR_LEN );
port = ntohs( sin->sin_port );
}
if ( addr_str == NULL )
@ -129,12 +178,8 @@ match_ip_addr_and_port(
rule_str );
}
/* We currently only support IPv4 and IPv4 embedded in IPv6 */
if ( rule->match_by_port ) {
if ( sin6->sin6_family == AF_INET6 )
port = ntohs( sin6->sin6_port );
else
port = ntohs( sin->sin_port );
port = ntohs( sin->sin_port );
if ( ( port < rule->sport ) || ( port > rule->eport ) ) {
__sdp_log( 3, "NEGATIVE by port range\n" );
@ -143,8 +188,7 @@ match_ip_addr_and_port(
}
if ( match && rule->match_by_addr ) {
if ( __sdp_sockaddr_to_sdp( addr_in, addrlen, &tmp_sin, NULL ) ||
match_ipv4_addr( rule, &tmp_sin ) ) {
if ( match_addr( rule, addr_in ) ) {
__sdp_log( 3, "NEGATIVE by address\n" );
match = 0;
}

View File

@ -356,7 +356,7 @@ static int replace_fd_with_its_shadow(int fd)
int shadow_fd = libsdp_fd_attributes[fd].shadow_fd;
if (shadow_fd == -1) {
__sdp_log(9, "Error replace_fd_with_its_shadow: no shadow for fd:%d\n",
__sdp_log(8, "Error replace_fd_with_its_shadow: no shadow for fd:%d\n",
fd);
return EINVAL;
}
@ -383,7 +383,7 @@ static sa_family_t get_sdp_domain(int domain)
else if (AF_INET6 == domain)
return AF_INET6_SDP;
__sdp_log(9, "Error %s: unknown TCP domain: %d\n", __func__, domain);
__sdp_log(8, "Error %s: unknown TCP domain: %d\n", __func__, domain);
return -1;
}
@ -394,7 +394,7 @@ static int get_sock_domain(int sd)
socklen_t tmp_sinlen = sizeof(tmp_sin);
if (_socket_funcs.getsockname(sd, (struct sockaddr *) &tmp_sin, &tmp_sinlen) < 0) {
__sdp_log(9, "Error %s: getsockname return <%d> for socket\n", __func__, errno);
__sdp_log(8, "Error %s: getsockname return <%d> for socket\n", __func__, errno);
return -1;
}
@ -514,7 +514,7 @@ ioctl(int fd,
}
if (sret < 0) {
__sdp_log(9, "Error ioctl: "
__sdp_log(8, "Error ioctl: "
"<%d> calling ioctl for SDP socket, closing it.\n",
errno);
cleanup_shadow(fd);
@ -560,7 +560,7 @@ int fcntl(int fd, int cmd, ...)
if ((ret >= 0) && (-1 != shadow_fd)) {
sret = _socket_funcs.fcntl(shadow_fd, cmd, arg);
if (sret < 0) {
__sdp_log(9, "Error fcntl:"
__sdp_log(8, "Error fcntl:"
" <%d> calling fcntl(%d, %d, %p) for SDP socket. Closing it.\n",
shadow_fd, cmd, arg, errno);
cleanup_shadow(fd);
@ -617,7 +617,7 @@ setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
" ignoring error on shadow SDP socket fd:<%d>\n", fd);
/*
* HACK: we should allow some errors as some sock opts are unsupported
* __sdp_log(9, "Error %d calling setsockopt for SDP socket, closing\n", errno);
* __sdp_log(8, "Error %d calling setsockopt for SDP socket, closing\n", errno);
* cleanup_shadow(fd);
*/
}
@ -672,6 +672,13 @@ static int __create_socket(int domain, int type, int protocol, int semantics)
__sdp_log(2, "SOCKET: <%s> domain <%d> type <%d> protocol <%d>\n",
program_invocation_short_name, domain, type, protocol);
if (!(AF_INET == domain || AF_INET6 == domain ||
AF_INET_SDP == domain || AF_INET6_SDP == domain)) {
__sdp_log(1, "SOCKET: making other socket\n");
s = __create_socket_semantic(domain, type, protocol, semantics);
goto done;
}
sdp_domain = get_sdp_domain(domain);
if (sdp_domain < 0) {
errno = EAFNOSUPPORT;
@ -737,7 +744,7 @@ static int __create_socket(int domain, int type, int protocol, int semantics)
set_is_sdp_socket(shadow_fd, 1);
set_shadow_for_fd(s, shadow_fd);
} else {
__sdp_log(9,
__sdp_log(8,
"Error socket: <%d> calling socket for SDP socket\n",
errno);
/* fail if we did not make the SDP socket */
@ -747,7 +754,7 @@ static int __create_socket(int domain, int type, int protocol, int semantics)
}
}
} else {
__sdp_log(9, "Error socket: "
__sdp_log(8, "Error socket: "
"ignoring SDP socket since TCP fd:%d out of range\n", s);
}
@ -782,7 +789,7 @@ static int get_fd_addr_port_num(int sd)
ret = _socket_funcs.getsockname(sd, (struct sockaddr *) &addr, &addrlen);
if (ret) {
__sdp_log(9, "Error: in get_fd_addr_port_num - Failed to get getsockname\n");
__sdp_log(8, "Error: in get_fd_addr_port_num - Failed to get getsockname\n");
return -1;
}
@ -925,7 +932,7 @@ find_free_port(const struct sockaddr *sin_addr,
ret = getsockopt(tmp_sd[1 - tmp_turn], SOL_TCP,
SDP_LAST_BIND_ERR, &err, &len);
if (-1 == ret) {
__sdp_log(9, "Error %s:getsockopt: %s\n",
__sdp_log(8, "Error %s:getsockopt: %s\n",
__func__, strerror(errno));
goto close_and_mark;
}
@ -1003,7 +1010,7 @@ check_legal_bind(const struct sockaddr *sin_addr,
__sdp_log(2, "check_legal_bind: binding two temporary sockets\n");
*sdp_sd = _socket_funcs.socket(sdp_domain, SOCK_STREAM, IPPROTO_TCP);
if (*sdp_sd < 0) {
__sdp_log(9, "Error check_legal_bind: " "creating SDP socket failed\n");
__sdp_log(8, "Error check_legal_bind: " "creating SDP socket failed\n");
goto done;
}
@ -1012,12 +1019,12 @@ check_legal_bind(const struct sockaddr *sin_addr,
_socket_funcs.setsockopt(*sdp_sd, SOL_SOCKET, SO_REUSEADDR, &yes,
sizeof(yes));
if (sret < 0) {
__sdp_log(9, "Error bind: Could not setsockopt sdp_sd\n");
__sdp_log(8, "Error bind: Could not setsockopt sdp_sd\n");
}
*tcp_sd = _socket_funcs.socket(domain, SOCK_STREAM, IPPROTO_TCP);
if (*tcp_sd < 0) {
__sdp_log(9, "Error check_legal_bind: "
__sdp_log(8, "Error check_legal_bind: "
"creating second socket failed:%s\n", strerror(errno));
_socket_funcs.close(*sdp_sd);
goto done;
@ -1028,7 +1035,7 @@ check_legal_bind(const struct sockaddr *sin_addr,
_socket_funcs.setsockopt(*tcp_sd, SOL_SOCKET, SO_REUSEADDR, &yes,
sizeof(yes));
if (sret < 0) {
__sdp_log(9, "Error bind: Could not setsockopt tcp_sd\n");
__sdp_log(8, "Error bind: Could not setsockopt tcp_sd\n");
}
__sdp_log(1, "check_legal_bind: binding SDP socket\n");
@ -1043,7 +1050,7 @@ check_legal_bind(const struct sockaddr *sin_addr,
goto done;
#ifdef __linux__
if (-1 == getsockopt(*sdp_sd, SOL_TCP, SDP_LAST_BIND_ERR, &err, &len)) {
__sdp_log(9, "Error check_legal_bind:getsockopt: %s\n",
__sdp_log(8, "Error check_legal_bind:getsockopt: %s\n",
strerror(errno));
goto done;
}
@ -1052,7 +1059,7 @@ check_legal_bind(const struct sockaddr *sin_addr,
#endif
if (-ENOENT != err) {
/* bind() failed due to real error. Can't continue */
__sdp_log(9, "Error check_legal_bind: "
__sdp_log(8, "Error check_legal_bind: "
"binding SDP socket failed:%s\n", strerror(errno));
_socket_funcs.close(*sdp_sd);
_socket_funcs.close(*tcp_sd);
@ -1072,7 +1079,7 @@ check_legal_bind(const struct sockaddr *sin_addr,
__sdp_log(1, "check_legal_bind: binding TCP socket\n");
ret = __bind_semantics(*tcp_sd, sin_addr, addrlen, semantics);
if (ret < 0) {
__sdp_log(9, "Error check_legal_bind: "
__sdp_log(8, "Error check_legal_bind: "
"binding TCP socket failed:%s\n", strerror(errno));
if (-1 != *sdp_sd)
_socket_funcs.close(*sdp_sd);
@ -1097,13 +1104,13 @@ close_and_bind(int old_sd,
__sdp_log(2, "close_and_bind: closing <%d> binding <%d>\n", old_sd, new_sd);
ret = _socket_funcs.close(old_sd);
if (ret < 0) {
__sdp_log(9, "Error bind: Could not close old_sd\n");
__sdp_log(8, "Error bind: Could not close old_sd\n");
goto done;
}
ret = __bind_semantics(new_sd, addr, addrlen, semantics);
if (ret < 0)
__sdp_log(9, "Error bind: Could not bind new_sd\n");
__sdp_log(8, "Error bind: Could not bind new_sd\n");
done:
__sdp_log(2, "close_and_bind: returning <%d>\n", ret);
@ -1148,12 +1155,12 @@ __perform_bind(int fd,
if ((addr == NULL) || is_invalid_addr(addr)) {
errno = EFAULT;
__sdp_log(9, "Error bind: illegal address provided\n");
__sdp_log(8, "Error bind: illegal address provided\n");
return -1;
}
if (get_addr_str(addr, buf, MAX_ADDR_STR_LEN)) {
__sdp_log(9, "Error bind: provided illegal address: %s\n",
__sdp_log(8, "Error bind: provided illegal address: %s\n",
strerror(errno));
return -1;
}
@ -1195,7 +1202,7 @@ __perform_bind(int fd,
* can actually bind the two addresses and then reuse */
ret = check_legal_bind(addr, addrlen, fd, &sdp_sd, &tcp_sd, semantics);
if (ret < 0) {
__sdp_log(9, "Error bind: "
__sdp_log(8, "Error bind: "
"Provided address can not bind on the two sockets\n");
}
}
@ -1215,7 +1222,7 @@ __perform_bind(int fd,
ret = close_and_bind(tcp_sd, fd, (struct sockaddr *) &tmp_addr,
addrlen, semantics);
if (ret < 0) {
__sdp_log(9, "Error bind: " "Could not close_and_bind TCP side\n");
__sdp_log(8, "Error bind: " "Could not close_and_bind TCP side\n");
if (-1 != sdp_sd)
_socket_funcs.close(sdp_sd);
goto done;
@ -1226,7 +1233,7 @@ __perform_bind(int fd,
addrlen, semantics);
if (ret < 0) {
__sdp_log(9,
__sdp_log(8,
"Error bind: " "Could not close_and_bind sdp side\n");
goto done;
}
@ -1302,12 +1309,12 @@ __perform_connect(int fd, const struct sockaddr *serv_addr,
if ((serv_addr == NULL) || is_invalid_addr(serv_addr)) {
errno = EFAULT;
__sdp_log(9, "Error connect: illegal address provided\n");
__sdp_log(8, "Error connect: illegal address provided\n");
return -1;
}
if (get_addr_str(serv_addr, buf, MAX_ADDR_STR_LEN)) {
__sdp_log(9, "Error connect: provided illegal address: %s\n",
__sdp_log(8, "Error connect: provided illegal address: %s\n",
strerror(errno));
return EADDRNOTAVAIL;
}
@ -1347,7 +1354,7 @@ __perform_connect(int fd, const struct sockaddr *serv_addr,
ret = __connect_semantics(shadow_fd, serv_addr, addrlen, semantics);
if ((ret < 0) && (errno != EINPROGRESS)) {
__sdp_log(9, "Error connect: "
__sdp_log(7, "Error connect: "
"failed for SDP fd:%d with error:%m\n", shadow_fd);
} else {
__sdp_log(7, "CONNECT: connected SDP fd:%d to:%s port %d\n",
@ -1377,7 +1384,7 @@ __perform_connect(int fd, const struct sockaddr *serv_addr,
__sdp_log(1, "CONNECT: connecting TCP fd:%d\n", fd);
ret = __connect_semantics(fd, serv_addr, addrlen, semantics);
if ((ret < 0) && (errno != EINPROGRESS))
__sdp_log(9, "Error connect: for TCP fd:%d failed with error:%m\n",
__sdp_log(8, "Error connect: for TCP fd:%d failed with error:%m\n",
fd);
else
__sdp_log(7, "CONNECT: connected TCP fd:%d to:%s port %d\n",
@ -1385,7 +1392,7 @@ __perform_connect(int fd, const struct sockaddr *serv_addr,
if ((target_family == USE_TCP) || (ret >= 0) || (errno == EINPROGRESS)) {
if (cleanup_shadow(fd) < 0)
__sdp_log(9,
__sdp_log(8,
"Error connect: failed to cleanup shadow for fd:%d\n",
fd);
}
@ -1460,7 +1467,7 @@ static int __perform_listen(int fd, int backlog, int semantics)
/* we need to obtain the address from the fd */
if (_socket_funcs.getsockname(fd, (struct sockaddr *) &tmp_sin, &tmp_sinlen)
< 0) {
__sdp_log(9, "Error listen: getsockname return <%d> for TCP socket\n",
__sdp_log(8, "Error listen: getsockname return <%d> for TCP socket\n",
errno);
errno = EADDRNOTAVAIL;
sret = -1;
@ -1468,7 +1475,7 @@ static int __perform_listen(int fd, int backlog, int semantics)
}
if (get_addr_str((struct sockaddr *) &tmp_sin, buf, MAX_ADDR_STR_LEN)) {
__sdp_log(9, "Error listen: provided illegal address: %s\n",
__sdp_log(8, "Error listen: provided illegal address: %s\n",
strerror(errno));
}
@ -1505,14 +1512,14 @@ static int __perform_listen(int fd, int backlog, int semantics)
ret = close_and_bind(tcp_sd, fd, (struct sockaddr *) sin4,
tmp_sinlen, semantics);
if (ret < 0) {
__sdp_log(9, "Error listen: "
__sdp_log(8, "Error listen: "
"Could not close_and_bind TCP side\n");
}
ret = close_and_bind(sdp_sd, shadow_fd, (struct sockaddr *) sin4,
tmp_sinlen, semantics);
if (ret < 0) {
__sdp_log(9, "Error listen: "
__sdp_log(8, "Error listen: "
"Could not close_and_bind SDP side\n");
}
}
@ -1522,7 +1529,7 @@ static int __perform_listen(int fd, int backlog, int semantics)
__sdp_log(1, "LISTEN: calling listen on TCP fd:%d\n", fd);
ret = __listen_semantics(fd, backlog, semantics);
if (ret < 0) {
__sdp_log(9, "Error listen: failed with code <%d> on TCP fd:<%d>\n",
__sdp_log(8, "Error listen: failed with code <%d> on TCP fd:<%d>\n",
errno, fd);
} else {
__sdp_log(7, "LISTEN: fd:%d listening on TCP bound to:%s port:%d\n",
@ -1534,7 +1541,7 @@ static int __perform_listen(int fd, int backlog, int semantics)
__sdp_log(1, "LISTEN: calling listen on SDP fd:<%d>\n", shadow_fd);
sret = __listen_semantics(shadow_fd, backlog, semantics);
if (sret < 0) {
__sdp_log(9, "Error listen: failed with code <%d> SDP fd:<%d>\n",
__sdp_log(8, "Error listen: failed with code <%d> SDP fd:<%d>\n",
errno, shadow_fd);
} else {
__sdp_log(7, "LISTEN: fd:%d listening on SDP bound to:%s port:%d\n",
@ -1546,7 +1553,7 @@ static int __perform_listen(int fd, int backlog, int semantics)
if ((target_family == USE_TCP) && (ret >= 0)) {
__sdp_log(1, "LISTEN: cleaning up shadow SDP\n");
if (cleanup_shadow(fd) < 0)
__sdp_log(9, "Error listen: failed to cleanup shadow for fd:%d\n",
__sdp_log(8, "Error listen: failed to cleanup shadow for fd:%d\n",
fd);
}
@ -1604,7 +1611,7 @@ int close(int fd)
if (shadow_fd != -1) {
__sdp_log(1, "CLOSE: closing shadow fd:<%d>\n", shadow_fd);
if (cleanup_shadow(fd) < 0)
__sdp_log(9, "Error close: failed to cleanup shadow for fd:%d\n",
__sdp_log(8, "Error close: failed to cleanup shadow for fd:%d\n",
fd);
}
@ -1643,7 +1650,7 @@ int dup(int fd)
return (fd);
if (!is_valid_fd(newfd)) {
__sdp_log(9, "Error dup: new fd <%d> out of range.\n", newfd);
__sdp_log(8, "Error dup: new fd <%d> out of range.\n", newfd);
} else {
/* copy attributes from old fd */
libsdp_fd_attributes[newfd] = libsdp_fd_attributes[fd];
@ -1653,7 +1660,7 @@ int dup(int fd)
__sdp_log(1, "DUP: duplication shadow fd:<%d>\n", shadow_fd);
new_shadow_fd = _socket_funcs.dup(shadow_fd);
if ((new_shadow_fd > max_file_descriptors) || (new_shadow_fd < 0)) {
__sdp_log(9, "Error dup: new shadow fd <%d> out of range.\n",
__sdp_log(8, "Error dup: new shadow fd <%d> out of range.\n",
new_shadow_fd);
} else {
libsdp_fd_attributes[new_shadow_fd] =
@ -1705,7 +1712,7 @@ int dup2(int fd, int newfd)
shadow_newfd);
ret = _socket_funcs.close(shadow_newfd);
if (ret != 0) {
__sdp_log(9,
__sdp_log(8,
"DUP2: fail to close newfd:<%d> shadow:<%d> with: %d %s\n",
newfd, shadow_newfd, ret, strerror(errno));
}
@ -1714,7 +1721,7 @@ int dup2(int fd, int newfd)
__sdp_log(1, "DUP2: duplicating fd:<%d> into:<%d>\n", fd, newfd);
newfd = _socket_funcs.dup2(fd, newfd);
if ((newfd > max_file_descriptors) || (newfd < 0)) {
__sdp_log(9, "Error dup2: new fd <%d> out of range.\n", newfd);
__sdp_log(8, "Error dup2: new fd <%d> out of range.\n", newfd);
} else {
/* copy attributes from old fd */
libsdp_fd_attributes[fd].shadow_fd = -1;
@ -1725,7 +1732,7 @@ int dup2(int fd, int newfd)
__sdp_log(1, "DUP2: duplication shadow fd:<%d>\n", shadow_fd);
new_shadow_fd = _socket_funcs.dup(shadow_fd);
if ((new_shadow_fd > max_file_descriptors) || (new_shadow_fd < 0)) {
__sdp_log(9, "Error dup2: new shadow fd <%d> out of range.\n",
__sdp_log(8, "Error dup2: new shadow fd <%d> out of range.\n",
new_shadow_fd);
} else {
libsdp_fd_attributes[new_shadow_fd] =
@ -1766,13 +1773,13 @@ int getsockname(int fd, struct sockaddr *name, socklen_t * namelen)
/* double check provided pointers */
if ((name == NULL) || is_invalid_addr(name)) {
errno = EFAULT;
__sdp_log(9, "Error getsockname: illegal address provided\n");
__sdp_log(8, "Error getsockname: illegal address provided\n");
return -1;
}
if ((namelen != NULL) && is_invalid_addr(namelen)) {
errno = EFAULT;
__sdp_log(9, "Error getsockname: illegal address length pointer provided\n");
__sdp_log(8, "Error getsockname: illegal address length pointer provided\n");
return -1;
}
@ -1812,13 +1819,13 @@ int getpeername(int fd, struct sockaddr *name, socklen_t * namelen)
/* double check provided pointers */
if ((name == NULL) || is_invalid_addr(name)) {
errno = EFAULT;
__sdp_log(9, "Error getsockname: illegal address provided\n");
__sdp_log(8, "Error getsockname: illegal address provided\n");
return -1;
}
if ((namelen != NULL) && is_invalid_addr(namelen)) {
errno = EFAULT;
__sdp_log(9,
__sdp_log(8,
"Error getsockname: illegal address length pointer provided\n");
return -1;
}
@ -1869,13 +1876,13 @@ int accept(int fd, struct sockaddr *addr, socklen_t * addrlen)
/* double check provided pointers */
if ((addr != NULL) && is_invalid_addr(addr)) {
errno = EINVAL;
__sdp_log(9, "Error accept: illegal address provided\n");
__sdp_log(8, "Error accept: illegal address provided\n");
return -1;
}
if ((addrlen != NULL) && is_invalid_addr(addrlen)) {
errno = EINVAL;
__sdp_log(9, "Error accept: illegal address length pointer provided\n");
__sdp_log(8, "Error accept: illegal address length pointer provided\n");
return -1;
}
@ -1892,7 +1899,7 @@ int accept(int fd, struct sockaddr *addr, socklen_t * addrlen)
ret = _socket_funcs.accept(fd, addr, addrlen);
if (ret < 0) {
if (!(fopts & O_NONBLOCK && errno == EWOULDBLOCK))
__sdp_log(9, "Error accept: accept returned :<%d> %s\n",
__sdp_log(8, "Error accept: accept returned :<%d> %s\n",
ret, strerror(errno));
} else {
set_is_sdp_socket(ret, get_is_sdp_socket(fd));
@ -1964,7 +1971,7 @@ int accept(int fd, struct sockaddr *addr, socklen_t * addrlen)
}
} else {
if (errno != EINTR) {
__sdp_log(9,
__sdp_log(8,
"Error accept: select returned :<%d> (%d) %s\n",
ret, errno, strerror(errno));
} else {
@ -2328,7 +2335,7 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
if (shadow_fd != -1) {
ret2 = _socket_funcs.epoll_ctl(epfd, op, shadow_fd, event);
if (ret2 < 0) {
__sdp_log(9, "Error epoll_ctl <%s:%d:%d>",
__sdp_log(8, "Error epoll_ctl <%s:%d:%d>",
program_invocation_short_name, fd, shadow_fd);
return ret2;
}

View File

@ -19,3 +19,7 @@ CFLAGS+= -DSYSCONFDIR=\"/etc\"
CFLAGS+= -I${OFEDSYS}/include
.include <bsd.lib.mk>
# Remove .[ly] since the checked-in version is preferred.
.SUFFIXES:
.SUFFIXES: .o .po .So .c .ln