github.com/opencontainers/runtime-tools@v0.9.0/generate/seccomp/parse_architecture.go (about) 1 package seccomp 2 3 import ( 4 "fmt" 5 6 rspec "github.com/opencontainers/runtime-spec/specs-go" 7 ) 8 9 // ParseArchitectureFlag takes the raw string passed with the --arch flag, parses it 10 // and updates the Seccomp config accordingly 11 func ParseArchitectureFlag(architectureArg string, config *rspec.LinuxSeccomp) error { 12 correctedArch, err := parseArch(architectureArg) 13 if err != nil { 14 return err 15 } 16 17 shouldAppend := true 18 for _, alreadySpecified := range config.Architectures { 19 if correctedArch == alreadySpecified { 20 shouldAppend = false 21 } 22 } 23 if shouldAppend { 24 config.Architectures = append(config.Architectures, correctedArch) 25 } 26 return nil 27 } 28 29 func parseArch(arch string) (rspec.Arch, error) { 30 arches := map[string]rspec.Arch{ 31 "x86": rspec.ArchX86, 32 "amd64": rspec.ArchX86_64, 33 "x32": rspec.ArchX32, 34 "arm": rspec.ArchARM, 35 "arm64": rspec.ArchAARCH64, 36 "mips": rspec.ArchMIPS, 37 "mips64": rspec.ArchMIPS64, 38 "mips64n32": rspec.ArchMIPS64N32, 39 "mipsel": rspec.ArchMIPSEL, 40 "mipsel64": rspec.ArchMIPSEL64, 41 "mipsel64n32": rspec.ArchMIPSEL64N32, 42 "parisc": rspec.ArchPARISC, 43 "parisc64": rspec.ArchPARISC64, 44 "ppc": rspec.ArchPPC, 45 "ppc64": rspec.ArchPPC64, 46 "ppc64le": rspec.ArchPPC64LE, 47 "s390": rspec.ArchS390, 48 "s390x": rspec.ArchS390X, 49 } 50 a, ok := arches[arch] 51 if !ok { 52 return "", fmt.Errorf("unrecognized architecture: %s", arch) 53 } 54 return a, nil 55 }