Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 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 | #include <vlib/vlib.h> |
| 17 | #include <vnet/vnet.h> |
| 18 | #include <vppinfra/error.h> |
| 19 | #include <vnet/ethernet/ethernet.h> |
| 20 | #include <vnet/feature/feature.h> |
| 21 | #include <vnet/l2/l2_in_out_feat_arc.h> |
| 22 | #include <vnet/gso/gso.h> |
| 23 | |
| 24 | gso_main_t gso_main; |
| 25 | |
| 26 | int |
| 27 | vnet_sw_interface_gso_enable_disable (u32 sw_if_index, u8 enable) |
| 28 | { |
| 29 | ethernet_interface_t *eif; |
| 30 | vnet_sw_interface_t *si; |
| 31 | ethernet_main_t *em; |
| 32 | vnet_main_t *vnm; |
| 33 | |
| 34 | vnm = vnet_get_main (); |
| 35 | em = ðernet_main; |
| 36 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 37 | |
| 38 | /* |
| 39 | * only ethernet HW interfaces are supported at this time |
| 40 | */ |
| 41 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 42 | { |
| 43 | return (VNET_API_ERROR_INVALID_VALUE); |
| 44 | } |
| 45 | |
| 46 | eif = ethernet_get_interface (em, si->hw_if_index); |
| 47 | |
| 48 | if (!eif) |
| 49 | { |
| 50 | return (VNET_API_ERROR_FEATURE_DISABLED); |
| 51 | } |
| 52 | |
| 53 | vnet_feature_enable_disable ("ip4-output", "gso-ip4", sw_if_index, enable, |
| 54 | 0, 0); |
| 55 | vnet_feature_enable_disable ("ip6-output", "gso-ip6", sw_if_index, enable, |
| 56 | 0, 0); |
| 57 | |
| 58 | vnet_l2_feature_enable_disable ("l2-output-nonip", "gso-l2-nonip", |
| 59 | sw_if_index, enable, 0, 0); |
| 60 | vnet_l2_feature_enable_disable ("l2-output-ip4", "gso-l2-ip4", |
| 61 | sw_if_index, enable, 0, 0); |
| 62 | vnet_l2_feature_enable_disable ("l2-output-ip6", "gso-l2-ip6", |
| 63 | sw_if_index, enable, 0, 0); |
| 64 | |
| 65 | return (0); |
| 66 | } |
| 67 | |
| 68 | static clib_error_t * |
| 69 | gso_init (vlib_main_t * vm) |
| 70 | { |
| 71 | gso_main_t *gm = &gso_main; |
| 72 | |
| 73 | clib_memset (gm, 0, sizeof (gm[0])); |
| 74 | gm->vlib_main = vm; |
| 75 | gm->vnet_main = vnet_get_main (); |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | VLIB_INIT_FUNCTION (gso_init); |
| 81 | |
| 82 | /* |
| 83 | * fd.io coding-style-patch-verification: ON |
| 84 | * |
| 85 | * Local Variables: |
| 86 | * eval: (c-set-style "gnu") |
| 87 | * End: |
| 88 | */ |