Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-present Open Networking Foundation |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | #ifndef __LOOKUP__ |
| 18 | #define __LOOKUP__ |
| 19 | |
| 20 | control LookupMdInit (in parsed_headers_t hdr, |
| 21 | out lookup_metadata_t lkp_md) { |
| 22 | apply { |
| 23 | lkp_md.is_ipv4 = _FALSE; |
| 24 | lkp_md.ipv4_src = 0; |
| 25 | lkp_md.ipv4_dst = 0; |
| 26 | lkp_md.ip_proto = 0; |
| 27 | lkp_md.l4_sport = 0; |
| 28 | lkp_md.l4_dport = 0; |
| 29 | lkp_md.icmp_type = 0; |
| 30 | lkp_md.icmp_code = 0; |
| 31 | if (hdr.inner_ipv4.isValid()) { |
| 32 | lkp_md.is_ipv4 = true; |
| 33 | lkp_md.ipv4_src = hdr.inner_ipv4.src_addr; |
| 34 | lkp_md.ipv4_dst = hdr.inner_ipv4.dst_addr; |
| 35 | lkp_md.ip_proto = hdr.inner_ipv4.protocol; |
| 36 | if (hdr.inner_tcp.isValid()) { |
| 37 | lkp_md.l4_sport = hdr.inner_tcp.sport; |
| 38 | lkp_md.l4_dport = hdr.inner_tcp.dport; |
| 39 | } else if (hdr.inner_udp.isValid()) { |
| 40 | lkp_md.l4_sport = hdr.inner_udp.sport; |
| 41 | lkp_md.l4_dport = hdr.inner_udp.dport; |
| 42 | } else if (hdr.inner_icmp.isValid()) { |
| 43 | lkp_md.icmp_type = hdr.inner_icmp.icmp_type; |
| 44 | lkp_md.icmp_code = hdr.inner_icmp.icmp_code; |
| 45 | } |
| 46 | } else if (hdr.ipv4.isValid()) { |
| 47 | lkp_md.is_ipv4 = true; |
| 48 | lkp_md.ipv4_src = hdr.ipv4.src_addr; |
| 49 | lkp_md.ipv4_dst = hdr.ipv4.dst_addr; |
| 50 | lkp_md.ip_proto = hdr.ipv4.protocol; |
| 51 | if (hdr.tcp.isValid()) { |
| 52 | lkp_md.l4_sport = hdr.tcp.sport; |
| 53 | lkp_md.l4_dport = hdr.tcp.dport; |
| 54 | } else if (hdr.udp.isValid()) { |
| 55 | lkp_md.l4_sport = hdr.udp.sport; |
| 56 | lkp_md.l4_dport = hdr.udp.dport; |
| 57 | } else if (hdr.icmp.isValid()) { |
| 58 | lkp_md.icmp_type = hdr.icmp.icmp_type; |
| 59 | lkp_md.icmp_code = hdr.icmp.icmp_code; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | #endif |
| 66 | |