2 * Copyright (c) 2014 VMware, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __PACKET_PARSER_H_
18 #define __PACKET_PARSER_H_ 1
23 const VOID* OvsGetPacketBytes(const NET_BUFFER_LIST *_pNB, UINT32 len,
24 UINT32 SrcOffset, VOID *storage);
25 NDIS_STATUS OvsParseIPv6(const NET_BUFFER_LIST *packet, OvsFlowKey *key,
26 POVS_PACKET_HDR_INFO layers);
27 VOID OvsParseTcp(const NET_BUFFER_LIST *packet, L4Key *flow,
28 POVS_PACKET_HDR_INFO layers);
29 VOID OvsParseUdp(const NET_BUFFER_LIST *packet, L4Key *flow,
30 POVS_PACKET_HDR_INFO layers);
31 NDIS_STATUS OvsParseIcmpV6(const NET_BUFFER_LIST *packet, OvsFlowKey *key,
32 POVS_PACKET_HDR_INFO layers);
35 OvsPacketLenNBL(const NET_BUFFER_LIST *_pNB)
40 nb = NET_BUFFER_LIST_FIRST_NB(_pNB);
43 length += NET_BUFFER_DATA_LENGTH(nb);
44 nb = NET_BUFFER_NEXT_NB(nb);
51 * Returns the ctl field from the TCP header in 'packet', or 0 if the field
52 * can't be read. The caller must have ensured that 'packet' contains a TCP
55 * We can't just use TCPHdr, from netProto.h, for this because that
56 * breaks the flags down into individual bit-fields. We can't even use
57 * offsetof because that will try to take the address of a bit-field,
58 * which C does not allow.
61 OvsGetTcpCtl(const NET_BUFFER_LIST *packet, // IN
62 const POVS_PACKET_HDR_INFO layers) // IN
64 #define TCP_CTL_OFS 12 // Offset of "ctl" field in TCP header.
65 #define TCP_FLAGS(CTL) ((CTL) & 0x3f) // Obtain TCP flags from CTL.
70 ctl = OvsGetPacketBytes(packet, sizeof *ctl, layers->l4Offset + TCP_CTL_OFS,
72 return ctl ? *ctl : 0;
77 OvsGetTcpFlags(const NET_BUFFER_LIST *packet, // IN
78 const POVS_PACKET_HDR_INFO layers) // IN
81 return TCP_FLAGS(OvsGetTcpCtl(packet, layers));
87 static const EtherArp *
88 OvsGetArp(const NET_BUFFER_LIST *packet,
92 return OvsGetPacketBytes(packet, sizeof *storage, ofs, storage);
96 OvsGetIp(const NET_BUFFER_LIST *packet,
100 const IPHdr *ip = OvsGetPacketBytes(packet, sizeof *ip, ofs, storage);
102 int ipLen = ip->ihl * 4;
103 if (ipLen >= sizeof *ip && OvsPacketLenNBL(packet) >= ofs + ipLen) {
110 static const TCPHdr *
111 OvsGetTcp(const NET_BUFFER_LIST *packet,
115 const TCPHdr *tcp = OvsGetPacketBytes(packet, sizeof *tcp, ofs, storage);
117 int tcpLen = tcp->doff * 4;
118 if (tcpLen >= sizeof *tcp && OvsPacketLenNBL(packet) >= ofs + tcpLen) {
125 static const UDPHdr *
126 OvsGetUdp(const NET_BUFFER_LIST *packet,
130 return OvsGetPacketBytes(packet, sizeof *storage, ofs, storage);
133 static const ICMPHdr *
134 OvsGetIcmp(const NET_BUFFER_LIST *packet,
138 return OvsGetPacketBytes(packet, sizeof *storage, ofs, storage);
141 #endif /* __PACKET_PARSER_H_ */