]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/netinet6/in6_rss.c
Store addresses instead of sockaddrs inside llentry.
[FreeBSD/FreeBSD.git] / sys / netinet6 / in6_rss.c
1 /*-
2  * Copyright (c) 2010-2011 Juniper Networks, Inc.
3  * All rights reserved.
4  *
5  * This software was developed by Robert N. M. Watson under contract
6  * to Juniper Networks, Inc.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #include <sys/cdefs.h>
31
32 __FBSDID("$FreeBSD$");
33
34 #include "opt_inet6.h"
35 #include "opt_pcbgroup.h"
36
37 #ifndef PCBGROUP
38 #error "options RSS depends on options PCBGROUP"
39 #endif
40
41 #include <sys/param.h>
42 #include <sys/mbuf.h>
43 #include <sys/socket.h>
44 #include <sys/priv.h>
45 #include <sys/kernel.h>
46 #include <sys/smp.h>
47 #include <sys/sysctl.h>
48 #include <sys/sbuf.h>
49
50 #include <net/if.h>
51 #include <net/if_var.h>
52 #include <net/netisr.h>
53 #include <net/rss_config.h>
54
55 #include <netinet/in.h>
56 #include <netinet/in_pcb.h>
57 #include <netinet6/in6_rss.h>
58 #include <netinet/in_var.h>
59
60 /* for software rss hash support */
61 #include <netinet/ip.h>
62 #include <netinet/tcp.h>
63 #include <netinet/udp.h>
64
65 /*
66  * Hash an IPv6 2-tuple.
67  */
68 uint32_t
69 rss_hash_ip6_2tuple(const struct in6_addr *src, const struct in6_addr *dst)
70 {
71         uint8_t data[sizeof(*src) + sizeof(*dst)];
72         u_int datalen;
73
74         datalen = 0;
75         bcopy(src, &data[datalen], sizeof(*src));
76         datalen += sizeof(*src);
77         bcopy(dst, &data[datalen], sizeof(*dst));
78         datalen += sizeof(*dst);
79         return (rss_hash(datalen, data));
80 }
81
82 /*
83  * Hash an IPv6 4-tuple.
84  */
85 uint32_t
86 rss_hash_ip6_4tuple(const struct in6_addr *src, u_short srcport,
87     const struct in6_addr *dst, u_short dstport)
88 {
89         uint8_t data[sizeof(*src) + sizeof(*dst) + sizeof(srcport) +
90             sizeof(dstport)];
91         u_int datalen;
92
93         datalen = 0;
94         bcopy(src, &data[datalen], sizeof(*src));
95         datalen += sizeof(*src);
96         bcopy(dst, &data[datalen], sizeof(*dst));
97         datalen += sizeof(*dst);
98         bcopy(&srcport, &data[datalen], sizeof(srcport));
99         datalen += sizeof(srcport);
100         bcopy(&dstport, &data[datalen], sizeof(dstport));
101         datalen += sizeof(dstport);
102         return (rss_hash(datalen, data));
103 }