diff --git a/cmd/disableTxOffload.go b/cmd/disableTxOffload.go new file mode 100644 index 000000000..34f7bedaa --- /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", cntName) + } + 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