/src/wpantund/src/util/IPv6PacketMatcher.h
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * Copyright (c) 2016 Nest Labs, Inc. |
4 | | * All rights reserved. |
5 | | * |
6 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | | * you may not use this file except in compliance with the License. |
8 | | * You may obtain a copy of the License at |
9 | | * |
10 | | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | | * |
12 | | * Unless required by applicable law or agreed to in writing, software |
13 | | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | | * See the License for the specific language governing permissions and |
16 | | * limitations under the License. |
17 | | * |
18 | | */ |
19 | | |
20 | | #ifndef __wpantund__IPv6PacketMatcherRule__ |
21 | | #define __wpantund__IPv6PacketMatcherRule__ |
22 | | |
23 | | #include <stdint.h> |
24 | | #include <arpa/inet.h> |
25 | | #include <string.h> |
26 | | #include <set> |
27 | | #include "IPv6Helpers.h" |
28 | | |
29 | | |
30 | | namespace nl { |
31 | | |
32 | | void dump_outbound_ipv6_packet(const uint8_t* packet, ssize_t len, const char* extra, bool dropped = false); |
33 | | void dump_inbound_ipv6_packet(const uint8_t* packet, ssize_t len, const char* extra, bool dropped = false); |
34 | | |
35 | | struct IPv6PacketMatcherRule { |
36 | | static const uint8_t TYPE_ALL; |
37 | | static const uint8_t TYPE_NONE; |
38 | | static const uint8_t TYPE_UDP; |
39 | | static const uint8_t TYPE_TCP; |
40 | | static const uint8_t TYPE_ICMP; |
41 | | static const uint8_t TYPE_HOP_BY_HOP; |
42 | | static const uint8_t SUBTYPE_ALL; |
43 | | static const uint8_t SUBTYPE_ICMP_NEIGHBOR_ADV; |
44 | | static const uint8_t SUBTYPE_ICMP_NEIGHBOR_SOL; |
45 | | static const uint8_t SUBTYPE_ICMP_ROUTER_ADV; |
46 | | static const uint8_t SUBTYPE_ICMP_ROUTER_SOL; |
47 | | static const uint8_t SUBTYPE_ICMP_REDIRECT; |
48 | | |
49 | | uint8_t type; |
50 | | uint8_t subtype; |
51 | | in_port_t local_port; |
52 | | bool local_port_match; |
53 | | struct in6_addr local_address; |
54 | | uint8_t local_match_mask; |
55 | | |
56 | | in_port_t remote_port; |
57 | | bool remote_port_match; |
58 | | struct in6_addr remote_address; |
59 | | uint8_t remote_match_mask; |
60 | | |
61 | | void clear(); |
62 | | IPv6PacketMatcherRule& update_from_inbound_packet(const uint8_t* packet); |
63 | | bool match_inbound(const uint8_t* packet) const; |
64 | | IPv6PacketMatcherRule& update_from_outbound_packet(const uint8_t* packet); |
65 | | bool match_outbound(const uint8_t* packet) const; |
66 | | bool operator==(const IPv6PacketMatcherRule& lhs) const; |
67 | | bool operator<(const IPv6PacketMatcherRule& lhs) const; |
68 | | |
69 | 0 | bool operator!=(const IPv6PacketMatcherRule& lhs) const { return !(*this == lhs); } |
70 | 0 | bool operator>=(const IPv6PacketMatcherRule& lhs) const { return !(*this < lhs); } |
71 | | |
72 | 0 | bool operator<=(const IPv6PacketMatcherRule& lhs) const { return (*this < lhs) || (*this == lhs); } |
73 | 0 | bool operator>(const IPv6PacketMatcherRule& lhs) const { return !(*this <= lhs); } |
74 | | }; |
75 | | |
76 | | class IPv6PacketMatcher : public std::set<IPv6PacketMatcherRule> { |
77 | | public: |
78 | | |
79 | | const_iterator match_outbound(const uint8_t* packet) const; |
80 | | const_iterator match_inbound(const uint8_t* packet) const; |
81 | | }; |
82 | | |
83 | | }; // namespace nl |
84 | | |
85 | | #endif /* defined(__wpantund__IPv6PacketMatcherRule__) */ |