From c55b861e599c10bfd4a721d8c874a74e15deb478 Mon Sep 17 00:00:00 2001 From: hellt Date: Fri, 29 Jan 2021 18:20:39 +0200 Subject: [PATCH 1/2] added disable-tx-offload cmd --- cmd/disableTxOffload.go | 62 ++++++++++++++++++++++++++++ cmd/tools.go | 16 +++++++ docs/cmd/tools/disable-tx-offload.md | 25 +++++++++++ mkdocs.yml | 2 + 4 files changed, 105 insertions(+) create mode 100644 cmd/disableTxOffload.go create mode 100644 cmd/tools.go create mode 100644 docs/cmd/tools/disable-tx-offload.md diff --git a/cmd/disableTxOffload.go b/cmd/disableTxOffload.go new file mode 100644 index 000000000..48c49f76d --- /dev/null +++ b/cmd/disableTxOffload.go @@ -0,0 +1,62 @@ +package cmd + +import ( + "context" + "strconv" + + "github.com/containernetworking/plugins/pkg/ns" + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "github.com/srl-wim/container-lab/clab" +) + +var cntName string + +// upgradeCmd represents the version command +var disableTxOffloadCmd = &cobra.Command{ + Use: "disable-tx-offload", + Short: "disables tx checksum offload on eth0 interface of a container", + + RunE: func(cmd *cobra.Command, args []string) error { + opts := []clab.ClabOption{ + clab.WithDebug(debug), + clab.WithTimeout(timeout), + clab.WithEnvDockerClient(), + } + c := clab.NewContainerLab(opts...) + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + cnt, err := c.DockerClient.ContainerInspect(ctx, cntName) + if err != nil { + return err + } + + log.Infof("getting container '%s' information", cntName) + NSPath := "/proc/" + strconv.Itoa(cnt.State.Pid) + "/ns/net" + nodeNS, err := ns.GetNS(NSPath) + if err != nil { + return err + } + err = nodeNS.Do(func(_ ns.NetNS) error { + // disabling offload on lo0 interface + err = clab.EthtoolTXOff("eth0") + if err != nil { + log.Infof("Failed to disable TX checksum offload for 'eth0' interface for '%s' container", c) + } + return nil + }) + if err != nil { + return err + } + log.Infof("Tx checksum offload disabled for eth0 interface of %s container", cntName) + return nil + }, +} + +func init() { + toolsCmd.AddCommand(disableTxOffloadCmd) + disableTxOffloadCmd.Flags().StringVarP(&cntName, "container", "c", "", "container name to disable offload in") + disableTxOffloadCmd.MarkFlagRequired("container") +} diff --git a/cmd/tools.go b/cmd/tools.go new file mode 100644 index 000000000..7f5ebc1fb --- /dev/null +++ b/cmd/tools.go @@ -0,0 +1,16 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +// toolsCmd represents the tools command +var toolsCmd = &cobra.Command{ + Use: "tools", + Short: "various tools your lab might need", + Long: "tools command groups various tools you might need for your lab\nreference: https://containerlab.srlinux.dev/cmd/tools/", +} + +func init() { + rootCmd.AddCommand(toolsCmd) +} diff --git a/docs/cmd/tools/disable-tx-offload.md b/docs/cmd/tools/disable-tx-offload.md new file mode 100644 index 000000000..e72f4c301 --- /dev/null +++ b/docs/cmd/tools/disable-tx-offload.md @@ -0,0 +1,25 @@ +# disable-tx-offload command + +### Description + +The `disable-tx-offload` command under the `tools` command disables tx checksum offload for `eth0` interface of a container referenced by its name. + +The need for `disable-tx-offload` might arise when you launch a container outside of containerlab or restart a container. Some nodes, like SR Linux, will require to have correct checksums in TCP packets, thus its needed to disable checksum offload on those containers for them to do checksum calculations instead of offloading it. + +### Usage + +`containerlab tools disable-tx-offload [local-flags]` + +### Flags + +#### container +With the local mandatory `--container | -c` flag a user specifies which container to remove tx offload in. + +### Examples + +```bash +# disable tx checksum on gnmic container +❯ clab tools disable-checksum -c clab-st-gnmic +INFO[0000] getting container 'clab-st-gnmic' information +INFO[0000] Tx checksum offload disabled for eth0 interface of clab-st-gnmic container +``` \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index b9f6b63a3..9cd895964 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -26,6 +26,8 @@ nav: - save: cmd/save.md - generate: cmd/generate.md - graph: cmd/graph.md + - tools: + - disable-tx-offload: cmd/tools/disable-tx-offload.md - Lab examples: - About: lab-examples/lab-examples.md - Single SR Linux node: lab-examples/single-srl.md From fae3e36b52b1e0c14d3f585d0db698aa6a2dc97c Mon Sep 17 00:00:00 2001 From: hellt Date: Fri, 29 Jan 2021 18:23:17 +0200 Subject: [PATCH 2/2] fix wrong var reference --- cmd/disableTxOffload.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/disableTxOffload.go b/cmd/disableTxOffload.go index 48c49f76d..34f7bedaa 100644 --- a/cmd/disableTxOffload.go +++ b/cmd/disableTxOffload.go @@ -43,7 +43,7 @@ var disableTxOffloadCmd = &cobra.Command{ // disabling offload on lo0 interface err = clab.EthtoolTXOff("eth0") if err != nil { - log.Infof("Failed to disable TX checksum offload for 'eth0' interface for '%s' container", c) + log.Infof("Failed to disable TX checksum offload for 'eth0' interface for '%s' container", cntName) } return nil })