Browse code

Merge remote-tracking branch 'shawnsi/iptables-wrapper'

Solomon Hykes authored on 2013/03/29 10:40:02
Showing 1 changed files
... ...
@@ -68,7 +68,11 @@ func networkSize(mask net.IPMask) (int32, error) {
68 68
 
69 69
 // Wrapper around the iptables command
70 70
 func iptables(args ...string) error {
71
-	if err := exec.Command("/sbin/iptables", args...).Run(); err != nil {
71
+	path, err := exec.LookPath("iptables")
72
+	if err != nil {
73
+		return fmt.Errorf("command not found: iptables")
74
+	}
75
+	if err := exec.Command(path, args...).Run(); err != nil {
72 76
 		return fmt.Errorf("iptables failed: iptables %v", strings.Join(args, " "))
73 77
 	}
74 78
 	return nil
... ...
@@ -120,13 +124,13 @@ func (mapper *PortMapper) cleanup() error {
120 120
 
121 121
 func (mapper *PortMapper) setup() error {
122 122
 	if err := iptables("-t", "nat", "-N", "DOCKER"); err != nil {
123
-		return errors.New("Unable to setup port networking: Failed to create DOCKER chain")
123
+		return fmt.Errorf("Failed to create DOCKER chain: %s", err)
124 124
 	}
125 125
 	if err := iptables("-t", "nat", "-A", "PREROUTING", "-j", "DOCKER"); err != nil {
126
-		return errors.New("Unable to setup port networking: Failed to inject docker in PREROUTING chain")
126
+		return fmt.Errorf("Failed to inject docker in PREROUTING chain: %s", err)
127 127
 	}
128 128
 	if err := iptables("-t", "nat", "-A", "OUTPUT", "-j", "DOCKER"); err != nil {
129
-		return errors.New("Unable to setup port networking: Failed to inject docker in OUTPUT chain")
129
+		return fmt.Errorf("Failed to inject docker in OUTPUT chain: %s", err)
130 130
 	}
131 131
 	return nil
132 132
 }