summaryrefslogtreecommitdiff
path: root/sysdep
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2013-06-24 16:37:30 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2013-06-24 16:37:30 +0200
commitef4a50be10c6dd0abffd957132cd146029c3d79d (patch)
treef01df1b69d1d5f495dcad82e2f0e30478be55cb8 /sysdep
parentfad04c750ca6906fb095f1b45958dec0ac8e210c (diff)
Better packet priority and traffic class handling.
Implements support for IPv6 traffic class, sets higher priority for OSPF and RIP outgoing packets by default and allows to configure ToS/DS/TClass IP header field and the local priority of outgoing packets.
Diffstat (limited to 'sysdep')
-rw-r--r--sysdep/bsd/sysio.h9
-rw-r--r--sysdep/linux/sysio.h19
-rw-r--r--sysdep/unix/io.c11
3 files changed, 37 insertions, 2 deletions
diff --git a/sysdep/bsd/sysio.h b/sysdep/bsd/sysio.h
index 4f91def5..085f16fa 100644
--- a/sysdep/bsd/sysio.h
+++ b/sysdep/bsd/sysio.h
@@ -284,3 +284,12 @@ sk_set_min_ttl6(sock *s, int ttl)
#endif
+
+int sk_priority_control = -1;
+
+static int
+sk_set_priority(sock *s, int prio UNUSED)
+{
+ log(L_WARN "Socket priority not supported");
+ return -1;
+}
diff --git a/sysdep/linux/sysio.h b/sysdep/linux/sysio.h
index 90b3ebd9..41287e71 100644
--- a/sysdep/linux/sysio.h
+++ b/sysdep/linux/sysio.h
@@ -310,3 +310,22 @@ sk_set_min_ttl6(sock *s, int ttl)
}
#endif
+
+
+#ifndef IPV6_TCLASS
+#define IPV6_TCLASS 67
+#endif
+
+int sk_priority_control = 7;
+
+static int
+sk_set_priority(sock *s, int prio)
+{
+ if (setsockopt(s->fd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio)) < 0)
+ {
+ log(L_WARN "sk_set_priority: setsockopt: %m");
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c
index 80914afe..434a05be 100644
--- a/sysdep/unix/io.c
+++ b/sysdep/unix/io.c
@@ -598,7 +598,7 @@ sock_new(pool *p)
sock *s = ralloc(p, &sk_class);
s->pool = p;
// s->saddr = s->daddr = IPA_NONE;
- s->tos = s->ttl = -1;
+ s->tos = s->priority = s->ttl = -1;
s->fd = -1;
return s;
}
@@ -783,11 +783,18 @@ sk_setup(sock *s)
ERR("fcntl(O_NONBLOCK)");
if (s->type == SK_UNIX)
return NULL;
-#ifndef IPV6
+
+#ifdef IPV6
+ if ((s->tos >= 0) && setsockopt(fd, SOL_IPV6, IPV6_TCLASS, &s->tos, sizeof(s->tos)) < 0)
+ WARN("IPV6_TCLASS");
+#else
if ((s->tos >= 0) && setsockopt(fd, SOL_IP, IP_TOS, &s->tos, sizeof(s->tos)) < 0)
WARN("IP_TOS");
#endif
+ if (s->priority >= 0)
+ sk_set_priority(s, s->priority);
+
#ifdef IPV6
int v = 1;
if ((s->flags & SKF_V6ONLY) && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &v, sizeof(v)) < 0)