projects
/
l2tpns.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
9bc9ec9
)
resolve gcc 4.1 warning by changing ip_hash to a union
author
bodea
<bodea>
Sat, 1 Jul 2006 14:07:35 +0000
(14:07 +0000)
committer
bodea
<bodea>
Sat, 1 Jul 2006 14:07:35 +0000
(14:07 +0000)
l2tpns.c
patch
|
blob
|
history
diff --git
a/l2tpns.c
b/l2tpns.c
index
d70786b
..
515efc8
100644
(file)
--- a/
l2tpns.c
+++ b/
l2tpns.c
@@
-4,7
+4,7
@@
// Copyright (c) 2002 FireBrick (Andrews & Arnold Ltd / Watchfront Ltd) - GPL licenced
// vim: sw=8 ts=8
// Copyright (c) 2002 FireBrick (Andrews & Arnold Ltd / Watchfront Ltd) - GPL licenced
// vim: sw=8 ts=8
-char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.1
69 2006/07/01 12:40:17
bodea Exp $";
+char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.1
70 2006/07/01 14:07:35
bodea Exp $";
#include <arpa/inet.h>
#include <assert.h>
#include <arpa/inet.h>
#include <assert.h>
@@
-82,9
+82,13
@@
uint16_t MSS = 0; // TCP MSS
struct cli_session_actions *cli_session_actions = NULL; // Pending session changes requested by CLI
struct cli_tunnel_actions *cli_tunnel_actions = NULL; // Pending tunnel changes required by CLI
struct cli_session_actions *cli_session_actions = NULL; // Pending session changes requested by CLI
struct cli_tunnel_actions *cli_tunnel_actions = NULL; // Pending tunnel changes required by CLI
-static void *ip_hash[256]; // Mapping from IP address to session structures.
+union iphash {
+ sessionidt sess;
+ union iphash *idx;
+} ip_hash[256]; // Mapping from IP address to session structures.
+
struct ipv6radix {
struct ipv6radix {
-
in
t sess;
+
sessionid
t sess;
struct ipv6radix *branch;
} ipv6_hash[256]; // Mapping from IPv6 address to session structures.
struct ipv6radix *branch;
} ipv6_hash[256]; // Mapping from IPv6 address to session structures.
@@
-189,9
+193,9
@@
struct Tstats *_statistics = NULL;
struct Tringbuffer *ringbuffer = NULL;
#endif
struct Tringbuffer *ringbuffer = NULL;
#endif
-static void cache_ipmap(in_addr_t ip,
in
t s);
+static void cache_ipmap(in_addr_t ip,
sessionid
t s);
static void uncache_ipmap(in_addr_t ip);
static void uncache_ipmap(in_addr_t ip);
-static void cache_ipv6map(struct in6_addr ip, int prefixlen,
in
t s);
+static void cache_ipv6map(struct in6_addr ip, int prefixlen,
sessionid
t s);
static void free_ip_address(sessionidt s);
static void dump_acct_info(int all);
static void sighup_handler(int sig);
static void free_ip_address(sessionidt s);
static void dump_acct_info(int all);
static void sighup_handler(int sig);
@@
-678,19
+682,19
@@
static void initudp(void)
// IP address.
//
// IP address.
//
-static
in
t lookup_ipmap(in_addr_t ip)
+static
sessionid
t lookup_ipmap(in_addr_t ip)
{
uint8_t *a = (uint8_t *) &ip;
{
uint8_t *a = (uint8_t *) &ip;
- u
int8_t **d = (uint8_t **)
ip_hash;
+ u
nion iphash *h =
ip_hash;
- if (!(
d = (uint8_t **) d[(size_t) *a++]
)) return 0;
- if (!(
d = (uint8_t **) d[(size_t) *a++]
)) return 0;
- if (!(
d = (uint8_t **) d[(size_t) *a++]
)) return 0;
+ if (!(
h = h[*a++].idx
)) return 0;
+ if (!(
h = h[*a++].idx
)) return 0;
+ if (!(
h = h[*a++].idx
)) return 0;
- return
(int) (intptr_t) d[(size_t) *a]
;
+ return
h[*a].sess
;
}
}
-static
in
t lookup_ipv6map(struct in6_addr ip)
+static
sessionid
t lookup_ipv6map(struct in6_addr ip)
{
struct ipv6radix *curnode;
int i;
{
struct ipv6radix *curnode;
int i;
@@
-718,18
+722,18
@@
static int lookup_ipv6map(struct in6_addr ip)
sessionidt sessionbyip(in_addr_t ip)
{
sessionidt sessionbyip(in_addr_t ip)
{
-
in
t s = lookup_ipmap(ip);
+
sessionid
t s = lookup_ipmap(ip);
CSTAT(sessionbyip);
if (s > 0 && s < MAXSESSION && session[s].opened)
CSTAT(sessionbyip);
if (s > 0 && s < MAXSESSION && session[s].opened)
- return
(sessionidt)
s;
+ return s;
return 0;
}
sessionidt sessionbyipv6(struct in6_addr ip)
{
return 0;
}
sessionidt sessionbyipv6(struct in6_addr ip)
{
-
in
t s;
+
sessionid
t s;
CSTAT(sessionbyipv6);
if (!memcmp(&config->ipv6_prefix, &ip, 8) ||
CSTAT(sessionbyipv6);
if (!memcmp(&config->ipv6_prefix, &ip, 8) ||
@@
-755,25
+759,22
@@
sessionidt sessionbyipv6(struct in6_addr ip)
//
// (It's actually cached in network order)
//
//
// (It's actually cached in network order)
//
-static void cache_ipmap(in_addr_t ip,
in
t s)
+static void cache_ipmap(in_addr_t ip,
sessionid
t s)
{
in_addr_t nip = htonl(ip); // MUST be in network order. I.e. MSB must in be ((char *) (&ip))[0]
uint8_t *a = (uint8_t *) &nip;
{
in_addr_t nip = htonl(ip); // MUST be in network order. I.e. MSB must in be ((char *) (&ip))[0]
uint8_t *a = (uint8_t *) &nip;
- u
int8_t **d = (uint8_t **)
ip_hash;
+ u
nion iphash *h =
ip_hash;
int i;
for (i = 0; i < 3; i++)
{
int i;
for (i = 0; i < 3; i++)
{
- if (!d[(size_t) a[i]])
- {
- if (!(d[(size_t) a[i]] = calloc(256, sizeof(void *))))
- return;
- }
+ if (!(h[a[i]].idx || (h[a[i]].idx = calloc(256, sizeof(union iphash)))))
+ return;
-
d = (uint8_t **) d[(size_t) a[i]]
;
+
h = h[a[i]].idx
;
}
}
-
d[(size_t) a[3]] = (uint8_t *) (intptr_t)
s;
+
h[a[3]].sess =
s;
if (s > 0)
LOG(4, s, session[s].tunnel, "Caching ip address %s\n", fmtaddr(nip, 0));
if (s > 0)
LOG(4, s, session[s].tunnel, "Caching ip address %s\n", fmtaddr(nip, 0));
@@
-788,7
+789,7
@@
static void uncache_ipmap(in_addr_t ip)
cache_ipmap(ip, 0); // Assign it to the NULL session.
}
cache_ipmap(ip, 0); // Assign it to the NULL session.
}
-static void cache_ipv6map(struct in6_addr ip, int prefixlen,
in
t s)
+static void cache_ipv6map(struct in6_addr ip, int prefixlen,
sessionid
t s)
{
int i;
int bytes;
{
int i;
int bytes;
@@
-829,7
+830,7
@@
static void cache_ipv6map(struct in6_addr ip, int prefixlen, int s)
//
int cmd_show_ipcache(struct cli_def *cli, char *command, char **argv, int argc)
{
//
int cmd_show_ipcache(struct cli_def *cli, char *command, char **argv, int argc)
{
-
char **d = (char **) ip_hash, **e, **f, *
*g;
+
union iphash *d = ip_hash, *e, *f,
*g;
int i, j, k, l;
int count = 0;
int i, j, k, l;
int count = 0;
@@
-840,24
+841,28
@@
int cmd_show_ipcache(struct cli_def *cli, char *command, char **argv, int argc)
for (i = 0; i < 256; ++i)
{
for (i = 0; i < 256; ++i)
{
- if (!d[i])
+ if (!d[i]
.idx
)
continue;
continue;
- e = (char **) d[i];
+
+ e = d[i].idx;
for (j = 0; j < 256; ++j)
{
for (j = 0; j < 256; ++j)
{
- if (!e[j])
+ if (!e[j]
.idx
)
continue;
continue;
- f = (char **) e[j];
+
+ f = e[j].idx;
for (k = 0; k < 256; ++k)
{
for (k = 0; k < 256; ++k)
{
- if (!f[k])
+ if (!f[k]
.idx
)
continue;
continue;
- g = (char **)f[k];
+
+ g = f[k].idx;
for (l = 0; l < 256; ++l)
{
for (l = 0; l < 256; ++l)
{
- if (!g[l])
+ if (!g[l]
.sess
)
continue;
continue;
- cli_print(cli, "%7d %d.%d.%d.%d", (int) (intptr_t) g[l], i, j, k, l);
+
+ cli_print(cli, "%7d %d.%d.%d.%d", g[l].sess, i, j, k, l);
++count;
}
}
++count;
}
}