udp: Changes to udp_offload to support remote checksum offload
[deliverable/linux.git] / include / net / gue.h
CommitLineData
37dd0247
TH
1#ifndef __NET_GUE_H
2#define __NET_GUE_H
3
5024c33a
TH
4/* Definitions for the GUE header, standard and private flags, lengths
5 * of optional fields are below.
6 *
7 * Diagram of GUE header:
8 *
9 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
10 * |Ver|C| Hlen | Proto/ctype | Standard flags |P|
11 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
12 * | |
13 * ~ Fields (optional) ~
14 * | |
15 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
16 * | Private flags (optional, P bit is set) |
17 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
18 * | |
19 * ~ Private fields (optional) ~
20 * | |
21 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
22 *
23 * C bit indicates contol message when set, data message when unset.
24 * For a control message, proto/ctype is interpreted as a type of
25 * control message. For data messages, proto/ctype is the IP protocol
26 * of the next header.
27 *
28 * P bit indicates private flags field is present. The private flags
29 * may refer to options placed after this field.
30 */
31
37dd0247
TH
32struct guehdr {
33 union {
34 struct {
35#if defined(__LITTLE_ENDIAN_BITFIELD)
5024c33a
TH
36 __u8 hlen:5,
37 control:1,
38 version:2;
37dd0247 39#elif defined (__BIG_ENDIAN_BITFIELD)
5024c33a
TH
40 __u8 version:2,
41 control:1,
42 hlen:5;
37dd0247
TH
43#else
44#error "Please fix <asm/byteorder.h>"
45#endif
5024c33a 46 __u8 proto_ctype;
37dd0247
TH
47 __u16 flags;
48 };
49 __u32 word;
50 };
51};
52
5024c33a
TH
53/* Standard flags in GUE header */
54
55#define GUE_FLAG_PRIV htons(1<<0) /* Private flags are in options */
56#define GUE_LEN_PRIV 4
57
58#define GUE_FLAGS_ALL (GUE_FLAG_PRIV)
59
60/* Private flags in the private option extension */
61
62#define GUE_PFLAGS_ALL (0)
63
64/* Functions to compute options length corresponding to flags.
65 * If we ever have a lot of flags this can be potentially be
66 * converted to a more optimized algorithm (table lookup
67 * for instance).
68 */
69static inline size_t guehdr_flags_len(__be16 flags)
70{
71 return ((flags & GUE_FLAG_PRIV) ? GUE_LEN_PRIV : 0);
72}
73
74static inline size_t guehdr_priv_flags_len(__be32 flags)
75{
76 return 0;
77}
78
79/* Validate standard and private flags. Returns non-zero (meaning invalid)
80 * if there is an unknown standard or private flags, or the options length for
81 * the flags exceeds the options length specific in hlen of the GUE header.
82 */
83static inline int validate_gue_flags(struct guehdr *guehdr,
84 size_t optlen)
85{
86 size_t len;
87 __be32 flags = guehdr->flags;
88
89 if (flags & ~GUE_FLAGS_ALL)
90 return 1;
91
92 len = guehdr_flags_len(flags);
93 if (len > optlen)
94 return 1;
95
96 if (flags & GUE_FLAG_PRIV) {
97 /* Private flags are last four bytes accounted in
98 * guehdr_flags_len
99 */
100 flags = *(__be32 *)((void *)&guehdr[1] + len - GUE_LEN_PRIV);
101
102 if (flags & ~GUE_PFLAGS_ALL)
103 return 1;
104
105 len += guehdr_priv_flags_len(flags);
106 if (len > optlen)
107 return 1;
108 }
109
110 return 0;
111}
112
37dd0247 113#endif
This page took 0.162486 seconds and 5 git commands to generate.