summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2015-12-21 03:27:41 +0100
committerOndrej Zajicek (work) <santiago@crfreenet.org>2015-12-21 03:33:18 +0100
commit23c212e7f1e80a3c6b88b49918972bc28375bd51 (patch)
treee2e162e5f3454ba1213435acf5980bbc4e4ed5d3 /lib
parente92a4b855f668e8ac685ad79c288ff182ebd110b (diff)
Follow-up work on integration
Diffstat (limited to 'lib')
-rw-r--r--lib/net.c6
-rw-r--r--lib/net.h8
-rw-r--r--lib/printf.c14
-rw-r--r--lib/socket.h16
-rw-r--r--lib/unaligned.h1
5 files changed, 21 insertions, 24 deletions
diff --git a/lib/net.c b/lib/net.c
index b851871a..09f23c7a 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -31,15 +31,15 @@ net_format(const net_addr *N, char *buf, int buflen)
{
net_addr_union *n = (void *) N;
- /* FIXME: quick hack */
+ /* XXXX fix %I vs %R */
switch (n->n.type)
{
case NET_IP4:
- return bsnprintf(buf, buflen, "%I/%d", n->ip4.prefix, n->ip4.pxlen);
+ return bsnprintf(buf, buflen, "%R/%d", n->ip4.prefix, n->ip4.pxlen);
case NET_IP6:
return bsnprintf(buf, buflen, "%I/%d", n->ip6.prefix, n->ip6.pxlen);
case NET_VPN4:
- return bsnprintf(buf, buflen, "%u:%u %I/%d", (u32) (n->vpn4.rd >> 32), (u32) n->vpn4.rd, n->vpn4.prefix, n->vpn4.pxlen);
+ return bsnprintf(buf, buflen, "%u:%u %R/%d", (u32) (n->vpn4.rd >> 32), (u32) n->vpn4.rd, n->vpn4.prefix, n->vpn4.pxlen);
case NET_VPN6:
return bsnprintf(buf, buflen, "%u:%u %I/%d", (u32) (n->vpn6.rd >> 32), (u32) n->vpn6.rd, n->vpn6.prefix, n->vpn6.pxlen);
}
diff --git a/lib/net.h b/lib/net.h
index ee9b382e..9439c6db 100644
--- a/lib/net.h
+++ b/lib/net.h
@@ -199,20 +199,20 @@ static inline void net_copy_vpn6(net_addr_vpn6 *dst, const net_addr_vpn6 *src)
static inline u32 net_hash_ip4(const net_addr_ip4 *n)
-{ return ip4_hash(n->prefix) ^ ((u32) n->pxlen << 26); }
+{ return ip4_hash32(n->prefix) ^ ((u32) n->pxlen << 26); }
static inline u32 net_hash_ip6(const net_addr_ip6 *n)
-{ return ip6_hash(n->prefix) ^ ((u32) n->pxlen << 26); }
+{ return ip6_hash32(n->prefix) ^ ((u32) n->pxlen << 26); }
/* XXXX */
static inline u32 u64_hash(u32 a)
{ return u32_hash(a); }
static inline u32 net_hash_vpn4(const net_addr_vpn4 *n)
-{ return ip4_hash(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); }
+{ return ip4_hash32(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); }
static inline u32 net_hash_vpn6(const net_addr_vpn6 *n)
-{ return ip6_hash(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); }
+{ return ip6_hash32(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); }
static inline int net_validate_ip4(const net_addr_ip4 *n)
diff --git a/lib/printf.c b/lib/printf.c
index 9db5363b..071fc953 100644
--- a/lib/printf.c
+++ b/lib/printf.c
@@ -292,9 +292,13 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
case 'I': {
ip_addr a = va_arg(args, ip_addr);
if (flags & SPECIAL)
- ipa_ntox(a, ipbuf);
+ ip6_ntox(ipa_to_ip6(a), ipbuf);
else {
- ipa_ntop(a, ipbuf);
+ // XXXX better IPv4 / IPv6 distinction
+ if (ipa_is_ip4(a))
+ ip4_ntop(ipa_to_ip4(a), ipbuf);
+ else
+ ip6_ntop(ipa_to_ip6(a), ipbuf);
if (field_width == 1)
field_width = (ipa_is_ip4(a) ? IP4_MAX_TEXT_LENGTH : IP6_MAX_TEXT_LENGTH);
}
@@ -319,11 +323,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
/* Router/Network ID - essentially IPv4 address in u32 value */
case 'R':
x = va_arg(args, u32);
- bsprintf(ipbuf, "%d.%d.%d.%d",
- ((x >> 24) & 0xff),
- ((x >> 16) & 0xff),
- ((x >> 8) & 0xff),
- (x & 0xff));
+ ip4_ntop(ip4_from_u32(x), ipbuf);
s = ipbuf;
goto str;
diff --git a/lib/socket.h b/lib/socket.h
index fbea92aa..b067eb54 100644
--- a/lib/socket.h
+++ b/lib/socket.h
@@ -67,18 +67,14 @@ void sk_set_tbsize(sock *s, uint val); /* Resize TX buffer, keeping content */
void sk_set_tbuf(sock *s, void *tbuf); /* Switch TX buffer, NULL-> return to internal */
void sk_dump_all(void);
-static inline int sk_send_buffer_empty(sock *sk)
-{ return sk->tbuf == sk->tpos; }
-
+static inline int sk_is_ipv4(sock *s)
+{ return s->af == AF_INET; }
-#ifdef IPV6
-#define sk_is_ipv4(X) 0
-#define sk_is_ipv6(X) 1
-#else
-#define sk_is_ipv4(X) 1
-#define sk_is_ipv6(X) 0
-#endif
+static inline int sk_is_ipv6(sock *s)
+{ return s->af == AF_INET6; }
+static inline int sk_send_buffer_empty(sock *sk)
+{ return sk->tbuf == sk->tpos; }
int sk_setup_multicast(sock *s); /* Prepare UDP or IP socket for multicasting */
int sk_join_group(sock *s, ip_addr maddr); /* Join multicast group on sk iface */
diff --git a/lib/unaligned.h b/lib/unaligned.h
index dc777fbf..130b2479 100644
--- a/lib/unaligned.h
+++ b/lib/unaligned.h
@@ -17,6 +17,7 @@
* if possible.
*/
+#include "lib/endian.h"
#include "lib/string.h"
static inline u16