Skip to content

Commit

Permalink
update based on latest spec
Browse files Browse the repository at this point in the history
Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
  • Loading branch information
Ma Shimiao committed Nov 14, 2016
1 parent fb5caf5 commit bc4a30a
Show file tree
Hide file tree
Showing 10 changed files with 430 additions and 430 deletions.
8 changes: 4 additions & 4 deletions cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ func validateOOMScoreAdj(spec *rspec.Spec) error {
return nil
}

func getIDMappings(path string) ([]rspec.IDMapping, error) {
var idMaps []rspec.IDMapping
func getIDMappings(path string) ([]rspec.LinuxIDMapping, error) {
var idMaps []rspec.LinuxIDMapping
f, err := os.Open(path)
if err != nil {
return nil, err
Expand All @@ -446,7 +446,7 @@ func getIDMappings(path string) ([]rspec.IDMapping, error) {
if err != nil {
return nil, err
}
idMaps = append(idMaps, rspec.IDMapping{HostID: uint32(hostID), ContainerID: uint32(containerID), Size: uint32(mapSize)})
idMaps = append(idMaps, rspec.LinuxIDMapping{HostID: uint32(hostID), ContainerID: uint32(containerID), Size: uint32(mapSize)})
} else {
return nil, fmt.Errorf("invalid format in %v", path)
}
Expand All @@ -455,7 +455,7 @@ func getIDMappings(path string) ([]rspec.IDMapping, error) {
return idMaps, nil
}

func validateIDMappings(mappings []rspec.IDMapping, path string, property string) error {
func validateIDMappings(mappings []rspec.LinuxIDMapping, path string, property string) error {
idMaps, err := getIDMappings(path)
if err != nil {
return fmt.Errorf("can not get items: %v", err)
Expand Down
40 changes: 20 additions & 20 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func New() Generator {
"CAP_KILL",
"CAP_AUDIT_WRITE",
},
Rlimits: []rspec.Rlimit{
Rlimits: []rspec.LinuxRlimit{
{
Type: "RLIMIT_NOFILE",
Hard: uint64(1024),
Expand Down Expand Up @@ -117,15 +117,15 @@ func New() Generator {
},
},
Linux: &rspec.Linux{
Resources: &rspec.Resources{
Devices: []rspec.DeviceCgroup{
Resources: &rspec.LinuxResources{
Devices: []rspec.LinuxDeviceCgroup{
{
Allow: false,
Access: strPtr("rwm"),
},
},
},
Namespaces: []rspec.Namespace{
Namespaces: []rspec.LinuxNamespace{
{
Type: "pid",
},
Expand All @@ -142,7 +142,7 @@ func New() Generator {
Type: "mount",
},
},
Devices: []rspec.Device{},
Devices: []rspec.LinuxDevice{},
},
}
spec.Linux.Seccomp = seccomp.DefaultProfile(&spec)
Expand Down Expand Up @@ -467,7 +467,7 @@ func (g *Generator) SetLinuxResourcesMemorySwappiness(swappiness uint64) {
// SetLinuxResourcesPidsLimit sets g.spec.Linux.Resources.Pids.Limit.
func (g *Generator) SetLinuxResourcesPidsLimit(limit int64) {
g.initSpecLinuxResourcesPids()
g.spec.Linux.Resources.Pids.Limit = &limit
g.spec.Linux.Resources.Pids.Limit = limit
}

// ClearLinuxSysctl clears g.spec.Linux.Sysctl.
Expand Down Expand Up @@ -497,12 +497,12 @@ func (g *Generator) ClearLinuxUIDMappings() {
if g.spec == nil || g.spec.Linux == nil {
return
}
g.spec.Linux.UIDMappings = []rspec.IDMapping{}
g.spec.Linux.UIDMappings = []rspec.LinuxIDMapping{}
}

// AddLinuxUIDMapping adds uidMap into g.spec.Linux.UIDMappings.
func (g *Generator) AddLinuxUIDMapping(hid, cid, size uint32) {
idMapping := rspec.IDMapping{
idMapping := rspec.LinuxIDMapping{
HostID: hid,
ContainerID: cid,
Size: size,
Expand All @@ -517,12 +517,12 @@ func (g *Generator) ClearLinuxGIDMappings() {
if g.spec == nil || g.spec.Linux == nil {
return
}
g.spec.Linux.GIDMappings = []rspec.IDMapping{}
g.spec.Linux.GIDMappings = []rspec.LinuxIDMapping{}
}

// AddLinuxGIDMapping adds gidMap into g.spec.Linux.GIDMappings.
func (g *Generator) AddLinuxGIDMapping(hid, cid, size uint32) {
idMapping := rspec.IDMapping{
idMapping := rspec.LinuxIDMapping{
HostID: hid,
ContainerID: cid,
Size: size,
Expand Down Expand Up @@ -756,24 +756,24 @@ func (g *Generator) DropProcessCapability(c string) error {
return nil
}

func mapStrToNamespace(ns string, path string) (rspec.Namespace, error) {
func mapStrToNamespace(ns string, path string) (rspec.LinuxNamespace, error) {
switch ns {
case "network":
return rspec.Namespace{Type: rspec.NetworkNamespace, Path: path}, nil
return rspec.LinuxNamespace{Type: rspec.NetworkNamespace, Path: path}, nil
case "pid":
return rspec.Namespace{Type: rspec.PIDNamespace, Path: path}, nil
return rspec.LinuxNamespace{Type: rspec.PIDNamespace, Path: path}, nil
case "mount":
return rspec.Namespace{Type: rspec.MountNamespace, Path: path}, nil
return rspec.LinuxNamespace{Type: rspec.MountNamespace, Path: path}, nil
case "ipc":
return rspec.Namespace{Type: rspec.IPCNamespace, Path: path}, nil
return rspec.LinuxNamespace{Type: rspec.IPCNamespace, Path: path}, nil
case "uts":
return rspec.Namespace{Type: rspec.UTSNamespace, Path: path}, nil
return rspec.LinuxNamespace{Type: rspec.UTSNamespace, Path: path}, nil
case "user":
return rspec.Namespace{Type: rspec.UserNamespace, Path: path}, nil
return rspec.LinuxNamespace{Type: rspec.UserNamespace, Path: path}, nil
case "cgroup":
return rspec.Namespace{Type: rspec.CgroupNamespace, Path: path}, nil
return rspec.LinuxNamespace{Type: rspec.CgroupNamespace, Path: path}, nil
default:
return rspec.Namespace{}, fmt.Errorf("Should not reach here!")
return rspec.LinuxNamespace{}, fmt.Errorf("Should not reach here!")
}
}

Expand All @@ -782,7 +782,7 @@ func (g *Generator) ClearLinuxNamespaces() {
if g.spec == nil || g.spec.Linux == nil {
return
}
g.spec.Linux.Namespaces = []rspec.Namespace{}
g.spec.Linux.Namespaces = []rspec.LinuxNamespace{}
}

// AddOrReplaceLinuxNamespace adds or replaces a namespace inside
Expand Down
16 changes: 8 additions & 8 deletions generate/seccomp/parse_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type SyscallOpts struct {

// ParseSyscallFlag takes a SyscallOpts struct and the seccomp configuration
// and sets the new syscall rule accordingly
func ParseSyscallFlag(args SyscallOpts, config *rspec.Seccomp) error {
func ParseSyscallFlag(args SyscallOpts, config *rspec.LinuxSeccomp) error {
var arguments []string
if args.Index != "" && args.Value != "" && args.ValueTwo != "" && args.Operator != "" {
arguments = []string{args.Action, args.Syscall, args.Index, args.Value,
Expand All @@ -34,7 +34,7 @@ func ParseSyscallFlag(args SyscallOpts, config *rspec.Seccomp) error {
return fmt.Errorf("default action already set as %s", action)
}

var newSyscall rspec.Syscall
var newSyscall rspec.LinuxSyscall
numOfArgs := len(arguments)
if numOfArgs == 6 || numOfArgs == 2 {
argStruct, err := parseArguments(arguments[1:])
Expand Down Expand Up @@ -67,7 +67,7 @@ func ParseSyscallFlag(args SyscallOpts, config *rspec.Seccomp) error {
return nil
}

var actions = map[string]rspec.Action{
var actions = map[string]rspec.LinuxSeccompAction{
"allow": rspec.ActAllow,
"errno": rspec.ActErrno,
"kill": rspec.ActKill,
Expand All @@ -76,7 +76,7 @@ var actions = map[string]rspec.Action{
}

// Take passed action, return the SCMP_ACT_<ACTION> version of it
func parseAction(action string) (rspec.Action, error) {
func parseAction(action string) (rspec.LinuxSeccompAction, error) {
a, ok := actions[action]
if !ok {
return "", fmt.Errorf("unrecognized action: %s", action)
Expand All @@ -86,7 +86,7 @@ func parseAction(action string) (rspec.Action, error) {

// ParseDefaultAction sets the default action of the seccomp configuration
// and then removes any rules that were already specified with this action
func ParseDefaultAction(action string, config *rspec.Seccomp) error {
func ParseDefaultAction(action string, config *rspec.LinuxSeccomp) error {
if action == "" {
return nil
}
Expand All @@ -104,7 +104,7 @@ func ParseDefaultAction(action string, config *rspec.Seccomp) error {
}

// ParseDefaultActionForce simply sets the default action of the seccomp configuration
func ParseDefaultActionForce(action string, config *rspec.Seccomp) error {
func ParseDefaultActionForce(action string, config *rspec.LinuxSeccomp) error {
if action == "" {
return nil
}
Expand All @@ -117,8 +117,8 @@ func ParseDefaultActionForce(action string, config *rspec.Seccomp) error {
return nil
}

func newSyscallStruct(name string, action rspec.Action, args []rspec.Arg) rspec.Syscall {
syscallStruct := rspec.Syscall{
func newSyscallStruct(name string, action rspec.LinuxSeccompAction, args []rspec.LinuxSeccompArg) rspec.LinuxSyscall {
syscallStruct := rspec.LinuxSyscall{
Name: name,
Action: action,
Args: args,
Expand Down
2 changes: 1 addition & 1 deletion generate/seccomp/parse_architecture.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// ParseArchitectureFlag takes the raw string passed with the --arch flag, parses it
// and updates the Seccomp config accordingly
func ParseArchitectureFlag(architectureArg string, config *rspec.Seccomp) error {
func ParseArchitectureFlag(architectureArg string, config *rspec.LinuxSeccomp) error {
correctedArch, err := parseArch(architectureArg)
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions generate/seccomp/parse_arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

// parseArguments takes a list of arguments (delimArgs). It parses and fills out
// the argument information and returns a slice of arg structs
func parseArguments(delimArgs []string) ([]rspec.Arg, error) {
nilArgSlice := []rspec.Arg{}
func parseArguments(delimArgs []string) ([]rspec.LinuxSeccompArg, error) {
nilArgSlice := []rspec.LinuxSeccompArg{}
numberOfArgs := len(delimArgs)

// No parameters passed with syscall
Expand Down Expand Up @@ -40,23 +40,23 @@ func parseArguments(delimArgs []string) ([]rspec.Arg, error) {
return nilArgSlice, err
}

argStruct := rspec.Arg{
argStruct := rspec.LinuxSeccompArg{
Index: uint(syscallIndex),
Value: syscallValue,
ValueTwo: syscallValueTwo,
Op: syscallOp,
}

argSlice := []rspec.Arg{}
argSlice := []rspec.LinuxSeccompArg{}
argSlice = append(argSlice, argStruct)
return argSlice, nil
}

return nilArgSlice, fmt.Errorf("incorrect number of arguments passed with syscall: %d", numberOfArgs)
}

func parseOperator(operator string) (rspec.Operator, error) {
operators := map[string]rspec.Operator{
func parseOperator(operator string) (rspec.LinuxSeccompOperator, error) {
operators := map[string]rspec.LinuxSeccompOperator{
"NE": rspec.OpNotEqual,
"LT": rspec.OpLessThan,
"LE": rspec.OpLessEqual,
Expand Down
8 changes: 4 additions & 4 deletions generate/seccomp/parse_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// RemoveAction takes the argument string that was passed with the --remove flag,
// parses it, and updates the Seccomp config accordingly
func RemoveAction(arguments string, config *rspec.Seccomp) error {
func RemoveAction(arguments string, config *rspec.LinuxSeccomp) error {
if config == nil {
return fmt.Errorf("Cannot remove action from nil Seccomp pointer")
}
Expand All @@ -33,17 +33,17 @@ func RemoveAction(arguments string, config *rspec.Seccomp) error {
}

// RemoveAllSeccompRules removes all seccomp syscall rules
func RemoveAllSeccompRules(config *rspec.Seccomp) error {
func RemoveAllSeccompRules(config *rspec.LinuxSeccomp) error {
if config == nil {
return fmt.Errorf("Cannot remove action from nil Seccomp pointer")
}
newSyscallSlice := []rspec.Syscall{}
newSyscallSlice := []rspec.LinuxSyscall{}
config.Syscalls = newSyscallSlice
return nil
}

// RemoveAllMatchingRules will remove any syscall rules that match the specified action
func RemoveAllMatchingRules(config *rspec.Seccomp, action string) error {
func RemoveAllMatchingRules(config *rspec.LinuxSeccomp, action string) error {
if config == nil {
return fmt.Errorf("Cannot remove action from nil Seccomp pointer")
}
Expand Down
Loading

0 comments on commit bc4a30a

Please sign in to comment.