Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | /** |
| 16 | * @brief |
| 17 | * The data-path object representing dropping the packet |
| 18 | */ |
| 19 | |
| 20 | #include <vnet/dpo/dpo.h> |
| 21 | |
| 22 | static dpo_id_t drop_dpos[DPO_PROTO_NUM]; |
| 23 | |
| 24 | const dpo_id_t * |
| 25 | drop_dpo_get (dpo_proto_t proto) |
| 26 | { |
Neale Ranns | 8c1bebe | 2016-10-28 06:31:54 -0700 | [diff] [blame] | 27 | dpo_set(&drop_dpos[proto], DPO_DROP, proto, proto); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 28 | |
| 29 | return (&drop_dpos[proto]); |
| 30 | } |
| 31 | |
| 32 | int |
| 33 | dpo_is_drop (const dpo_id_t *dpo) |
| 34 | { |
| 35 | return (dpo->dpoi_type == DPO_DROP); |
| 36 | } |
| 37 | |
| 38 | static void |
| 39 | drop_dpo_lock (dpo_id_t *dpo) |
| 40 | { |
| 41 | /* |
| 42 | * not maintaining a lock count on the drop |
| 43 | * more trouble than it's worth. |
| 44 | * There always needs to be one around. no point it managaing its lifetime |
| 45 | */ |
| 46 | } |
| 47 | static void |
| 48 | drop_dpo_unlock (dpo_id_t *dpo) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | static u8* |
| 53 | format_drop_dpo (u8 *s, va_list *ap) |
| 54 | { |
Billy McFall | cfcf1e2 | 2016-10-14 09:51:49 -0400 | [diff] [blame] | 55 | CLIB_UNUSED(index_t index) = va_arg(*ap, index_t); |
| 56 | CLIB_UNUSED(u32 indent) = va_arg(*ap, u32); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 57 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 58 | return (format(s, "dpo-drop %U", format_dpo_proto, index)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | const static dpo_vft_t drop_vft = { |
| 62 | .dv_lock = drop_dpo_lock, |
| 63 | .dv_unlock = drop_dpo_unlock, |
| 64 | .dv_format = format_drop_dpo, |
| 65 | }; |
| 66 | |
| 67 | /** |
| 68 | * @brief The per-protocol VLIB graph nodes that are assigned to a drop |
| 69 | * object. |
| 70 | * |
| 71 | * this means that these graph nodes are ones from which a drop is the |
| 72 | * parent object in the DPO-graph. |
| 73 | */ |
| 74 | const static char* const drop_ip4_nodes[] = |
| 75 | { |
| 76 | "ip4-drop", |
| 77 | NULL, |
| 78 | }; |
| 79 | const static char* const drop_ip6_nodes[] = |
| 80 | { |
| 81 | "ip6-drop", |
| 82 | NULL, |
| 83 | }; |
| 84 | const static char* const drop_mpls_nodes[] = |
| 85 | { |
| 86 | "mpls-drop", |
| 87 | NULL, |
| 88 | }; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 89 | const static char* const drop_ethernet_nodes[] = |
| 90 | { |
| 91 | "error-drop", |
| 92 | NULL, |
| 93 | }; |
Florin Coras | b69111e | 2017-02-13 23:55:27 -0800 | [diff] [blame] | 94 | const static char* const drop_nsh_nodes[] = |
| 95 | { |
| 96 | "error-drop", |
| 97 | NULL, |
| 98 | }; |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame^] | 99 | const static char* const drop_bier_nodes[] = |
| 100 | { |
| 101 | "bier-drop", |
| 102 | NULL, |
| 103 | }; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 104 | const static char* const * const drop_nodes[DPO_PROTO_NUM] = |
| 105 | { |
| 106 | [DPO_PROTO_IP4] = drop_ip4_nodes, |
| 107 | [DPO_PROTO_IP6] = drop_ip6_nodes, |
| 108 | [DPO_PROTO_MPLS] = drop_mpls_nodes, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 109 | [DPO_PROTO_ETHERNET] = drop_ethernet_nodes, |
Florin Coras | b69111e | 2017-02-13 23:55:27 -0800 | [diff] [blame] | 110 | [DPO_PROTO_NSH] = drop_nsh_nodes, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame^] | 111 | [DPO_PROTO_BIER] = drop_bier_nodes, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | void |
| 115 | drop_dpo_module_init (void) |
| 116 | { |
| 117 | dpo_register(DPO_DROP, &drop_vft, drop_nodes); |
| 118 | } |