Neale Ranns | 59ff918 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * tunnel.h: shared definitions for tunnels. |
| 3 | * |
| 4 | * Copyright (c) 2019 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <vnet/tunnel/tunnel.h> |
| 19 | |
| 20 | u8 * |
| 21 | format_tunnel_mode (u8 * s, va_list * args) |
| 22 | { |
| 23 | tunnel_mode_t mode = va_arg (*args, int); |
| 24 | |
| 25 | switch (mode) |
| 26 | { |
| 27 | #define _(n, v) case TUNNEL_MODE_##n: \ |
| 28 | s = format (s, "%s", v); \ |
| 29 | break; |
| 30 | foreach_tunnel_mode |
| 31 | #undef _ |
| 32 | } |
| 33 | |
| 34 | return (s); |
| 35 | } |
| 36 | |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 37 | uword |
| 38 | unformat_tunnel_mode (unformat_input_t * input, va_list * args) |
| 39 | { |
| 40 | tunnel_mode_t *m = va_arg (*args, tunnel_mode_t *); |
| 41 | |
| 42 | if (unformat (input, "p2p")) |
| 43 | *m = TUNNEL_MODE_P2P; |
| 44 | else if (unformat (input, "p2mp") || unformat (input, "mp")) |
| 45 | *m = TUNNEL_MODE_MP; |
| 46 | else |
| 47 | return 0; |
| 48 | return 1; |
| 49 | } |
| 50 | |
Neale Ranns | 59ff918 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 51 | u8 * |
| 52 | format_tunnel_encap_decap_flags (u8 * s, va_list * args) |
| 53 | { |
| 54 | tunnel_encap_decap_flags_t f = va_arg (*args, int); |
| 55 | |
| 56 | if (f == TUNNEL_ENCAP_DECAP_FLAG_NONE) |
| 57 | return (format (s, "none")); |
| 58 | |
| 59 | #define _(a,b,c) if (f & TUNNEL_ENCAP_DECAP_FLAG_##a) s = format(s, "%s ", b); |
| 60 | forech_tunnel_encap_decap_flag |
| 61 | #undef _ |
| 62 | return (s); |
| 63 | } |
| 64 | |
Mohammed Hawari | 59b792f | 2020-12-01 11:30:57 +0100 | [diff] [blame] | 65 | uword |
| 66 | unformat_tunnel_encap_decap_flags (unformat_input_t * input, va_list * args) |
| 67 | { |
| 68 | tunnel_encap_decap_flags_t *f = |
| 69 | va_arg (*args, tunnel_encap_decap_flags_t *); |
| 70 | #define _(a,b,c) if (unformat(input, b)) {\ |
| 71 | *f |= TUNNEL_ENCAP_DECAP_FLAG_##a;\ |
| 72 | return 1;\ |
| 73 | } |
| 74 | forech_tunnel_encap_decap_flag; |
| 75 | #undef _ |
| 76 | return 0; |
| 77 | } |
| 78 | |
Neale Ranns | 59ff918 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * fd.io coding-style-patch-verification: ON |
| 82 | * |
| 83 | * Local Variables: |
| 84 | * eval: (c-set-style "gnu") |
| 85 | * End: |
| 86 | */ |