components/docker/patches/0001-Solaris-v1.10.3.patch
changeset 7795 92fb0e1622f7
parent 7480 aa7a775dd813
child 7919 1f1a5eef7925
equal deleted inserted replaced
7794:4953ab4958ad 7795:92fb0e1622f7
     1 From a3e044c4d94e66259008000a451578849b50b516 Mon Sep 17 00:00:00 2001
     1 From 1bf2c9d74d8e53335f4e36f66cd400f9dd0e8ac1 Mon Sep 17 00:00:00 2001
     2 From: Shreya Jain <[email protected]>
     2 From: Edward Pilatowicz <[email protected]>
     3 Date: Fri, 9 Dec 2016 13:30:07 -0800
     3 Date: Tue, 21 Mar 2017 22:27:52 -0700
     4 Subject: [PATCH] Solaris-v1.10.3
     4 Subject: [PATCH] Solaris-v1.10.3
     5 
     5 
     6 ---
       
     7  Dockerfile.solaris                                 |   26 +
       
     8  Makefile                                           |   35 +-
       
     9  api/client/run.go                                  |    1 +
       
    10  api/client/version.go                              |   20 -
       
    11  api/server/router/container/container_routes.go    |    7 +
       
    12  api/server/server_unix.go                          |    2 +-
       
    13  container/container_solaris.go                     |  650 ++++++++++++
       
    14  container/monitor.go                               |    9 +
       
    15  container/state_solaris.go                         |    9 +
       
    16  contrib/docker-device-tool/device_tool.go          |    2 +-
       
    17  contrib/httpserver/Dockerfile                      |    2 +-
       
    18  contrib/mkimage.sh                                 |   11 +
       
    19  contrib/mkimage/solaris                            |  120 +++
       
    20  daemon/commit.go                                   |   22 +-
       
    21  daemon/config.go                                   |    4 +
       
    22  daemon/config_solaris.go                           |   66 ++
       
    23  daemon/config_test.go                              |   30 +-
       
    24  daemon/container_operations_solaris.go             |  973 ++++++++++++++++++
       
    25  daemon/daemon.go                                   |    6 +-
       
    26  daemon/daemon_solaris.go                           |  576 +++++++++++
       
    27  daemon/daemon_test.go                              |    2 +
       
    28  daemon/daemon_unix_test.go                         |    2 +-
       
    29  daemon/daemon_unsupported.go                       |    2 +-
       
    30  daemon/daemonbuilder/builder_unix.go               |    2 +-
       
    31  daemon/debugtrap_unsupported.go                    |    2 +-
       
    32  daemon/exec_solaris.go                             |   18 +
       
    33  daemon/execdriver/driver_solaris.go                |   76 ++
       
    34  daemon/execdriver/driver_unix.go                   |    2 +-
       
    35  .../execdriver/execdrivers/execdrivers_solaris.go  |   13 +
       
    36  daemon/execdriver/zones/driver.go                  |  799 +++++++++++++++
       
    37  daemon/execdriver/zones/driver_unsupported.go      |   12 +
       
    38  .../execdriver/zones/driver_unsupported_nocgo.go   |   13 +
       
    39  daemon/graphdriver/driver_solaris.go               |    8 +
       
    40  daemon/graphdriver/driver_unsupported.go           |    2 +-
       
    41  daemon/graphdriver/graphtest/graphtest_unix.go     |    2 +-
       
    42  daemon/graphdriver/register/register_zfs.go        |    2 +-
       
    43  daemon/graphdriver/zfs/zfs.go                      |   47 +-
       
    44  daemon/graphdriver/zfs/zfs_freebsd.go              |   36 +
       
    45  daemon/graphdriver/zfs/zfs_linux.go                |   37 +
       
    46  daemon/graphdriver/zfs/zfs_solaris.go              |   95 ++
       
    47  daemon/graphdriver/zfs/zfs_unsupported.go          |    2 +-
       
    48  daemon/info.go                                     |    2 -
       
    49  daemon/inspect_solaris.go                          |   30 +
       
    50  daemon/inspect_unix.go                             |    2 +-
       
    51  daemon/list_unix.go                                |    2 +-
       
    52  daemon/network.go                                  |    7 +
       
    53  daemon/selinux_unsupported.go                      |    8 +
       
    54  daemon/start.go                                    |   16 +
       
    55  daemon/stats_collector_solaris.go                  |  537 ++++++++++
       
    56  daemon/stats_collector_unix.go                     |    2 +-
       
    57  daemon/stats_solaris.go                            |   84 ++
       
    58  docker/daemon_solaris.go                           |   58 ++
       
    59  docker/daemon_unix.go                              |    2 +-
       
    60  hack/.vendor-helpers.sh                            |    8 +-
       
    61  hack/make.sh                                       |   14 +-
       
    62  hack/make/.detect-daemon-osarch                    |   20 +-
       
    63  hack/make/.ensure-httpserver                       |    2 +-
       
    64  hack/make/.integration-daemon-setup                |    6 +-
       
    65  hack/make/.integration-daemon-start                |    9 +-
       
    66  integration-cli/docker_api_build_test.go           |    4 +-
       
    67  integration-cli/docker_api_events_test.go          |    4 +-
       
    68  integration-cli/docker_api_exec_test.go            |    6 +-
       
    69  integration-cli/docker_api_inspect_test.go         |   14 +-
       
    70  integration-cli/docker_api_volumes_test.go         |    4 +-
       
    71  integration-cli/docker_cli_attach_unix_test.go     |    2 +-
       
    72  integration-cli/docker_cli_authz_unix_test.go      |    2 +-
       
    73  integration-cli/docker_cli_build_test.go           |    2 +-
       
    74  integration-cli/docker_cli_build_unix_test.go      |    2 +-
       
    75  integration-cli/docker_cli_create_test.go          |    4 +-
       
    76  integration-cli/docker_cli_daemon_test.go          |   14 +
       
    77  integration-cli/docker_cli_events_test.go          |    4 +-
       
    78  integration-cli/docker_cli_events_unix_test.go     |   54 +-
       
    79  integration-cli/docker_cli_exec_unix_test.go       |    2 +-
       
    80  integration-cli/docker_cli_images_test.go          |    8 +-
       
    81  integration-cli/docker_cli_inspect_test.go         |   24 +-
       
    82  integration-cli/docker_cli_links_test.go           |    2 +
       
    83  integration-cli/docker_cli_links_unix_test.go      |    2 +-
       
    84  integration-cli/docker_cli_network_unix_test.go    |    2 +-
       
    85  integration-cli/docker_cli_ps_test.go              |   15 +-
       
    86  integration-cli/docker_cli_run_test.go             |  341 +++---
       
    87  integration-cli/docker_cli_run_unix_test.go        |   49 +-
       
    88  integration-cli/docker_cli_save_load_unix_test.go  |    2 +-
       
    89  .../docker_cli_start_volume_driver_unix_test.go    |   16 +-
       
    90  .../docker_cli_volume_driver_compat_unix_test.go   |    4 +-
       
    91  integration-cli/docker_cli_volume_test.go          |   12 +-
       
    92  integration-cli/docker_cli_wait_test.go            |    4 +-
       
    93  integration-cli/docker_test_vars.go                |    2 +-
       
    94  integration-cli/docker_utils.go                    |    2 +-
       
    95  integration-cli/test_vars_unix.go                  |    4 +-
       
    96  layer/layer_unix.go                                |    2 +-
       
    97  migrate/v1/migratev1_test.go                       |    2 +
       
    98  opts/hosts.go                                      |    3 -
       
    99  opts/hosts_solaris.go                              |   10 +
       
   100  opts/hosts_test.go                                 |    4 +-
       
   101  opts/hosts_unix.go                                 |    6 +-
       
   102  pkg/archive/archive_test.go                        |   38 +-
       
   103  pkg/archive/changes_test.go                        |   12 +-
       
   104  pkg/chrootarchive/archive_test.go                  |   54 +-
       
   105  pkg/chrootarchive/diff_unix.go                     |    1 -
       
   106  pkg/directory/directory_unix.go                    |    2 +-
       
   107  pkg/fileutils/fileutils_solaris.go                 |    7 +
       
   108  pkg/integration/utils_test.go                      |   11 +-
       
   109  pkg/mount/flags_solaris.go                         |   42 +
       
   110  pkg/mount/flags_unsupported.go                     |    2 +-
       
   111  pkg/mount/mount.go                                 |    3 +-
       
   112  pkg/mount/mount_test.go                            |    2 +
       
   113  pkg/mount/mounter_solaris.go                       |   33 +
       
   114  pkg/mount/mounter_unsupported.go                   |    2 +-
       
   115  pkg/mount/mountinfo_solaris.go                     |   35 +
       
   116  pkg/mount/mountinfo_unsupported.go                 |    2 +-
       
   117  pkg/parsers/kernel/uname_solaris.go                |   14 +
       
   118  pkg/parsers/kernel/uname_unsupported.go            |    2 +-
       
   119  .../operatingsystem/operatingsystem_solaris.go     |   33 +
       
   120  pkg/platform/architecture_solaris.go               |   16 +
       
   121  pkg/proxy/network_proxy_test.go                    |   40 +-
       
   122  pkg/reexec/command_solaris.go                      |   23 +
       
   123  pkg/reexec/command_unsupported.go                  |    2 +-
       
   124  pkg/signal/signal_solaris.go                       |   42 +
       
   125  pkg/signal/signal_unsupported.go                   |    2 +-
       
   126  pkg/sysinfo/sysinfo_solaris.go                     |  117 +++
       
   127  pkg/system/meminfo_solaris.go                      |  127 +++
       
   128  pkg/system/meminfo_unsupported.go                  |    2 +-
       
   129  pkg/system/stat_linux.go                           |   33 -
       
   130  pkg/system/stat_solaris.go                         |   20 +-
       
   131  pkg/system/stat_unix.go                            |   35 +
       
   132  pkg/system/stat_unsupported.go                     |    2 +-
       
   133  pkg/term/tc_other.go                               |    1 +
       
   134  pkg/term/tc_solaris_cgo.go                         |   60 ++
       
   135  pkg/term/term.go                                   |   22 -
       
   136  pkg/term/term_solaris.go                           |   39 +
       
   137  pkg/term/term_unix.go                              |   27 +
       
   138  registry/auth_test.go                              |    2 +
       
   139  registry/registry_mock_test.go                     |    2 +
       
   140  registry/registry_test.go                          |    2 +
       
   141  runconfig/hostconfig_solaris.go                    |   82 ++
       
   142  runconfig/hostconfig_unix.go                       |    1 +
       
   143  runconfig/opts/parse.go                            |    2 +
       
   144  .../github.com/Sirupsen/logrus/terminal_solaris.go |   15 +
       
   145  .../docker/engine-api/types/container/config.go    |    4 +
       
   146  .../engine-api/types/container/host_config.go      |    1 +
       
   147  .../github.com/docker/engine-api/types/types.go    |    2 -
       
   148  .../docker/go-connections/sockets/unix_socket.go   |    2 +-
       
   149  .../docker/libnetwork/default_gateway_solaris.go   |    7 +
       
   150  .../libnetwork/drivers/solaris/bridge/bridge.go    | 1084 ++++++++++++++++++++
       
   151  .../drivers/solaris/bridge/bridge_store.go         |  212 ++++
       
   152  .../libnetwork/drivers/solaris/bridge/errors.go    |  341 ++++++
       
   153  .../drivers/solaris/bridge/port_mapping.go         |  247 +++++
       
   154  .../docker/libnetwork/drivers_solaris.go           |   13 +
       
   155  .../docker/libnetwork/ipamutils/utils_solaris.go   |   92 ++
       
   156  vendor/src/github.com/docker/libnetwork/network.go |    2 -
       
   157  .../docker/libnetwork/osl/interface_solaris.go     |    6 +
       
   158  .../docker/libnetwork/osl/namespace_solaris.go     |   41 +
       
   159  .../docker/libnetwork/osl/namespace_unsupported.go |    2 +-
       
   160  .../docker/libnetwork/osl/neigh_solaris.go         |    6 +
       
   161  .../docker/libnetwork/osl/sandbox_unsupported.go   |    2 +-
       
   162  .../libnetwork/portallocator/portallocator.go      |   22 -
       
   163  .../portallocator/portallocator_linux.go           |   28 +
       
   164  .../portallocator/portallocator_solaris.go         |    5 +
       
   165  .../docker/libnetwork/portmapper/mapper.go         |  228 ----
       
   166  .../docker/libnetwork/portmapper/mapper_linux.go   |  228 ++++
       
   167  .../docker/libnetwork/portmapper/mapper_solaris.go |  150 +++
       
   168  .../docker/libnetwork/portmapper/mock_proxy.go     |   18 -
       
   169  .../libnetwork/portmapper/mock_proxy_linux.go      |   18 +
       
   170  .../docker/libnetwork/portmapper/proxy.go          |  209 ----
       
   171  .../docker/libnetwork/portmapper/proxy_linux.go    |  209 ++++
       
   172  vendor/src/github.com/docker/libnetwork/sandbox.go |    7 +-
       
   173  .../libnetwork/sandbox_externalkey_solaris.go      |   45 +
       
   174  .../docker/libnetwork/sandbox_externalkey_unix.go  |    2 +-
       
   175  .../src/github.com/godbus/dbus/transport_unix.go   |    2 +-
       
   176  vendor/src/github.com/kr/pty/ioctl.go              |    2 +
       
   177  vendor/src/github.com/kr/pty/util.go               |   11 -
       
   178  vendor/src/github.com/mistifyio/go-zfs/utils.go    |   82 +-
       
   179  .../mistifyio/go-zfs/utils_notsolaris.go           |   82 ++
       
   180  .../github.com/mistifyio/go-zfs/utils_solaris.go   |   85 ++
       
   181  vendor/src/github.com/mistifyio/go-zfs/zfs.go      |   86 +-
       
   182  .../github.com/mistifyio/go-zfs/zfs_notsolaris.go  |   80 ++
       
   183  .../src/github.com/mistifyio/go-zfs/zfs_solaris.go |   87 ++
       
   184  vendor/src/github.com/mistifyio/go-zfs/zpool.go    |   37 +-
       
   185  .../mistifyio/go-zfs/zpool_notsolaris.go           |   33 +
       
   186  .../github.com/mistifyio/go-zfs/zpool_solaris.go   |   40 +
       
   187  .../runc/libcontainer/configs/cgroup_solaris.go    |    6 +
       
   188  .../libcontainer/configs/cgroup_unsupported.go     |    2 +-
       
   189  .../runc/libcontainer/configs/device_defaults.go   |    4 +-
       
   190  .../runc/libcontainer/console_solaris.go           |   13 +
       
   191  .../runc/libcontainer/container_solaris.go         |   22 +
       
   192  .../runc/libcontainer/stats_solaris.go             |    8 +
       
   193  .../runc/libcontainer/system/sysconfig.go          |    2 +-
       
   194  .../runc/libcontainer/zones/stats.go               |   86 ++
       
   195  vendor/src/gopkg.in/fsnotify.v1/fen.go             |  188 ++++
       
   196  vendor/src/gopkg.in/fsnotify.v1/fen_cgo.go         |   82 ++
       
   197  vendor/src/gopkg.in/fsnotify.v1/fsnotify.go        |    2 +-
       
   198  volume/local/local_unix.go                         |    2 +-
       
   199  volume/store/store_unix.go                         |    2 +-
       
   200  193 files changed, 9237 insertions(+), 1241 deletions(-)
       
   201  create mode 100644 Dockerfile.solaris
       
   202  create mode 100644 container/container_solaris.go
       
   203  create mode 100644 container/state_solaris.go
       
   204  create mode 100755 contrib/mkimage/solaris
       
   205  create mode 100644 daemon/config_solaris.go
       
   206  create mode 100644 daemon/container_operations_solaris.go
       
   207  create mode 100644 daemon/daemon_solaris.go
       
   208  create mode 100644 daemon/exec_solaris.go
       
   209  create mode 100644 daemon/execdriver/driver_solaris.go
       
   210  create mode 100644 daemon/execdriver/execdrivers/execdrivers_solaris.go
       
   211  create mode 100644 daemon/execdriver/zones/driver.go
       
   212  create mode 100644 daemon/execdriver/zones/driver_unsupported.go
       
   213  create mode 100644 daemon/execdriver/zones/driver_unsupported_nocgo.go
       
   214  create mode 100644 daemon/graphdriver/driver_solaris.go
       
   215  create mode 100644 daemon/graphdriver/zfs/zfs_solaris.go
       
   216  create mode 100644 daemon/inspect_solaris.go
       
   217  create mode 100644 daemon/stats_collector_solaris.go
       
   218  create mode 100644 daemon/stats_solaris.go
       
   219  create mode 100644 docker/daemon_solaris.go
       
   220  create mode 100644 opts/hosts_solaris.go
       
   221  create mode 100644 pkg/fileutils/fileutils_solaris.go
       
   222  create mode 100644 pkg/mount/flags_solaris.go
       
   223  create mode 100644 pkg/mount/mounter_solaris.go
       
   224  create mode 100644 pkg/mount/mountinfo_solaris.go
       
   225  create mode 100644 pkg/parsers/kernel/uname_solaris.go
       
   226  create mode 100644 pkg/parsers/operatingsystem/operatingsystem_solaris.go
       
   227  create mode 100644 pkg/platform/architecture_solaris.go
       
   228  create mode 100644 pkg/reexec/command_solaris.go
       
   229  create mode 100644 pkg/signal/signal_solaris.go
       
   230  create mode 100644 pkg/sysinfo/sysinfo_solaris.go
       
   231  create mode 100644 pkg/system/meminfo_solaris.go
       
   232  delete mode 100644 pkg/system/stat_linux.go
       
   233  create mode 100644 pkg/system/stat_unix.go
       
   234  create mode 100644 pkg/term/tc_solaris_cgo.go
       
   235  create mode 100644 pkg/term/term_solaris.go
       
   236  create mode 100644 pkg/term/term_unix.go
       
   237  create mode 100644 runconfig/hostconfig_solaris.go
       
   238  create mode 100644 vendor/src/github.com/Sirupsen/logrus/terminal_solaris.go
       
   239  create mode 100644 vendor/src/github.com/docker/libnetwork/default_gateway_solaris.go
       
   240  create mode 100644 vendor/src/github.com/docker/libnetwork/drivers/solaris/bridge/bridge.go
       
   241  create mode 100644 vendor/src/github.com/docker/libnetwork/drivers/solaris/bridge/bridge_store.go
       
   242  create mode 100644 vendor/src/github.com/docker/libnetwork/drivers/solaris/bridge/errors.go
       
   243  create mode 100644 vendor/src/github.com/docker/libnetwork/drivers/solaris/bridge/port_mapping.go
       
   244  create mode 100644 vendor/src/github.com/docker/libnetwork/drivers_solaris.go
       
   245  create mode 100644 vendor/src/github.com/docker/libnetwork/ipamutils/utils_solaris.go
       
   246  create mode 100644 vendor/src/github.com/docker/libnetwork/osl/interface_solaris.go
       
   247  create mode 100644 vendor/src/github.com/docker/libnetwork/osl/namespace_solaris.go
       
   248  create mode 100644 vendor/src/github.com/docker/libnetwork/osl/neigh_solaris.go
       
   249  create mode 100644 vendor/src/github.com/docker/libnetwork/portallocator/portallocator_linux.go
       
   250  create mode 100644 vendor/src/github.com/docker/libnetwork/portallocator/portallocator_solaris.go
       
   251  delete mode 100644 vendor/src/github.com/docker/libnetwork/portmapper/mapper.go
       
   252  create mode 100644 vendor/src/github.com/docker/libnetwork/portmapper/mapper_linux.go
       
   253  create mode 100644 vendor/src/github.com/docker/libnetwork/portmapper/mapper_solaris.go
       
   254  delete mode 100644 vendor/src/github.com/docker/libnetwork/portmapper/mock_proxy.go
       
   255  create mode 100644 vendor/src/github.com/docker/libnetwork/portmapper/mock_proxy_linux.go
       
   256  delete mode 100644 vendor/src/github.com/docker/libnetwork/portmapper/proxy.go
       
   257  create mode 100644 vendor/src/github.com/docker/libnetwork/portmapper/proxy_linux.go
       
   258  create mode 100644 vendor/src/github.com/docker/libnetwork/sandbox_externalkey_solaris.go
       
   259  create mode 100644 vendor/src/github.com/mistifyio/go-zfs/utils_notsolaris.go
       
   260  create mode 100644 vendor/src/github.com/mistifyio/go-zfs/utils_solaris.go
       
   261  create mode 100644 vendor/src/github.com/mistifyio/go-zfs/zfs_notsolaris.go
       
   262  create mode 100644 vendor/src/github.com/mistifyio/go-zfs/zfs_solaris.go
       
   263  create mode 100644 vendor/src/github.com/mistifyio/go-zfs/zpool_notsolaris.go
       
   264  create mode 100644 vendor/src/github.com/mistifyio/go-zfs/zpool_solaris.go
       
   265  create mode 100644 vendor/src/github.com/opencontainers/runc/libcontainer/configs/cgroup_solaris.go
       
   266  create mode 100644 vendor/src/github.com/opencontainers/runc/libcontainer/console_solaris.go
       
   267  create mode 100644 vendor/src/github.com/opencontainers/runc/libcontainer/container_solaris.go
       
   268  create mode 100644 vendor/src/github.com/opencontainers/runc/libcontainer/stats_solaris.go
       
   269  create mode 100644 vendor/src/github.com/opencontainers/runc/libcontainer/zones/stats.go
       
   270  create mode 100644 vendor/src/gopkg.in/fsnotify.v1/fen.go
       
   271  create mode 100644 vendor/src/gopkg.in/fsnotify.v1/fen_cgo.go
       
   272 
     6 
   273 diff --git a/Dockerfile.solaris b/Dockerfile.solaris
     7 diff --git a/Dockerfile.solaris b/Dockerfile.solaris
   274 new file mode 100644
     8 new file mode 100644
   275 index 0000000..a4ad4d4
     9 index 0000000..a4ad4d4
   276 --- /dev/null
    10 --- /dev/null
  9455 +func (c *controller) createGWNetwork() (Network, error) {
  9189 +func (c *controller) createGWNetwork() (Network, error) {
  9456 +	return nil, types.NotImplementedErrorf("default gateway functionality is not implemented in solaris")
  9190 +	return nil, types.NotImplementedErrorf("default gateway functionality is not implemented in solaris")
  9457 +}
  9191 +}
  9458 diff --git a/vendor/src/github.com/docker/libnetwork/drivers/solaris/bridge/bridge.go b/vendor/src/github.com/docker/libnetwork/drivers/solaris/bridge/bridge.go
  9192 diff --git a/vendor/src/github.com/docker/libnetwork/drivers/solaris/bridge/bridge.go b/vendor/src/github.com/docker/libnetwork/drivers/solaris/bridge/bridge.go
  9459 new file mode 100644
  9193 new file mode 100644
  9460 index 0000000..23db1d9
  9194 index 0000000..5db0560
  9461 --- /dev/null
  9195 --- /dev/null
  9462 +++ b/vendor/src/github.com/docker/libnetwork/drivers/solaris/bridge/bridge.go
  9196 +++ b/vendor/src/github.com/docker/libnetwork/drivers/solaris/bridge/bridge.go
  9463 @@ -0,0 +1,1084 @@
  9197 @@ -0,0 +1,1041 @@
  9464 +package bridge
  9198 +package bridge
  9465 +
  9199 +
  9466 +import (
  9200 +import (
  9467 +	"bufio"
  9201 +	"bytes"
  9468 +	"errors"
  9202 +	"errors"
  9469 +	"fmt"
  9203 +	"fmt"
  9470 +	"net"
  9204 +	"net"
  9471 +	"os"
       
  9472 +	"os/exec"
  9205 +	"os/exec"
  9473 +	"strconv"
  9206 +	"strconv"
  9474 +	"strings"
  9207 +	"strings"
  9475 +	"sync"
  9208 +	"sync"
  9476 +
  9209 +
  9509 +	// DefaultGatewayV4AuxKey represents the default-gateway configured by the user
  9242 +	// DefaultGatewayV4AuxKey represents the default-gateway configured by the user
  9510 +	DefaultGatewayV4AuxKey = "DefaultGatewayIPv4"
  9243 +	DefaultGatewayV4AuxKey = "DefaultGatewayIPv4"
  9511 +
  9244 +
  9512 +	// DefaultGatewayV6AuxKey represents the ipv6 default-gateway configured by the user
  9245 +	// DefaultGatewayV6AuxKey represents the ipv6 default-gateway configured by the user
  9513 +	DefaultGatewayV6AuxKey = "DefaultGatewayIPv6"
  9246 +	DefaultGatewayV6AuxKey = "DefaultGatewayIPv6"
       
  9247 +
       
  9248 +	pfctl = "/usr/sbin/pfctl"
  9514 +)
  9249 +)
  9515 +
  9250 +
  9516 +// networkConfiguration for network specific configuration
  9251 +// networkConfiguration for network specific configuration
  9517 +type networkConfiguration struct {
  9252 +type networkConfiguration struct {
  9518 +	ID                 string
  9253 +	ID                 string
  9629 +		config.BridgeName = DefaultBridgeName
  9364 +		config.BridgeName = DefaultBridgeName
  9630 +	}
  9365 +	}
  9631 +	return i
  9366 +	return i
  9632 +}
  9367 +}
  9633 +
  9368 +
  9634 +func fixPFConf() error {
  9369 +func runCmd(
  9635 +	conf := "/etc/firewall/pf.conf"
  9370 +    stdin *bytes.Buffer, stdout *bytes.Buffer,
  9636 +	f, err := os.Open("/etc/firewall/pf.conf")
  9371 +    name string, arg ...string) error {
       
  9372 +	cmd := exec.Command(name, arg...);
       
  9373 +
       
  9374 +	/* Setup Stdin, Stdout, and Stderr */
       
  9375 +	if stdin != nil {
       
  9376 +		cmd.Stdin = stdin
       
  9377 +	} else {
       
  9378 +		cmd.Stdin = nil
       
  9379 +	}
       
  9380 +	if stdout != nil {
       
  9381 +		cmd.Stdout = stdout
       
  9382 +	} else {
       
  9383 +		cmd.Stdout = new(bytes.Buffer)
       
  9384 +	}
       
  9385 +	stderr := new(bytes.Buffer)
       
  9386 +	cmd.Stderr = stderr
       
  9387 +
       
  9388 +	/*
       
  9389 +	 * Run the command.  If the command fails create a new error
       
  9390 +	 * object to return that includes stderr output.
       
  9391 +	 */
       
  9392 +	err := cmd.Start()
  9637 +	if err != nil {
  9393 +	if err != nil {
  9638 +		return fmt.Errorf("cannot open %s: %v", conf, err)
  9394 +		return err
  9639 +	}
  9395 +	}
  9640 +	defer f.Close()
  9396 +	err = cmd.Wait()
  9641 +
       
  9642 +	modify := false
       
  9643 +	lines := []string{}
       
  9644 +	scanner := bufio.NewScanner(f)
       
  9645 +	for scanner.Scan() {
       
  9646 +		l := scanner.Text()
       
  9647 +		if strings.Contains(l, "REMOVE THIS LINE") {
       
  9648 +			modify = true
       
  9649 +			continue
       
  9650 +		}
       
  9651 +		lines = append(lines, fmt.Sprintf("%s\n", l))
       
  9652 +	}
       
  9653 +	if err = scanner.Err(); err != nil {
       
  9654 +		return fmt.Errorf("cannot scan %s: %v", conf, err)
       
  9655 +	}
       
  9656 +	if !modify {
       
  9657 +		return nil
       
  9658 +	}
       
  9659 +	tmpname := "/etc/firewall/pf.conf.tmp." + strconv.Itoa(os.Getpid())
       
  9660 +	tmp, err := os.OpenFile(tmpname,
       
  9661 +		os.O_CREATE|os.O_TRUNC|os.O_WRONLY|os.O_APPEND, 0644)
       
  9662 +	if err != nil {
  9397 +	if err != nil {
  9663 +		return fmt.Errorf("cannot open %s: %v", tmpname, err)
  9398 +		return errors.New(fmt.Sprintf("%v: %s", err, stderr.String()))
  9664 +	}
       
  9665 +	defer tmp.Close()
       
  9666 +	for _, l := range lines {
       
  9667 +		_, err = tmp.WriteString(l)
       
  9668 +		if err != nil {
       
  9669 +			return fmt.Errorf("cannot write to %s: %v",
       
  9670 +				tmpname, err)
       
  9671 +		}
       
  9672 +	}
       
  9673 +	if err = tmp.Sync(); err != nil {
       
  9674 +		return fmt.Errorf("cannot sync %s: %v", tmpname, err)
       
  9675 +	}
       
  9676 +	if err = os.Rename(tmpname, conf); err != nil {
       
  9677 +		return fmt.Errorf("cannot rename %s to %s: %v",
       
  9678 +			tmpname, conf, err)
       
  9679 +	}
  9399 +	}
  9680 +	return nil
  9400 +	return nil
  9681 +}
  9401 +}
  9682 +
  9402 +
  9683 +func (d *driver) initFirewall() error {
  9403 +func (d *driver) initFirewall() error {
  9684 +	out, err := exec.Command("/usr/bin/svcs", "-Ho", "state",
  9404 +	pf_anchor := "_auto/docker"
  9685 +		"firewall").Output()
  9405 +	pf_rule := "anchor \"*\" all\n"
       
  9406 +
       
  9407 +	/* Create a packet filter anchor for docker packet filter rules.  */
       
  9408 +	stdin := bytes.NewBufferString(pf_rule)
       
  9409 +	err := runCmd(stdin, nil, pfctl, "-a", pf_anchor, "-f", "-")
  9686 +	if err != nil {
  9410 +	if err != nil {
  9687 +		return fmt.Errorf("cannot check firewall state: %v", err)
  9411 +		return fmt.Errorf(
  9688 +	}
  9412 +		    "failed to update packet filter %s ruleset: %v\n",
  9689 +	state := strings.TrimSpace(string(out))
  9413 +		    pf_anchor, err)
  9690 +	if state != "online" {
       
  9691 +		if state != "disabled" {
       
  9692 +			return fmt.Errorf("firewall service is in %s state. "+
       
  9693 +				"please enable service manually.", state)
       
  9694 +		}
       
  9695 +		if err = fixPFConf(); err != nil {
       
  9696 +			return err
       
  9697 +		}
       
  9698 +		err = exec.Command("/usr/sbin/svcadm", "enable", "-ts",
       
  9699 +			"firewall").Run()
       
  9700 +		if err != nil {
       
  9701 +			return fmt.Errorf("svcadm failed: %v", err)
       
  9702 +		}
       
  9703 +	}
       
  9704 +	out, err = exec.Command("/usr/sbin/pfctl", "-sr").Output()
       
  9705 +	if err != nil {
       
  9706 +		return fmt.Errorf("cannot run pfctl: %v", err)
       
  9707 +	}
       
  9708 +	if strings.Contains(string(out), "anchor \"_auto/docker/*\" all") {
       
  9709 +		return nil
       
  9710 +	}
       
  9711 +	pfctl_cmd := "(/usr/sbin/pfctl -sr; " +
       
  9712 +		"/usr/bin/echo \"anchor \\\"_auto/docker/*\\\"\") |" +
       
  9713 +		"/usr/sbin/pfctl -f -"
       
  9714 +	err = exec.Command("/usr/bin/bash", "-c", pfctl_cmd).Run()
       
  9715 +	if err != nil {
       
  9716 +		return fmt.Errorf("cannot add docker anchor: %v", err)
       
  9717 +	}
       
  9718 +	// XXX remove after 23533272 is fixed
       
  9719 +	workaround_cmd := "echo \"mac_pf_bypass/W 1\" | mdb -kw"
       
  9720 +	err = exec.Command("/usr/bin/bash", "-c", workaround_cmd).Run()
       
  9721 +	if err != nil {
       
  9722 +		return fmt.Errorf("cannot add workaround: %v", err)
       
  9723 +	}
  9414 +	}
  9724 +	return nil
  9415 +	return nil
  9725 +}
  9416 +}
  9726 +
  9417 +
  9727 +func (d *driver) initRouting() error {
  9418 +func (d *driver) initRouting() error {
  9838 +		return err
  9529 +		return err
  9839 +	}
  9530 +	}
  9840 +
  9531 +
  9841 +	tableName := "bridge_nw_subnets"
  9532 +	tableName := "bridge_nw_subnets"
  9842 +	pf_anchor := fmt.Sprintf("_auto/docker/%s", tableName)
  9533 +	pf_anchor := fmt.Sprintf("_auto/docker/%s", tableName)
  9843 +	err = exec.Command("/usr/sbin/pfctl", "-a", pf_anchor, "-t", tableName, "-T", "add", gwIP).Run()
  9534 +	err = exec.Command(pfctl, "-a", pf_anchor, "-t", tableName, "-T", "add", gwIP).Run()
  9844 +	if err != nil {
  9535 +	if err != nil {
  9845 +		fmt.Printf("cannot add bridge network '%s' to PF table\n", bridgeName)
  9536 +		fmt.Printf("cannot add bridge network '%s' to PF table\n", bridgeName)
  9846 +	}
  9537 +	}
  9847 +
  9538 +
  9848 +	pf_cmd := fmt.Sprintf(
  9539 +	pf_cmd := fmt.Sprintf(
  9869 +	gwName := fmt.Sprintf("%s_gw0", bridgeName)
  9560 +	gwName := fmt.Sprintf("%s_gw0", bridgeName)
  9870 +	gwIP := config.AddressIPv4.String()
  9561 +	gwIP := config.AddressIPv4.String()
  9871 +	pf_anchor := fmt.Sprintf("_auto/docker/%s", bridgeName)
  9562 +	pf_anchor := fmt.Sprintf("_auto/docker/%s", bridgeName)
  9872 +	table_anchor := fmt.Sprintf("_auto/docker/%s", tableName)
  9563 +	table_anchor := fmt.Sprintf("_auto/docker/%s", tableName)
  9873 +
  9564 +
  9874 +	err = exec.Command("/usr/sbin/pfctl", "-a", pf_anchor, "-F", "all").Run()
  9565 +	err = exec.Command(pfctl, "-a", pf_anchor, "-F", "all").Run()
  9875 +	if err != nil && logErr {
  9566 +	if err != nil && logErr {
  9876 +		fmt.Println("pfctl flush failed")
  9567 +		fmt.Println("pfctl flush failed")
  9877 +	}
  9568 +	}
  9878 +	err = exec.Command("/usr/sbin/ifconfig", gwName, "unplumb").Run()
  9569 +	err = exec.Command("/usr/sbin/ifconfig", gwName, "unplumb").Run()
  9879 +	if err != nil && logErr {
  9570 +	if err != nil && logErr {
  9887 +	err = exec.Command("/usr/sbin/dladm", "delete-etherstub",
  9578 +	err = exec.Command("/usr/sbin/dladm", "delete-etherstub",
  9888 +		"-t", bridgeName).Run()
  9579 +		"-t", bridgeName).Run()
  9889 +	if err != nil && logErr {
  9580 +	if err != nil && logErr {
  9890 +		fmt.Println("dladm delete-etherstub failed")
  9581 +		fmt.Println("dladm delete-etherstub failed")
  9891 +	}
  9582 +	}
  9892 +	err = exec.Command("/usr/sbin/pfctl", "-a", table_anchor, "-t", tableName, "-T", "delete", gwIP).Run()
  9583 +	err = exec.Command(pfctl, "-a", table_anchor, "-t", tableName, "-T", "delete", gwIP).Run()
  9893 +	if err != nil && logErr {
  9584 +	if err != nil && logErr {
  9894 +		fmt.Printf("cannot remove bridge network '%s' from PF table\n", bridgeName)
  9585 +		fmt.Printf("cannot remove bridge network '%s' from PF table\n", bridgeName)
  9895 +	}
  9586 +	}
  9896 +}
  9587 +}
  9897 +
  9588 +