summaryrefslogtreecommitdiff
path: root/sysdep
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2014-10-24 11:11:43 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2014-10-24 11:11:43 +0200
commit88a183c6c9a2b86b52f67e87bbc8b7edd32670c6 (patch)
treeb1348b71e69f9ed0d919a4792549026c9e31b092 /sysdep
parentf8fefde318c6248ad94e7b6d60155deed9ab8eed (diff)
Integrated IP functions.
Diffstat (limited to 'sysdep')
-rw-r--r--sysdep/bsd/krt-sock.c4
-rw-r--r--sysdep/unix/io.c23
-rw-r--r--sysdep/unix/unix.h18
3 files changed, 32 insertions, 13 deletions
diff --git a/sysdep/bsd/krt-sock.c b/sysdep/bsd/krt-sock.c
index 621f7309..0e65c51c 100644
--- a/sysdep/bsd/krt-sock.c
+++ b/sysdep/bsd/krt-sock.c
@@ -382,7 +382,7 @@ krt_read_route(struct ks_msg *msg, struct krt_proto *p, int scan)
if ((c < 0) || !(c & IADDR_HOST) || ((c & IADDR_SCOPE_MASK) <= SCOPE_LINK))
SKIP("strange class/scope\n");
- int pxlen = (flags & RTF_HOST) ? MAX_PREFIX_LENGTH : ipa_mklen(imask);
+ int pxlen = (flags & RTF_HOST) ? MAX_PREFIX_LENGTH : ipa_masklen(imask);
if (pxlen < 0)
{ log(L_ERR "%s (%I) - netmask %I", errmsg, idst, imask); return; }
@@ -653,7 +653,7 @@ krt_read_addr(struct ks_msg *msg, int scan)
ibrd = ipa_from_sa(&brd);
- if ((masklen = ipa_mklen(imask)) < 0)
+ if ((masklen = ipa_masklen(imask)) < 0)
{
log(L_ERR "KIF: Invalid masklen %I for %s", imask, iface->name);
return;
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c
index 164038ec..04f0fe50 100644
--- a/sysdep/unix/io.c
+++ b/sysdep/unix/io.c
@@ -764,6 +764,29 @@ sk_set_tos6(sock *s, int tos)
return 0;
}
+static inline byte *
+sk_skip_ip_header(byte *pkt, int *len)
+{
+ if ((*len < 20) || ((*pkt & 0xf0) != 0x40))
+ return NULL;
+
+ int hlen = (*pkt & 0x0f) * 4;
+ if ((hlen < 20) || (hlen > *len))
+ return NULL;
+
+ *len -= hlen;
+ return pkt + hlen;
+}
+
+byte *
+sk_rx_buffer(sock *s, int *len)
+{
+ if (sk_is_ipv4(s) && (s->type == SK_IP))
+ return sk_skip_ip_header(s->rbuf, len);
+ else
+ return s->rbuf;
+}
+
/*
* Public socket functions
diff --git a/sysdep/unix/unix.h b/sysdep/unix/unix.h
index 518713bc..3cee96b4 100644
--- a/sysdep/unix/unix.h
+++ b/sysdep/unix/unix.h
@@ -47,19 +47,9 @@ typedef struct sockaddr_bird {
#ifdef IPV6
#define BIRD_AF AF_INET6
-#define _MI6(x1,x2,x3,x4) _MI(x1, x2, x3, x4)
-#define ipa_is_link_local(x) ipa_has_link_scope(x)
#define ipa_from_sa(x) ipa_from_sa6(x)
-#define ipa_from_u32(x) _MI6(0,0,0xffff,x)
-#define ipa_to_u32(x) _I3(x)
#else
#define BIRD_AF AF_INET
-#define _I0(X) 0
-#define _I1(X) 0
-#define _I2(X) 0
-#define _I3(X) 0
-#define _MI6(x1,x2,x3,x4) IPA_NONE
-#define ipa_is_link_local(x) 0
#define ipa_from_sa(x) ipa_from_sa4(x)
#endif
@@ -75,7 +65,7 @@ static inline ip_addr ipa_from_in4(struct in_addr a)
{ return ipa_from_u32(ntohl(a.s_addr)); }
static inline ip_addr ipa_from_in6(struct in6_addr a)
-{ return _MI6(ntohl(a.s6_addr32[0]), ntohl(a.s6_addr32[1]), ntohl(a.s6_addr32[2]), ntohl(a.s6_addr32[3])); }
+{ return ipa_build6(ntohl(a.s6_addr32[0]), ntohl(a.s6_addr32[1]), ntohl(a.s6_addr32[2]), ntohl(a.s6_addr32[3])); }
static inline ip_addr ipa_from_sa4(sockaddr *sa)
{ return ipa_from_in4(((struct sockaddr_in *) sa)->sin_addr); }
@@ -86,8 +76,14 @@ static inline ip_addr ipa_from_sa6(sockaddr *sa)
static inline struct in_addr ipa_to_in4(ip_addr a)
{ return (struct in_addr) { htonl(ipa_to_u32(a)) }; }
+#ifdef IPV6
static inline struct in6_addr ipa_to_in6(ip_addr a)
{ return (struct in6_addr) { .s6_addr32 = { htonl(_I0(a)), htonl(_I1(a)), htonl(_I2(a)), htonl(_I3(a)) } }; }
+#else
+/* Temporary dummy */
+static inline struct in6_addr ipa_to_in6(ip_addr a)
+{ return (struct in6_addr) { .s6_addr32 = { 0, 0, 0, 0 } }; }
+#endif
void sockaddr_fill(sockaddr *sa, int af, ip_addr a, struct iface *ifa, uint port);
int sockaddr_read(sockaddr *sa, int af, ip_addr *a, struct iface **ifa, uint *port);