summaryrefslogtreecommitdiffstats
path: root/sysdep
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2010-04-02 11:31:20 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2010-04-02 11:31:20 +0200
commitbed417288e989c48a1362bb1177f436a2e2f9f4f (patch)
tree3fb727a0e2b0be0cfecef14f30b57134eeb3348b /sysdep
parent126683feeda03ffb5a4ce23611e59a4598382d49 (diff)
downloadbird-bed417288e989c48a1362bb1177f436a2e2f9f4f.tar
bird-bed417288e989c48a1362bb1177f436a2e2f9f4f.zip
Minor fixes to previous patches.
Diffstat (limited to 'sysdep')
-rw-r--r--sysdep/bsd/sysio.h14
-rw-r--r--sysdep/linux/sysio.h12
-rw-r--r--sysdep/unix/io.c143
3 files changed, 86 insertions, 83 deletions
diff --git a/sysdep/bsd/sysio.h b/sysdep/bsd/sysio.h
index 9ee4ade..87c78fb 100644
--- a/sysdep/bsd/sysio.h
+++ b/sysdep/bsd/sysio.h
@@ -150,18 +150,18 @@ sysio_process_rx_cmsgs(sock *s, struct msghdr *msg)
// log(L_WARN "RX %I %d", s->laddr, s->lifindex);
}
-
-void
-sysio_prepare_tx_cmsgs(sock *s, struct msghdr *msg)
+/* Unfortunately, IP_SENDSRCADDR does not work for raw IP sockets on BSD kernels */
+static void
+sysio_prepare_tx_cmsgs(sock *s, struct msghdr *msg, void *cbuf, size_t cbuflen)
{
struct cmsghdr *cm;
struct in_addr *sa;
if (!(s->flags & SKF_LADDR_TX))
- {
- msg->msg_controllen = 0;
- return;
- }
+ return;
+
+ msg->msg_control = cbuf;
+ msg->msg_controllen = cbuflen;
if (s->iface)
{
diff --git a/sysdep/linux/sysio.h b/sysdep/linux/sysio.h
index 91cbdcd..1cfbcc4 100644
--- a/sysdep/linux/sysio.h
+++ b/sysdep/linux/sysio.h
@@ -272,17 +272,17 @@ sysio_process_rx_cmsgs(sock *s, struct msghdr *msg)
}
-void
-sysio_prepare_tx_cmsgs(sock *s, struct msghdr *msg)
+static void
+sysio_prepare_tx_cmsgs(sock *s, struct msghdr *msg, void *cbuf, size_t cbuflen)
{
struct cmsghdr *cm;
struct in_pktinfo *pi;
if (!(s->flags & SKF_LADDR_TX))
- {
- msg->msg_controllen = 0;
- return;
- }
+ return;
+
+ msg->msg_control = cbuf;
+ msg->msg_controllen = cbuflen;
cm = CMSG_FIRSTHDR(msg);
cm->cmsg_level = IPPROTO_IP;
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c
index e9d78b6..abfa5c2 100644
--- a/sysdep/unix/io.c
+++ b/sysdep/unix/io.c
@@ -660,6 +660,77 @@ get_sockaddr(struct sockaddr_in *sa, ip_addr *a, unsigned *port, int check)
#endif
+
+#ifdef IPV6
+
+/* PKTINFO handling is also standardized in IPv6 */
+#define CMSG_RX_SPACE CMSG_SPACE(sizeof(struct in6_pktinfo))
+#define CMSG_TX_SPACE CMSG_SPACE(sizeof(struct in6_pktinfo))
+
+static char *
+sysio_register_cmsgs(sock *s)
+{
+ int ok = 1;
+ if ((s->flags & SKF_LADDR_RX) &&
+ setsockopt(s->fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &ok, sizeof(ok)) < 0)
+ return "IPV6_RECVPKTINFO";
+
+ return NULL;
+}
+
+static void
+sysio_process_rx_cmsgs(sock *s, struct msghdr *msg)
+{
+ struct cmsghdr *cm;
+ struct in6_pktinfo *pi = NULL;
+
+ if (!(s->flags & SKF_LADDR_RX))
+ return;
+
+ for (cm = CMSG_FIRSTHDR(msg); cm != NULL; cm = CMSG_NXTHDR(msg, cm))
+ {
+ if (cm->cmsg_level == IPPROTO_IPV6 && cm->cmsg_type == IPV6_PKTINFO)
+ pi = (struct in6_pktinfo *) CMSG_DATA(cm);
+ }
+
+ if (!pi)
+ {
+ s->laddr = IPA_NONE;
+ s->lifindex = 0;
+ return;
+ }
+
+ get_inaddr(&s->laddr, &pi->ipi6_addr);
+ s->lifindex = pi->ipi6_ifindex;
+ return;
+}
+
+static void
+sysio_prepare_tx_cmsgs(sock *s, struct msghdr *msg, void *cbuf, size_t cbuflen)
+{
+ struct cmsghdr *cm;
+ struct in6_pktinfo *pi;
+
+ if (!(s->flags & SKF_LADDR_TX))
+ return;
+
+ msg->msg_control = cbuf;
+ msg->msg_controllen = cbuflen;
+
+ cm = CMSG_FIRSTHDR(msg);
+ cm->cmsg_level = IPPROTO_IPV6;
+ cm->cmsg_type = IPV6_PKTINFO;
+ cm->cmsg_len = CMSG_LEN(sizeof(*pi));
+
+ pi = (struct in6_pktinfo *) CMSG_DATA(cm);
+ set_inaddr(&pi->ipi6_addr, s->saddr);
+ pi->ipi6_ifindex = s->iface ? s->iface->index : 0;
+
+ msg->msg_controllen = cm->cmsg_len;
+ return;
+}
+#endif
+
static char *
sk_set_ttl_int(sock *s)
{
@@ -856,71 +927,6 @@ sk_leave_group(sock *s, ip_addr maddr)
return 0;
}
-/* PKTINFO handling is also standardized in IPv6 */
-#define CMSG_RX_SPACE CMSG_SPACE(sizeof(struct in6_pktinfo))
-
-static char *
-sysio_register_cmsgs(sock *s)
-{
- int ok = 1;
- if ((s->flags & SKF_LADDR_RX) &&
- setsockopt(s->fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &ok, sizeof(ok)) < 0)
- return "IPV6_RECVPKTINFO";
-
- return NULL;
-}
-
-void
-sysio_process_rx_cmsgs(sock *s, struct msghdr *msg)
-{
- struct cmsghdr *cm;
- struct in6_pktinfo *pi = NULL;
-
- if (!(s->flags & SKF_LADDR_RX))
- return;
-
- for (cm = CMSG_FIRSTHDR(msg); cm != NULL; cm = CMSG_NXTHDR(msg, cm))
- {
- if (cm->cmsg_level == IPPROTO_IPV6 && cm->cmsg_type == IPV6_PKTINFO)
- pi = (struct in6_pktinfo *) CMSG_DATA(cm);
- }
-
- if (!pi)
- {
- s->laddr = IPA_NONE;
- s->lifindex = 0;
- return;
- }
-
- get_inaddr(&s->laddr, &pi->ipi6_addr);
- s->lifindex = pi->ipi6_ifindex;
- return;
-}
-
-void
-sysio_prepare_tx_cmsgs(sock *s, struct msghdr *msg)
-{
- struct cmsghdr *cm;
- struct in6_pktinfo *pi;
-
- if (!(s->flags & SKF_LADDR_TX))
- {
- msg->msg_controllen = 0;
- return;
- }
-
- cm = CMSG_FIRSTHDR(msg);
- cm->cmsg_level = IPPROTO_IPV6;
- cm->cmsg_type = PIV6_PKTINFO;
- cm->cmsg_len = CMSG_LEN(sizeof(*pi));
-
- pi = (struct in6_pktinfo *) CMSG_DATA(cm);
- set_inaddr(&pi->ipi6_addr, s->saddr);
- pi->ipi6_ifindex = s->iface ? s->iface->index : 0;
-
- msg->msg_controllen = cmsg->cmsg_len;
- return;
-}
#else /* IPV4 */
@@ -1216,12 +1222,9 @@ sk_maybe_write(sock *s)
.msg_name = &sa,
.msg_namelen = sizeof(sa),
.msg_iov = &iov,
- .msg_iovlen = 1,
- .msg_control = cmsg_buf,
- .msg_controllen = sizeof(cmsg_buf),
- .msg_flags = 0};
+ .msg_iovlen = 1};
- sysio_prepare_tx_cmsgs(s, &msg);
+ sysio_prepare_tx_cmsgs(s, &msg, cmsg_buf, sizeof(cmsg_buf));
e = sendmsg(s->fd, &msg, 0);
if (e < 0)