From: Arne Meyer <meyer.arne83@netcologne.de>
To: "9front@9front.org" <9front@9front.org>
Subject: [9front] [PATCH] ipv6 flow label support
Date: Sat, 25 Nov 2023 19:27:41 +0100 (CET) [thread overview]
Message-ID: <1375031432.2686734.1700936861177@comcenter.netcologne.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 280 bytes --]
Hello,
this patch implements ipv6 flow labels. The labels are generated by hashing the 5-tuple (src,dst,proto,srcport,dstport) with the fnv-1a hash function (http://www.isthe.com/chongo/tech/comp/fnv/index.html). Flow labels are implemented for tcp, udp and esp.
Greetings,
Arne
[-- Attachment #2: flowlabel.patch --]
[-- Type: application/octet-stream, Size: 3509 bytes --]
diff 970d3b7eb7dc56aa84924dd68c4c39fd1df5d1f5 uncommitted
--- a/sys/src/9/ip/esp.c
+++ b/sys/src/9/ip/esp.c
@@ -339,6 +339,7 @@
Esptail *et;
Userhdr *uh;
Versdep vers;
+ uint hash;
getverslens(convipvers(c), &vers);
bp = qget(c->wq);
@@ -414,6 +415,11 @@
hnputl(eh6->espspi, ecb->spi);
hnputl(eh6->espseq, ++ecb->seq);
+
+ hash = flowhash(eh6->src, eh6->dst, IP_ESPPROTO, eh->spi, eh->spi+2);
+ eh6->vcf[1] = hash>>16;
+ eh6->vcf[2] = hash>>8;
+ eh6->vcf[3] = hash;
}
/* compute secure hash */
--- a/sys/src/9/ip/ipaux.c
+++ b/sys/src/9/ip/ipaux.c
@@ -578,3 +578,38 @@
csum = (csum & 0xFFFF) + v;
hnputs(pcsum, csum^0xFFFF);
}
+
+#define FNV_INIT 0x811c9dc5
+#define FNV_PRIME 0x01000193
+
+static uint fnv(uchar *v, int l, uint h)
+{
+ int i;
+
+ for(i = 0; i < l; i++){
+ h ^= (uint) v[i];
+ h *= FNV_PRIME;
+ }
+
+ return h;
+}
+
+/*
+ * Compute ipv6 flowhash withe the fnv-1a hash function
+ */
+uint flowhash6(uchar *s, uchar *d, uchar p, uchar *sp, uchar *dp)
+{
+ uint h;
+
+ h = FNV_INIT;
+
+ h = fnv(s, IPaddrlen, h);
+ h = fnv(d, IPaddrlen, h);
+ h = fnv(&p, 1, h);
+ h = fnv(sp, 2, h);
+ h = fnv(dp, 2, h);
+
+ h = (h >> 20) ^ (h & 0x0fffff);
+
+ return h;
+}
\ No newline at end of file
--- a/sys/src/9/ip/ipv6.c
+++ b/sys/src/9/ip/ipv6.c
@@ -97,7 +97,7 @@
} else {
eh->vcf[0] = IP_VER6;
eh->vcf[0] |= tos >> 4;
- eh->vcf[1] = tos << 4;
+ eh->vcf[1] |= tos << 4;
}
eh->ttl = ttl;
--- a/sys/src/9/ip/ipv6.h
+++ b/sys/src/9/ip/ipv6.h
@@ -164,6 +164,7 @@
extern int v6aNpreflen;
extern int v6aLpreflen;
+uint flowhash6(uchar *, uchar *, uchar, uchar *, uchar *);
void ipv62smcast(uchar *, uchar *);
void icmpns6(Fs *f, uchar* src, int suni, uchar* targ, int tuni, uchar* mac, int maclen);
void icmpna6(Fs *f, uchar* src, uchar* dst, uchar* targ, uchar* mac, int maclen, uchar flags);
--- a/sys/src/9/ip/tcp.c
+++ b/sys/src/9/ip/tcp.c
@@ -6,6 +6,7 @@
#include "../port/error.h"
#include "ip.h"
+#include "ipv6.h"
enum
{
@@ -1025,6 +1026,7 @@
ushort csum;
ushort hdrlen, optpad = 0;
uchar *opt;
+ uint hash;
hdrlen = TCP6_HDRSIZE;
if(tcph->flags & SYN){
@@ -1090,7 +1092,11 @@
/* move from pseudo header back to normal ip header */
memset(h->vcf, 0, 4);
+ hash = flowhash6(h->tcpsrc, h->tcpdst, IP_TCPPROTO, h->tcpsport, h->tcpdport);
h->vcf[0] = IP_VER6;
+ h->vcf[1] = hash>>16;
+ h->vcf[2] = hash>>8;
+ h->vcf[3] = hash;
hnputs(h->ploadlen, hdrlen+dlen);
h->proto = ph->proto;
--- a/sys/src/9/ip/udp.c
+++ b/sys/src/9/ip/udp.c
@@ -193,6 +193,7 @@
int version;
Routehint *rh;
ushort csum;
+ uint hash;
upriv = c->p->priv;
f = c->p->f;
@@ -313,7 +314,11 @@
csum = 0xffff; /* -0 */
hnputs(uh6->udpcksum, csum);
memset(uh6, 0, 8);
+ hash = flowhash6(uh6->udpsrc, uh6->udpdst, IP_UDPPROTO, uh6->udpsport, uh6->udpdport);
uh6->viclfl[0] = IP_VER6;
+ uh6->viclfl[1] = hash>>16;
+ uh6->viclfl[2] = hash>>8;
+ uh6->viclfl[3] = hash;
hnputs(uh6->len, ptcllen);
uh6->nextheader = IP_UDPPROTO;
ipoput6(f, bp, nil, c->ttl, c->tos, rh);
--- a/sys/src/cmd/ip/snoopy/ip6.c
+++ b/sys/src/cmd/ip/snoopy/ip6.c
@@ -279,8 +279,8 @@
if(len < m->pe - m->ps)
m->pe = m->ps + len;
- m->p = seprint(m->p, m->e, "s=%I d=%I ttl=%3d pr=%d ln=%d",
- h->src, h->dst, h->ttl, h->proto, NetS(h->length));
+ m->p = seprint(m->p, m->e, "s=%I d=%I ttl=%3d pr=%d fl=%ux ln=%d",
+ h->src, h->dst, h->ttl, h->proto, Net3(h->vcf+1) & 0x0fffff, NetS(h->length));
v6hdr_seprint(m);
return 0;
}
next reply other threads:[~2023-11-25 18:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-25 18:27 Arne Meyer [this message]
2023-11-25 20:46 ` cinap_lenrek
2023-11-25 20:51 ` cinap_lenrek
2023-11-25 21:03 ` Arne Meyer
2023-11-25 21:05 ` cinap_lenrek
2023-11-25 21:49 ` Arne Meyer
2023-11-26 13:28 ` cinap_lenrek
2023-11-27 19:17 ` Arne Meyer
2023-11-26 16:51 ` ori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1375031432.2686734.1700936861177@comcenter.netcologne.de \
--to=meyer.arne83@netcologne.de \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).