github.com/geofffranks/garden-linux@v0.0.0-20160715111146-26c893169cfa/sysconfig/config.go (about) 1 package sysconfig 2 3 import ( 4 "fmt" 5 "strconv" 6 "strings" 7 8 "code.cloudfoundry.org/garden-linux/process" 9 ) 10 11 type Config struct { 12 CgroupPath string 13 CgroupNodeFilePath string 14 NetworkInterfacePrefix string 15 IPTables IPTablesConfig 16 Tag string 17 DNSServers []string 18 } 19 20 type IPTablesConfig struct { 21 Filter IPTablesFilterConfig 22 NAT IPTablesNATConfig 23 } 24 25 type IPTablesFilterConfig struct { 26 AllowHostAccess bool 27 InputChain string 28 ForwardChain string 29 DefaultChain string 30 InstancePrefix string 31 } 32 33 type IPTablesNATConfig struct { 34 PreroutingChain string 35 PostroutingChain string 36 InstancePrefix string 37 } 38 39 func NewConfig(tag string, allowHostAccess bool, dnsServers []string) Config { 40 return Config{ 41 NetworkInterfacePrefix: fmt.Sprintf("w%s", tag), 42 Tag: tag, 43 DNSServers: dnsServers, 44 45 CgroupPath: fmt.Sprintf("/tmp/garden-%s/cgroup", tag), 46 CgroupNodeFilePath: "/proc/self/cgroup", 47 48 IPTables: IPTablesConfig{ 49 Filter: IPTablesFilterConfig{ 50 AllowHostAccess: allowHostAccess, 51 InputChain: fmt.Sprintf("w-%s-input", tag), 52 ForwardChain: fmt.Sprintf("w-%s-forward", tag), 53 DefaultChain: fmt.Sprintf("w-%s-default", tag), 54 InstancePrefix: fmt.Sprintf("w-%s-instance-", tag), 55 }, 56 NAT: IPTablesNATConfig{ 57 PreroutingChain: fmt.Sprintf("w-%s-prerouting", tag), 58 PostroutingChain: fmt.Sprintf("w-%s-postrouting", tag), 59 InstancePrefix: fmt.Sprintf("w-%s-instance-", tag), 60 }, 61 }, 62 } 63 } 64 65 func (config Config) Environ() process.Env { 66 return process.Env{ 67 "GARDEN_CGROUP_PATH": config.CgroupPath, 68 69 "GARDEN_NETWORK_INTERFACE_PREFIX": config.NetworkInterfacePrefix, 70 "GARDEN_TAG": config.Tag, 71 "GARDEN_DNS_SERVERS": strings.Join(config.DNSServers, "\n"), 72 73 "GARDEN_IPTABLES_ALLOW_HOST_ACCESS": strconv.FormatBool(config.IPTables.Filter.AllowHostAccess), 74 "GARDEN_IPTABLES_FILTER_INPUT_CHAIN": config.IPTables.Filter.InputChain, 75 76 "GARDEN_IPTABLES_FILTER_FORWARD_CHAIN": config.IPTables.Filter.ForwardChain, 77 "GARDEN_IPTABLES_FILTER_DEFAULT_CHAIN": config.IPTables.Filter.DefaultChain, 78 "GARDEN_IPTABLES_FILTER_INSTANCE_PREFIX": config.IPTables.Filter.InstancePrefix, 79 80 "GARDEN_IPTABLES_NAT_PREROUTING_CHAIN": config.IPTables.NAT.PreroutingChain, 81 "GARDEN_IPTABLES_NAT_POSTROUTING_CHAIN": config.IPTables.NAT.PostroutingChain, 82 "GARDEN_IPTABLES_NAT_INSTANCE_PREFIX": config.IPTables.NAT.InstancePrefix, 83 } 84 }