On 1/12/26 12:20 PM, Eelco Chaudron wrote:
> This patch adds the tc provider framework.
> 
> Acked-by: Eli Britstein <elibr.nvidia.com>
> Signed-off-by: Eelco Chaudron <[email protected]>
> ---
> 
> v3 changes:
>  - Use the actual variable to determine the size for xmalloc().
> ---
>  lib/automake.mk                  |  1 +
>  lib/dpif-offload-provider.h      |  2 ++
>  lib/dpif-offload-tc.c            | 47 ++++++++++++++++++++++++++++++++
>  lib/dpif-offload.c               |  3 ++
>  tests/system-offloads-traffic.at | 20 ++++++++++++++
>  5 files changed, 73 insertions(+)
>  create mode 100644 lib/dpif-offload-tc.c
> 
> diff --git a/lib/automake.mk b/lib/automake.mk
> index 314102ecc..6e015ebfc 100644
> --- a/lib/automake.mk
> +++ b/lib/automake.mk
> @@ -475,6 +475,7 @@ lib_libopenvswitch_la_SOURCES += \
>       lib/dpif-netlink.h \
>       lib/dpif-netlink-rtnl.c \
>       lib/dpif-netlink-rtnl.h \
> +     lib/dpif-offload-tc.c \
>       lib/if-notifier.c \
>       lib/netdev-linux.c \
>       lib/netdev-linux.h \
> diff --git a/lib/dpif-offload-provider.h b/lib/dpif-offload-provider.h
> index ca8b68574..301329b69 100644
> --- a/lib/dpif-offload-provider.h
> +++ b/lib/dpif-offload-provider.h
> @@ -17,6 +17,7 @@
>  #ifndef DPIF_OFFLOAD_PROVIDER_H
>  #define DPIF_OFFLOAD_PROVIDER_H
>  
> +#include "dpif-provider.h"
>  #include "ovs-thread.h"
>  
>  #include "openvswitch/list.h"
> @@ -89,6 +90,7 @@ struct dpif_offload_class {
>  
>  extern struct dpif_offload_class dpif_offload_dummy_class;
>  extern struct dpif_offload_class dpif_offload_dummy_x_class;
> +extern struct dpif_offload_class dpif_offload_tc_class;
>  
>  
>  /* Global function, called by the dpif layer. */
> diff --git a/lib/dpif-offload-tc.c b/lib/dpif-offload-tc.c
> new file mode 100644
> index 000000000..88efdaac8
> --- /dev/null
> +++ b/lib/dpif-offload-tc.c
> @@ -0,0 +1,47 @@
> +/*
> + * Copyright (c) 2025 Red Hat, Inc.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at:
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +#include <config.h>
> +
> +#include "dpif-offload.h"
> +#include "dpif-offload-provider.h"
> +#include "util.h"
> +
> +static int
> +dpif_offload_tc_open(const struct dpif_offload_class *offload_class,
> +                     struct dpif *dpif, struct dpif_offload **dpif_offload)
> +{
> +    struct dpif_offload *offload = xmalloc(sizeof *offload);
> +
> +    dpif_offload_init(offload, offload_class, dpif);
> +    *dpif_offload = offload;
> +    return 0;
> +}
> +
> +static void
> +dpif_offload_tc_close(struct dpif_offload *dpif_offload)
> +{
> +    free(dpif_offload);
> +}
> +
> +struct dpif_offload_class dpif_offload_tc_class = {
> +    .type = "tc",
> +    .supported_dpif_types = (const char *const[]) {
> +        "system",
> +        NULL},

nit: Single line, or '},' on a separate line.

> +    .open = dpif_offload_tc_open,
> +    .close = dpif_offload_tc_close,
> +};
> diff --git a/lib/dpif-offload.c b/lib/dpif-offload.c
> index e29df6d51..70748f789 100644
> --- a/lib/dpif-offload.c
> +++ b/lib/dpif-offload.c
> @@ -37,6 +37,9 @@ static struct shash dpif_offload_providers \
>      SHASH_INITIALIZER(&dpif_offload_providers);
>  
>  static const struct dpif_offload_class *base_dpif_offload_classes[] = {
> +#if defined(__linux__)
> +    &dpif_offload_tc_class,
> +#endif
>      &dpif_offload_dummy_class,
>      &dpif_offload_dummy_x_class,
>  };
> diff --git a/tests/system-offloads-traffic.at 
> b/tests/system-offloads-traffic.at
> index 492d5b689..894306385 100644
> --- a/tests/system-offloads-traffic.at
> +++ b/tests/system-offloads-traffic.at
> @@ -1166,3 +1166,23 @@ OVS_WAIT_WHILE(
>  
>  OVS_TRAFFIC_VSWITCHD_STOP
>  AT_CLEANUP
> +
> +AT_SETUP([offloads - ovs-appctl dpif/offload/show - offloads enabled])
> +AT_KEYWORDS([dpif-offload])
> +OVS_TRAFFIC_VSWITCHD_START([], [],
> +  [-- set Open_vSwitch . other_config:hw-offload=true])
> +
> +AT_CHECK([ovs-appctl dpif/offload/show], [0], [dnl
> +system@ovs-system:
> +  tc
> +])
> +
> +AT_CHECK([ovs-appctl --format json --pretty dpif/offload/show], [0], [dnl
> +{
> +  "system@ovs-system": {
> +    "providers": [[
> +      "tc"]]}}
> +])
> +
> +OVS_TRAFFIC_VSWITCHD_STOP
> +AT_CLEANUP

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to