Compare commits

...

1228 Commits
v0.1.0 ... main

Author SHA1 Message Date
Casey Callendrello ee7c96f201
Merge pull request #1152 from architkulkarni/status-codes
Add error codes for STATUS verb to `types.go` and `SPEC.md`
2025-06-02 17:11:33 +02:00
Casey Callendrello d0bdb01ee9
Merge pull request #1153 from xmulligan/patch-1
docs: remove archived 3rd party plugins
2025-05-16 10:30:26 +02:00
Lionel Jouin 8338cebec2
Merge pull request #1161 from bleggett/bleggett/update-email
Update my email
2025-04-22 23:46:17 +02:00
Benjamin Leggett 44a77d77e9
Update my email
Signed-off-by: Benjamin Leggett <benjamin@edera.io>
2025-04-22 11:20:07 -04:00
Tomofumi Hayashi 277757c333
Merge pull request #1157 from squeed/update-maintainers
update MAINTAINERS
2025-04-15 00:40:04 +09:00
Casey Callendrello 0b7ae2f1b1
Merge pull request #1156 from bleggett/bleggett/clarify-del
SPEC: Clarify some language around `DEL` and `prevResult`
2025-04-14 17:31:05 +02:00
Casey Callendrello 40b0a08c95 update MAINTAINERS
Add some new ones, mark others as emeritus.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2025-04-14 17:26:51 +02:00
Benjamin Leggett 7f701df6ab
Clarify some language around `DEL` and `prevResult`
Signed-off-by: Benjamin Leggett <benjamin@edera.io>
2025-04-09 18:07:38 -04:00
Casey Callendrello a28faab926
Merge pull request #1155 from squeed/remove-deprecated
libcni: remove some deprecation warnings
2025-04-07 17:37:53 +02:00
Casey Callendrello 3f7369aeb9 libcni: remove some deprecation warnings
We were a bit over-eager with the deprecations; these types and aliases
are doing no harm :-).

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2025-04-07 17:34:18 +02:00
Mike Zappa 097592d34b
Merge pull request #1154 from LionelJouin/maintainers
Update MAINTAINERS
2025-03-31 08:15:00 -06:00
Lionel Jouin d2f3f46deb Update MAINTAINERS
Signed-off-by: Lionel Jouin <lionel.jouin@est.tech>
2025-03-27 15:07:21 +01:00
Bill Mulligan 3578abe586 remove archived 3rd party plugins
Signed-off-by: Bill Mulligan <billmulligan516@gmail.com>
2025-03-16 03:48:34 +01:00
Archit Kulkarni 5f84615a5d
Add error codes for STATUS verb to `types.go` and `SPEC.md`
Signed-off-by: Archit Kulkarni <architkulkarni@google.com>
2025-01-16 00:33:03 +00:00
Casey Callendrello 3b4dfc5dff
Merge pull request #1119 from containernetworking/dependabot/github_actions/github/codeql-action-3.26.7
build(deps): bump github/codeql-action from 3.26.4 to 3.26.7
2024-09-17 16:14:21 +02:00
dependabot[bot] a845cc88d2
build(deps): bump github/codeql-action from 3.26.4 to 3.26.7
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.4 to 3.26.7.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](f0f3afee80...8214744c54)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-16 00:12:22 +00:00
Casey Callendrello 4c9ae43c0e
Merge pull request #1109 from containernetworking/dependabot/go_modules/golang-53495c1738
build(deps): bump the golang group across 1 directory with 2 updates
2024-08-29 10:01:03 +02:00
Casey Callendrello be3f5a9b2d
Merge pull request #1108 from mmorel-35/scorecard
Setup scorecard workflow
2024-08-29 10:00:34 +02:00
Matthieu MOREL f4f2dc7430 Setup scorecard workflow
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-08-28 15:01:51 +00:00
Casey Callendrello 81ed2d06d6
Merge pull request #1110 from danwinship/cnitool-binary
Remove accidentally-committed cnitool binary
2024-08-28 15:30:50 +02:00
Dan Winship 00f4094a12 Remove accidentally-committed cnitool binary
Signed-off-by: Dan Winship <danwinship@redhat.com>
2024-08-28 09:04:46 -04:00
dependabot[bot] f0289faa47
build(deps): bump the golang group across 1 directory with 2 updates
Bumps the golang group with 1 update in the / directory: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo).


Updates `github.com/onsi/ginkgo/v2` from 2.19.0 to 2.20.1
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.19.0...v2.20.1)

Updates `github.com/onsi/gomega` from 1.33.1 to 1.34.1
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.33.1...v1.34.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: golang
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: golang
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-26 00:39:46 +00:00
Casey Callendrello 81d15e90c3
Merge pull request #1052 from bleggett/bleggett/multi-dir-pluginconfig
RFC - Support safe subdirectory-based plugin conf loading
2024-07-22 11:14:15 -04:00
Casey Callendrello 309b6bbc17
Merge pull request #1103 from squeed/fix-gc-key-name
SPEC, libcni: harmonize GC valid-attachment key
2024-07-22 11:10:34 -04:00
Casey Callendrello 692efbd2a7 libcni: set both GC valid attachment keys
I made an (embarassing) error where SPEC.md and libcni disagreed on the
key for valid attachments for a GC operation. The spec has been
updated, but libcni should set both keys as a transition mechanism.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2024-07-22 10:57:12 -04:00
Casey Callendrello 6a68851f26 SPEC: use correct GC field name.
The SPEC and libcni disagreed on the name to use for still-valid
attachments. Change the spec to be aligned with libcni.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2024-07-01 17:28:26 +02:00
Mike Zappa d5c71ad528
Merge pull request #1100 from squeed/parse-semver 2024-06-24 13:59:30 -06:00
Casey Callendrello 587837eeda libcni: remove use of Masterminds/semver
We didn't really need it, and it's yet another dep to update.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2024-06-24 18:32:57 +02:00
Benjamin Leggett 425425837e
libcni: Support subdirectory-based plugin loading (#928)
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
2024-06-17 12:22:05 -04:00
Benjamin Leggett c0cc785dbc
Use type aliases to hint deprecation for old API types (#928)
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
2024-06-17 11:45:13 -04:00
Benjamin Leggett 9f73d4da82
SPEC: #928 support non-inlined plugin loading
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
2024-06-17 11:19:33 -04:00
Tomofumi Hayashi e82d9969cf
Merge pull request #1098 from squeed/gc-shared-warning
SPEC: add warning about preserving shared resources for GC
2024-06-18 00:15:44 +09:00
Casey Callendrello 2c926b5f17 SPEC: add warning about preserving shared resources for GC
For plugins that may share resources or resource pools across networks,
we should make it explicitly clear that GC must only clean up resources
known to be owned by the calling network.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2024-06-10 18:06:29 +02:00
Casey Callendrello ed014fe9dc
Merge pull request #1089 from Icarus9913/chore/darwin-ns
supplement ns building files for darwin OS
2024-06-10 17:23:41 +02:00
Casey Callendrello db70b6d343
Merge pull request #1094 from containernetworking/dependabot/go_modules/golang-a90ed34d00
build(deps): bump github.com/onsi/ginkgo/v2 from 2.17.3 to 2.19.0 in the golang group
2024-06-10 17:23:26 +02:00
Casey Callendrello fac588ba52
Merge pull request #1093 from containernetworking/dependabot/docker/dot-github/actions/retest-action/alpine-3.20
build(deps): bump alpine from 3.19 to 3.20 in /.github/actions/retest-action
2024-06-10 17:23:04 +02:00
Casey Callendrello 6e57c2ee5d
Merge pull request #1097 from s1061123/fix/1096
Fix faulty json.Marshal behavior for embeds types.NetConf
2024-06-10 17:20:05 +02:00
Tomofumi Hayashi 499596af1b
Merge branch 'main' into fix/1096 2024-06-11 00:06:55 +09:00
Casey Callendrello 73debca5ce
Merge pull request #1090 from squeed/gc-improvements
Spec, libcni: add disableGC flag
2024-06-10 17:06:14 +02:00
Tomofumi Hayashi 9d422db72c Fix faulty json.Marshal behavior for embeds types.NetConf
Signed-off-by: Tomofumi Hayashi <tohayash@redhat.com>
2024-06-04 03:31:55 +09:00
Casey Callendrello c28331408d libcni: implement disableGC
This allows administrators to disable GC behavior.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2024-06-03 16:58:20 +02:00
Casey Callendrello 1125b83816 Spec: add disableGC flag
This flag allows administrators to disable garbage collection for
exceptional circumstances.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2024-06-03 16:51:40 +02:00
Casey Callendrello 529bccb346 GetCachedAttachments should ignore missing directories
If there's no cache dir, there are no cached attachments to return. No
sense in propagating that error.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2024-06-03 16:51:40 +02:00
dependabot[bot] 267db7092b
build(deps): bump github.com/onsi/ginkgo/v2 in the golang group
Bumps the golang group with 1 update: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo).


Updates `github.com/onsi/ginkgo/v2` from 2.17.3 to 2.19.0
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.17.3...v2.19.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: golang
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-03 00:57:15 +00:00
Casey Callendrello cebd7dff3a
Merge pull request #1095 from maiqueb/always-attempt-to-cleanup-cache-on-list-delete
libcni: always delete the cache on conflist for CNI DEL
2024-05-28 10:26:17 +02:00
Miguel Duarte Barroso 6ef571535d libcni: always delete the cache on conflist for CNI DEL
This aligns the call with `DelNetwork`, and allows CRIO tests to bump -
[0].

[0] - https://github.com/cri-o/cri-o/pull/8207#issuecomment-2129937741

Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
2024-05-27 17:52:09 +02:00
dependabot[bot] 02ffd013fe
build(deps): bump alpine in /.github/actions/retest-action
Bumps alpine from 3.19 to 3.20.

---
updated-dependencies:
- dependency-name: alpine
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-27 01:00:56 +00:00
Icarus Wu 1e7858f987
supplement ns building files for darwin os
Signed-off-by: Icarus Wu <icaruswu66@qq.com>
2024-05-13 22:43:34 +08:00
Casey Callendrello c04330ee9e
Merge pull request #1063 from austinvazquez/update-golangci-lint-action-package
Update golangci-lint to v1.57.1
2024-05-13 16:41:31 +02:00
Austin Vazquez 52babb0dd3 Update golangci-lint to v1.57.1
Signed-off-by: Austin Vazquez <macedonv@amazon.com>
2024-05-13 16:40:38 +02:00
Casey Callendrello 9f32fa36f7
Merge pull request #1087 from containernetworking/dependabot/github_actions/golangci/golangci-lint-action-6
build(deps): bump golangci/golangci-lint-action from 4 to 6
2024-05-13 16:37:27 +02:00
dependabot[bot] f5e23f52c0 build(deps): bump golangci/golangci-lint-action from 4 to 6
Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 4 to 6.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v4...v6)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-13 16:37:19 +02:00
Casey Callendrello 85241009c7
Merge pull request #1088 from containernetworking/dependabot/go_modules/golang-4bdc54f992
build(deps): bump the golang group with 2 updates
2024-05-13 16:36:35 +02:00
dependabot[bot] e34763a7ec
build(deps): bump the golang group with 2 updates
Bumps the golang group with 2 updates: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) and [github.com/onsi/gomega](https://github.com/onsi/gomega).


Updates `github.com/onsi/ginkgo/v2` from 2.17.2 to 2.17.3
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.17.2...v2.17.3)

Updates `github.com/onsi/gomega` from 1.33.0 to 1.33.1
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.33.0...v1.33.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: golang
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: golang
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-13 01:01:31 +00:00
Casey Callendrello f85b8fe31f
Merge pull request #1084 from containernetworking/dependabot/go_modules/golang-7f8ea5be5c
build(deps): bump the golang group across 1 directory with 2 updates
2024-05-06 16:48:11 +02:00
dependabot[bot] 3d7be1bae9
build(deps): bump the golang group across 1 directory with 2 updates
Bumps the golang group with 1 update in the / directory: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo).


Updates `github.com/onsi/ginkgo/v2` from 2.17.1 to 2.17.2
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.17.1...v2.17.2)

Updates `github.com/onsi/gomega` from 1.32.0 to 1.33.0
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.32.0...v1.33.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: golang
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: golang
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-29 00:39:11 +00:00
Casey Callendrello df52e9460d
Merge pull request #1082 from squeed/v1.2-release
spec: remove "-dev" tag
2024-04-15 17:47:08 +02:00
Casey Callendrello 047255eeed spec: remove "-dev" tag
This is ready for release :-)

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2024-04-15 17:39:18 +02:00
Casey Callendrello 0137b32398
Merge pull request #1054 from MikeZappa87/feature/addversiontocni
Add Version to CNI interface
2024-04-08 17:16:56 +02:00
Michael Zappa dd65e2d527 add version to cni interface
Signed-off-by: Michael Zappa <michael.zappa@gmail.com>
2024-04-08 17:09:10 +02:00
Casey Callendrello bbae2202a6
Merge pull request #1080 from s1061123/cnitool-1.1.0-support
cnitool CNI 1.1.0 support
2024-04-05 14:00:25 +02:00
Tomofumi Hayashi 0036b628e1 cnitool CNI 1.1.0 support
This change make cnitool CNI v1.1.0 support. This also addresses
to fix error crash in case of GC with empty attachments.

Signed-off-by: Tomofumi Hayashi <tohayash@redhat.com>
2024-04-03 23:49:46 +09:00
Casey Callendrello 83287db830
Merge pull request #1078 from henry118/multierror
use errors package in golang v20 to join multiple errors
2024-03-27 16:40:23 +01:00
Henry Wang a67dabb3d0 use errors package in golang v20 to join multiple errors
Signed-off-by: Henry Wang <henwang@amazon.com>
2024-03-26 16:57:40 +00:00
Casey Callendrello 951d8d0e05
Merge pull request #1077 from containernetworking/dependabot/go_modules/golang-74105ccef4
build(deps): bump the golang group with 2 updates
2024-03-25 15:35:32 +01:00
dependabot[bot] f846cb72b0
build(deps): bump the golang group with 2 updates
Bumps the golang group with 2 updates: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) and [github.com/onsi/gomega](https://github.com/onsi/gomega).


Updates `github.com/onsi/ginkgo/v2` from 2.13.2 to 2.17.1
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.13.2...v2.17.1)

Updates `github.com/onsi/gomega` from 1.30.0 to 1.32.0
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.30.0...v1.32.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: golang
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: golang
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-25 14:28:03 +00:00
Casey Callendrello e4b261e1a2
Merge pull request #1073 from henry118/updatego
Update golang to active supported version
2024-03-25 15:27:11 +01:00
Henry Wang 829ae61c58 Update golang to active supported version
Signed-off-by: Henry Wang <henwang@amazon.com>
2024-03-19 20:24:14 +00:00
Tomofumi Hayashi 86c37cb0a2
Merge pull request #1071 from squeed/minor-api-fixes
Minor CNI v1.1 api fixes
2024-03-19 11:36:33 +01:00
Casey Callendrello 56f11c6c0c types: add ValidAttachments to "base" NetConf struct
Since every plugin needs to deserialize this, it should be in the
standard network configuration struct.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2024-03-18 12:22:01 +01:00
Casey Callendrello 8eb1091d78 pkg/invoke: add DelegateStatus, DelegateGC methods
Signed-off-by: Casey Callendrello <c1@caseyc.net>
2024-03-18 12:22:01 +01:00
Casey Callendrello a448e71e98
Merge pull request #961 from squeed/cleanup-releasing
Docs: remove obsolete information about building release artifacts
2024-03-17 21:37:38 +01:00
Casey Callendrello 2e9688f3b4 Docs: remove obsolete information about building release artifacts
Now that plugins live in a different repository, we don't need these old
files. We don't actuall build any release binaries.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2024-03-17 21:32:20 +01:00
Casey Callendrello 1c8da137b2
Merge pull request #1060 from SchSeba/add_mtu
Add MTU to CNI result
2024-03-15 16:11:10 +01:00
Sebastian Sch c45adb66fe Add MTU to CNI result
This commit allow CNIs to expose the MTU of interface

Signed-off-by: Sebastian Sch <sebassch@gmail.com>
2024-03-14 14:19:38 +02:00
Casey Callendrello 563cf56c27
Merge pull request #1072 from henry118/invalidcache
tolerate invalid cni caches for deletion
2024-03-12 13:27:38 +01:00
Henry Wang 2d04079cfe tolerate invalid cni caches for deletion
Signed-off-by: Henry Wang <henwang@amazon.com>
2024-03-07 23:12:45 +00:00
Casey Callendrello 845a73789a
Merge pull request #1068 from LionelJouin/scope
Add Scope property for routes
2024-03-05 10:53:32 +01:00
Lionel Jouin 00576a2e55 Scope property as int pointer
Signed-off-by: Lionel Jouin <lionel.jouin@est.tech>
2024-03-04 18:34:55 +01:00
Lionel Jouin a4d4a0d1ff Add Scope property for routes
Fixes: #598
Signed-off-by: Lionel Jouin <lionel.jouin@est.tech>
2024-03-04 18:32:23 +01:00
Casey Callendrello 06d9dec402
Merge pull request #1062 from LionelJouin/tableid
Add table ID property for routes
2024-03-04 17:53:01 +01:00
Tomofumi Hayashi d9f3a7bb2b
Merge branch 'main' into tableid 2024-03-05 01:45:57 +09:00
Casey Callendrello c822f1331b
Merge pull request #1069 from MikeZappa87/spec/socketpci
Add SocketPath/PciID to Interface struct
2024-03-04 17:41:10 +01:00
Michael Zappa 163db33480 Add socket path and pciid to CNI interface result
Signed-off-by: Michael Zappa <michaelzappa@microsoft.com>
2024-03-04 09:23:25 -07:00
Lionel Jouin 94fc2b1545 Table ID property as int pointer
Signed-off-by: Lionel Jouin <lionel.jouin@est.tech>
2024-02-19 18:58:35 +01:00
Lionel Jouin 3c4079b3db Add table ID property for routes
Fixes #1061

Signed-off-by: Lionel Jouin <lionel.jouin@est.tech>
2024-02-02 15:49:20 +01:00
Casey Callendrello b62753aa2b
Merge pull request #1039 from s1061123/json-remove-dns
Add Marshal function in Result/NetConf to omit empty value
2024-01-08 17:47:25 +01:00
Casey Callendrello 1557aeb57c
Merge pull request #1047 from containernetworking/dependabot/github_actions/actions/setup-go-5
build(deps): bump actions/setup-go from 4 to 5
2024-01-08 17:00:11 +01:00
Casey Callendrello dc24f70105
Merge pull request #1048 from containernetworking/dependabot/docker/dot-github/actions/retest-action/alpine-3.19
build(deps): bump alpine from 3.18 to 3.19 in /.github/actions/retest-action
2024-01-08 16:59:21 +01:00
Casey Callendrello 8ddb290852
Merge pull request #1049 from containernetworking/dependabot/go_modules/plugins/debug/github.com/containernetworking/plugins-1.4.0
build(deps): bump github.com/containernetworking/plugins from 1.2.0 to 1.4.0 in /plugins/debug
2024-01-08 16:58:55 +01:00
Tomofumi Hayashi d1276f1ed4 Add Marshal function in Result/NetConf to omit empty value
This change fix to avoid empty DNS field in NetConf/Result
if DNS is empty.

Signed-off-by: Tomofumi Hayashi <tohayash@redhat.com>
2023-12-19 01:02:21 +09:00
Casey Callendrello 66c292a7c5
Merge pull request #1041 from alopintsev/add-route-attributes
Add route attributes - MTU, AdvMSS, Priority
2023-12-18 16:58:10 +01:00
Casey Callendrello 2317778d4d
Merge pull request #1010 from squeed/cni-versions
spec, libcni: add cniVersions field in CNI configurations
2023-12-11 18:00:26 +01:00
Casey Callendrello a6a989119a libcni: implement version negotiation
This implements the `cniVersions` field in the network configuration
list. It allows for CNI plugins to specify that they support multiple
versions, and the runtime may select the highest version it supports.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-12-11 17:48:56 +01:00
Casey Callendrello 1362169a1f go get github.com/Masterminds/semver/v3
Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-12-11 17:39:41 +01:00
Casey Callendrello f51f8eafe2 SPEC: add version negotiation
This adds a new top-level configuration field, `cniVersions`, where
network configurations can indicate support for more than one version.

This is to enable easy upgrading of CNI versions in plugins without
lock-step updates to the runtime.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-12-11 17:39:41 +01:00
dependabot[bot] f8d7b81f43
build(deps): bump github.com/containernetworking/plugins
Bumps [github.com/containernetworking/plugins](https://github.com/containernetworking/plugins) from 1.2.0 to 1.4.0.
- [Release notes](https://github.com/containernetworking/plugins/releases)
- [Commits](https://github.com/containernetworking/plugins/compare/v1.2.0...v1.4.0)

---
updated-dependencies:
- dependency-name: github.com/containernetworking/plugins
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-11 01:10:55 +00:00
dependabot[bot] 6bac4ee028
build(deps): bump alpine in /.github/actions/retest-action
Bumps alpine from 3.18 to 3.19.

---
updated-dependencies:
- dependency-name: alpine
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-11 00:47:34 +00:00
dependabot[bot] 91db252b9d
build(deps): bump actions/setup-go from 4 to 5
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 4 to 5.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-11 00:45:33 +00:00
Casey Callendrello d2bbac8e63
Merge pull request #1045 from squeed/ref-cleanup
cleanup: update references, make links relative
2023-12-05 17:34:52 +01:00
Casey Callendrello 0e4c0e225b cleanup: update references, make links relative
Go through and update some incorrect / obsolete links and references.

No code changes.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-12-05 12:50:31 +01:00
Casey Callendrello 2cec989c82
Merge pull request #1030 from squeed/status-impl
libcni, skel: implement STATUS
2023-12-04 16:58:37 +01:00
Casey Callendrello 4caff13753 libcni, skel: implement STATUS
This adds an implementation of STATUS to libcni and skel, along with
tests.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-12-04 16:49:48 +01:00
Casey Callendrello 9c19f13738
Merge pull request #1003 from squeed/spec-status
spec: STATUS wording
2023-12-04 16:48:40 +01:00
Casey Callendrello d654dde532
Merge pull request #1044 from containernetworking/dependabot/go_modules/golang-15a4b9dd4e
build(deps): bump the golang group with 1 update
2023-12-04 12:02:07 +01:00
dependabot[bot] b9a9324609
build(deps): bump the golang group with 1 update
Bumps the golang group with 1 update: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo).

- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.13.1...v2.13.2)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: golang
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-04 00:04:37 +00:00
Alexander Lopintsev 4a0bccb249 describe mtu, advmss, priority attributes of route object in specification
Signed-off-by: Alexander Lopintsev <alex@fort.plus>
2023-11-28 18:25:07 +03:00
Alexander Lopintsev efffbeeef4 Add route attributes - MTU, AdvMSS, Priority
Signed-off-by: Alexander Lopintsev <alex@fort.plus>
2023-11-21 23:45:49 +03:00
Dan Williams 93878e6530
Merge pull request #1038 from s1061123/fix-netnsoverride
Fix if condition for netns override
2023-11-20 10:08:23 -06:00
Tomofumi Hayashi 26cfdbe95b
Merge branch 'main' into fix-netnsoverride 2023-11-20 22:58:42 +09:00
Casey Callendrello cf9ca9e003
Merge pull request #1040 from containernetworking/dependabot/go_modules/golang-027c04c118
build(deps): bump the golang group with 2 updates
2023-11-15 10:08:39 +01:00
Tomofumi Hayashi baaee10d93
Merge branch 'main' into fix-netnsoverride 2023-11-14 01:04:26 +09:00
dependabot[bot] cd1b855eae
build(deps): bump the golang group with 2 updates
Bumps the golang group with 2 updates: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) and [github.com/onsi/gomega](https://github.com/onsi/gomega).


Updates `github.com/onsi/ginkgo/v2` from 2.13.0 to 2.13.1
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.13.0...v2.13.1)

Updates `github.com/onsi/gomega` from 1.29.0 to 1.30.0
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.29.0...v1.30.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: golang
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: golang
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-13 00:29:26 +00:00
Casey Callendrello c18965d032
Merge pull request #1019 from Yejining/fix/spec-typo
SPEC: fix misspelled word
2023-11-06 17:34:19 +01:00
Casey Callendrello 911855c357
Merge pull request #1031 from mmorel-35/replace
use replace directive for github.com/containernetworking/cni
2023-11-06 17:33:20 +01:00
Casey Callendrello 8640c3ff16
Merge pull request #990 from containernetworking/dependabot/docker/dot-github/actions/retest-action/alpine-3.18
build(deps): bump alpine from 3.17 to 3.18 in /.github/actions/retest-action
2023-11-06 17:33:10 +01:00
Casey Callendrello 58eb836866
Merge pull request #1015 from jayanthvn/main
Add AWS VPC CNI for 3P list
2023-11-06 17:32:52 +01:00
Tomofumi Hayashi 6ed65ac99d Fix if condition for netns override
Signed-off-by: Tomofumi Hayashi <tohayash@redhat.com>
2023-11-06 17:32:01 +01:00
Matthieu MOREL f67e207467 use replace directive for github.com/containernetworking/cni
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-11-06 17:27:47 +01:00
Casey Callendrello 17331add54
Merge pull request #1036 from containernetworking/dependabot/go_modules/golang-a9a3abe015
build(deps): bump the golang group with 1 update
2023-11-06 17:09:18 +01:00
dependabot[bot] cfdc39b16b
build(deps): bump the golang group with 1 update
Bumps the golang group with 1 update: [github.com/onsi/gomega](https://github.com/onsi/gomega).

- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.28.0...v1.29.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: golang
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-30 00:48:29 +00:00
Casey Callendrello 509c4908cf spec: STATUS wording
This adds a new verb, STATUS, which indicates whether or not a plugin is
ready to accept ADD requests. Runtimes may choose to use the STATUS
mechanism to determine if a network is ready.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-10-23 11:40:38 +02:00
Casey Callendrello 5968d61a1e
Merge pull request #1020 from containernetworking/dependabot/github_actions/actions/checkout-4
build(deps): bump actions/checkout from 3 to 4
2023-10-23 10:56:01 +02:00
Casey Callendrello 94fd332ecd
Merge pull request #1029 from containernetworking/dependabot/go_modules/golang-91599c5cf7
build(deps): bump the golang group with 2 updates
2023-10-23 10:55:03 +02:00
dependabot[bot] 0c68fe12dc
build(deps): bump the golang group with 2 updates
Bumps the golang group with 2 updates: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) and [github.com/onsi/gomega](https://github.com/onsi/gomega).


Updates `github.com/onsi/ginkgo/v2` from 2.11.0 to 2.13.0
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.11.0...v2.13.0)

Updates `github.com/onsi/gomega` from 1.27.10 to 1.28.0
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.27.10...v1.28.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: golang
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: golang
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-23 00:58:18 +00:00
Casey Callendrello a6eaa01146
Merge pull request #987 from mmorel-35/patch-1
Define Makefile with golangci-lint
2023-10-18 16:45:32 +02:00
Casey Callendrello 58553d6cdb
Merge pull request #994 from mmorel-35/debug
Upgrade debug module go version to 1.18
2023-10-18 16:37:57 +02:00
Casey Callendrello c9fdf812d2
Merge branch 'main' into patch-1 2023-10-18 16:37:14 +02:00
Casey Callendrello 82b44c5282
Merge pull request #988 from mmorel-35/linter-gocritic
enable gocritic linter
2023-10-18 16:35:34 +02:00
Matthieu MOREL 29ba516d90 Upgrade debug module go version to 1.18
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-10-18 07:44:33 +02:00
Matthieu MOREL b7d75ff4da Define Makefile with golangci-lint
As govet and gofmt are now handled by golangci-lint, there is no need to apply them here.

Install golangci-lint

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-10-18 07:44:03 +02:00
Matthieu MOREL 4683716a59 enable gocritic linter
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-10-18 07:43:38 +02:00
Casey Callendrello 2cfe79728d
Merge pull request #1028 from squeed/dependabot-batch
dependabot: batch updates
2023-10-17 13:02:29 +02:00
Casey Callendrello 91629d5751 dependabot: batch updates
This combines go pkg updates in to a weekly branch, saving bother and
rebase time.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-10-17 12:38:53 +02:00
Casey Callendrello b15c73737e
Merge pull request #1022 from henry118/gc
implement GC keyword for CNI spec 1.1
2023-10-16 17:27:07 +02:00
Henry Wang e86c9ca58f resume and complete gc impl
Signed-off-by: Henry Wang <henwang@amazon.com>
2023-10-13 20:46:19 +00:00
Casey Callendrello 02155e0c8c skel: add gc support
Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-10-13 20:46:19 +00:00
Casey Callendrello d9f1e675b7 wip GC implementation -- spec
Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-10-13 20:46:19 +00:00
Casey Callendrello 8fdefe9412 noop: support command log file
Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-10-13 20:46:19 +00:00
Casey Callendrello 743a44d404
Merge pull request #1024 from s1061123/add-maintainer
Add Tomofumi Hayashi as a CNI maintainer
2023-10-02 17:28:04 +02:00
Tomofumi Hayashi 004b09b6a6 Add Tomofumi Hayashi as a CNI maintainer
Signed-off-by: Tomofumi Hayashi <tohayash@redhat.com>
2023-09-26 00:14:20 +09:00
Jayanth Varavani 902534de61
Merge branch 'main' into main 2023-09-14 22:28:17 -07:00
dependabot[bot] 11077bcc03
build(deps): bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-11 00:42:05 +00:00
Yejin Kim 0021b93858 SPEC: fix misspelled word
Signed-off-by: Yejin Kim <kimyejin.kr@gmail.com>
2023-09-08 16:22:10 +00:00
Dan Williams f6506e215f
Merge pull request #981 from squeed/spec-gc
SPEC: add wording for GC
2023-08-07 10:56:19 -05:00
Casey Callendrello 3072cfe946 SPEC: add wording for GC verb
GC, or garbage collection, is intended as a way for runtimes to tell
plugins about valid attachments, enabling them to delete any leaked or
stale resources.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-08-07 17:49:53 +02:00
Dan Williams 3bbe370e68
Merge pull request #1013 from haiyux/fix/k8sUrl
fix kubernetes document url in readme
2023-08-07 10:37:19 -05:00
Dan Williams 44a6eef2b2
Merge pull request #1011 from squeed/fix-version-registration
pkg/types: explicitly import all versions
2023-08-07 10:35:28 -05:00
Jayanth Varavani 837171b012 Add AWS VPC CNI for 3P list
Signed-off-by: Jayanth Varavani <1111446+jayanthvn@users.noreply.github.com>
2023-08-03 17:35:00 +00:00
haiyux 215259b17d fix kubernetes document url in readme
Signed-off-by: haiyux <haiyux@foxmail.com>
2023-07-28 15:55:12 +08:00
Casey Callendrello 4a096f6be2 pkg/types: explicitly import all versions
There was a bug in which some versions didn't register their creation
function, thus leaving some types un-decodeable. Fix that by explicitly
importing all known versions.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-07-20 10:50:22 +02:00
Casey Callendrello ca96f4ca96
Merge pull request #967 from squeed/setup-1.1
Prepare for spec version v1.1
2023-07-14 00:28:22 +02:00
Casey Callendrello a899051e44 libcni: add version v1.1.0
This adds support for CNI spec v1.1.0. Since there are no result type
changes expected, this means that we can use the existing v1.0.0 types.
That takes a bit of plumbing to decouple the type from the version.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-07-13 22:57:00 +02:00
Casey Callendrello c768dcb129 SPEC: bump version to v1.1.0-dev
Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-07-13 22:57:00 +02:00
Dan Williams 622537633d
Merge pull request #1001 from containernetworking/dependabot/go_modules/github.com/onsi/ginkgo/v2-2.11.0
build(deps): bump github.com/onsi/ginkgo/v2 from 2.9.7 to 2.11.0
2023-07-10 10:23:54 -05:00
dependabot[bot] e34f9d2bff
build(deps): bump github.com/onsi/ginkgo/v2 from 2.9.7 to 2.11.0
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.9.7 to 2.11.0.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.9.7...v2.11.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-19 01:26:35 +00:00
Dan Williams e255525e4d
Merge pull request #995 from containernetworking/dependabot/go_modules/github.com/onsi/ginkgo/v2-2.9.7
build(deps): bump github.com/onsi/ginkgo/v2 from 2.9.4 to 2.9.7
2023-06-05 10:30:24 -05:00
dependabot[bot] 2161bf8c24
build(deps): bump github.com/onsi/ginkgo/v2 from 2.9.4 to 2.9.7
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.9.4 to 2.9.7.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.9.4...v2.9.7)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-05 01:23:59 +00:00
dependabot[bot] a8fdbf9c40
build(deps): bump alpine in /.github/actions/retest-action
Bumps alpine from 3.17 to 3.18.

---
updated-dependencies:
- dependency-name: alpine
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-15 01:22:35 +00:00
Dan Williams dc0779e8ce
Merge pull request #989 from containernetworking/dependabot/go_modules/github.com/onsi/ginkgo/v2-2.9.4
build(deps): bump github.com/onsi/ginkgo/v2 from 2.9.2 to 2.9.4
2023-05-08 10:55:03 -05:00
dependabot[bot] b6608f8c87
build(deps): bump github.com/onsi/ginkgo/v2 from 2.9.2 to 2.9.4
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.9.2 to 2.9.4.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.9.2...v2.9.4)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-08 01:08:09 +00:00
dependabot[bot] 15612fccaa build(deps): bump github.com/onsi/ginkgo/v2 from 2.8.0 to 2.9.2
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.8.0 to 2.9.2.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.8.0...v2.9.2)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-21 13:22:18 +02:00
dependabot[bot] 10ec024835 build(deps): bump actions/setup-go from 3 to 4
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 3 to 4.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-20 14:22:01 +02:00
Casey Callendrello cfb0b54407
Merge pull request #954 from containernetworking/dependabot/go_modules/github.com/vishvananda/netns-0.0.4
build(deps): bump github.com/vishvananda/netns from 0.0.2 to 0.0.4
2023-04-20 14:21:23 +02:00
Casey Callendrello c9cfcaa2c7
Merge pull request #950 from containernetworking/dependabot/go_modules/plugins/debug/github.com/containernetworking/plugins-1.2.0
build(deps): bump github.com/containernetworking/plugins from 1.1.1 to 1.2.0 in /plugins/debug
2023-04-20 14:20:51 +02:00
dependabot[bot] db718fc6d5
build(deps): bump github.com/containernetworking/plugins
Bumps [github.com/containernetworking/plugins](https://github.com/containernetworking/plugins) from 1.1.1 to 1.2.0.
- [Release notes](https://github.com/containernetworking/plugins/releases)
- [Commits](https://github.com/containernetworking/plugins/compare/v1.1.1...v1.2.0)

---
updated-dependencies:
- dependency-name: github.com/containernetworking/plugins
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-20 11:30:55 +00:00
Casey Callendrello 4093160909
Merge pull request #976 from mmorel-35/golangci-lint
enable more linters
2023-04-20 13:25:32 +02:00
Matthieu MOREL 9302e5ff67 enable more linters
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-04-20 13:08:34 +02:00
Casey Callendrello 9a71f523e2
Merge pull request #984 from weizhoublue/pr/welan/spiderpool
3rd party plugins - spiderpool
2023-04-20 13:07:29 +02:00
weizhou.lan@daocloud.io 05f80e4fd9 3rd party plugins - spiderpool
Signed-off-by: weizhou.lan@daocloud.io <weizhou.lan@daocloud.io>
2023-03-29 21:35:21 +08:00
Mike Zappa f8aa587bba
Merge pull request #963 from henry118/cachelist
Porting over getCachedNetworkInfo routine from cri-o
2023-03-14 13:23:13 -06:00
Henry Wang aef15f60b3 Porting over getCachedNetworkInfo routine from cri-o
Signed-off-by: Henry Wang <henwang@amazon.com>
2023-03-13 16:05:01 +00:00
Casey Callendrello 6626820a52
Merge pull request #973 from squeed/add-meeting
add meeting link to README
2023-03-06 16:33:41 +01:00
Casey Callendrello 435fcb1414 add meeting link to README
Signed-off-by: Casey Callendrello <c1@caseyc.net>
2023-03-06 16:32:57 +01:00
Casey Callendrello 52b1cb11a5
Merge pull request #958 from mmorel-35/errorlint
ci(lint): enable errorlint linter
2023-02-20 18:05:01 +01:00
Matthieu MOREL d4c7848c2a ci(lint): enable errorlint linter
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-02-14 20:22:23 +01:00
Dan Williams d42556829e
Merge pull request #962 from yanggangtony/clean-notes
fix wrong notes for ValidateInterfaceName()
2023-02-13 10:14:48 -06:00
yanggang 1ffb655895
fix wrong notes for ValidateInterfaceName()
Signed-off-by: yanggang <gang.yang@daocloud.io>
2023-02-10 09:30:07 +08:00
Casey Callendrello cb0d26535b
Merge pull request #936 from aditighag/pr/aditighag/add-cgroup-path-to-cni-args
Extend capabilities with cgroup path
2023-02-09 11:44:20 +01:00
Aditi Ghag 420e5949b0 Extend capabilities with cgroup path
Container runtimes can pass pod cgroup path
when requested by CNI plugins.

Details around the use cases for this field are
documented - https://github.com/kubernetes/kubernetes/issues/113342.

Signed-off-by: Aditi Ghag <aditi@cilium.io>
2023-02-08 17:54:04 +01:00
dependabot[bot] 024c57f43f
build(deps): bump github.com/vishvananda/netns from 0.0.2 to 0.0.4
Bumps [github.com/vishvananda/netns](https://github.com/vishvananda/netns) from 0.0.2 to 0.0.4.
- [Release notes](https://github.com/vishvananda/netns/releases)
- [Commits](https://github.com/vishvananda/netns/compare/v0.0.2...v0.0.4)

---
updated-dependencies:
- dependency-name: github.com/vishvananda/netns
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-06 16:11:09 +00:00
Dan Williams 0821ff55fc
Merge pull request #959 from containernetworking/dependabot/go_modules/github.com/onsi/ginkgo/v2-2.8.0
build(deps): bump github.com/onsi/ginkgo/v2 from 2.7.0 to 2.8.0
2023-02-06 10:08:01 -06:00
dependabot[bot] 121798a08d
build(deps): bump github.com/onsi/ginkgo/v2 from 2.7.0 to 2.8.0
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.7.0 to 2.8.0.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.7.0...v2.8.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-06 01:14:50 +00:00
Casey Callendrello f89a8c6a3e
Merge pull request #953 from mmorel-35/lint
ci(lint): setup lint job
2023-01-30 17:41:22 +01:00
Matthieu MOREL da8672c859 ci(lint): setup lint job
Creates a lint job with a yamllint and a golangci-lint
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-01-27 11:03:37 +01:00
Casey Callendrello c5603949c1
Merge pull request #944 from containernetworking/dependabot/go_modules/github.com/onsi/ginkgo/v2-2.7.0
build(deps): bump github.com/onsi/ginkgo/v2 from 2.6.1 to 2.7.0
2023-01-16 10:31:55 +01:00
dependabot[bot] 8ac5c8a7f1
build(deps): bump github.com/onsi/ginkgo/v2 from 2.6.1 to 2.7.0
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.6.1 to 2.7.0.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.6.1...v2.7.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-16 09:21:27 +00:00
Casey Callendrello ed461a9b0e
Merge pull request #945 from containernetworking/dependabot/go_modules/github.com/vishvananda/netns-0.0.2
build(deps): bump github.com/vishvananda/netns from 0.0.1 to 0.0.2
2023-01-16 10:13:26 +01:00
dependabot[bot] 5fa3464d59
build(deps): bump github.com/vishvananda/netns from 0.0.1 to 0.0.2
Bumps [github.com/vishvananda/netns](https://github.com/vishvananda/netns) from 0.0.1 to 0.0.2.
- [Release notes](https://github.com/vishvananda/netns/releases)
- [Commits](https://github.com/vishvananda/netns/compare/v0.0.1...v0.0.2)

---
updated-dependencies:
- dependency-name: github.com/vishvananda/netns
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-16 01:27:27 +00:00
Casey Callendrello 6a43fb5511
Merge pull request #938 from mmorel-35/main
ci(deps): setup dependabot
2023-01-09 18:04:09 +01:00
Matthieu MOREL 45761d9522 update github.com/vishvananda/netns to v0.0.1
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2022-12-26 21:32:38 +00:00
dependabot[bot] aeb1d8ebf8 build(deps): bump github.com/containernetworking/plugins
Bumps [github.com/containernetworking/plugins](https://github.com/containernetworking/plugins) from 0.9.1 to 1.1.1.
- [Release notes](https://github.com/containernetworking/plugins/releases)
- [Commits](https://github.com/containernetworking/plugins/compare/v0.9.1...v1.1.1)

---
updated-dependencies:
- dependency-name: github.com/containernetworking/plugins
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2022-12-26 21:32:38 +00:00
dependabot[bot] dd2d40c4f6 build(deps): bump github.com/containernetworking/cni in /plugins/debug
Bumps [github.com/containernetworking/cni](https://github.com/containernetworking/cni) from 1.0.1 to 1.1.2.
- [Release notes](https://github.com/containernetworking/cni/releases)
- [Commits](https://github.com/containernetworking/cni/compare/v1.0.1...v1.1.2)

---
updated-dependencies:
- dependency-name: github.com/containernetworking/cni
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2022-12-26 21:32:38 +00:00
Matthieu MOREL 97954935c5 Update dependabot.yml
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2022-12-26 21:32:38 +00:00
dependabot[bot] 0a26996875 build(deps): bump alpine in /.github/actions/retest-action
Bumps alpine from 3.10 to 3.17.

---
updated-dependencies:
- dependency-name: alpine
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2022-12-26 21:32:38 +00:00
dependabot[bot] cc036171cc build(deps): bump github.com/onsi/gomega from 1.17.0 to 1.24.2
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.17.0 to 1.24.2.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.17.0...v1.24.2)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2022-12-26 21:32:38 +00:00
Matthieu MOREL 55be4ccd0d Create dependabot.yml
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2022-12-26 21:32:38 +00:00
Eng Zer Jun f024754da8 refactor: move from io/ioutil to io and os packages
The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

[1]: https://golang.org/doc/go1.16#ioutil
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-12-12 17:44:39 +01:00
Michael Zappa e18f6322ff Update email to gmail
Signed-off-by: Michael Zappa <michael.zappa@gmail.com>
2022-12-12 17:44:01 +01:00
Dan Williams 6e5ac36b42
Merge pull request #935 from austinvazquez/update-github-actions-packages
Upgrade GitHub actions packages to resolve NodeJS 12 warnings
2022-12-05 10:12:12 -06:00
Austin Vazquez 58488a6214 Upgrade GitHub actions packages to resolve NodeJS 12 warnings
Upgrades actions/checkout and actions/setup-go packages to v3 to resolve
CI workflow NodeJS 12 warnings.

Signed-off-by: Austin Vazquez <macedonv@amazon.com>
2022-12-01 21:43:45 +00:00
Dan Williams e629d106b4
Merge pull request #920 from loxi-admin/main
Removed loxilight as it is not supported anymore
2022-11-14 10:06:37 -06:00
loxi-admin 62709e0a59 Removed loxilight as it is not supported anymore
Signed-off-by: loxi-admin <admin@netlox.io>
2022-10-31 16:33:09 +01:00
Dan Williams 76aaefb2cb libcni: handle string-type disableCheck values
CNI spec 0.4x (and possibly earlier) mistakenly specified disableCheck
as a string type, while 1.0 cleaned that up to be a real boolean.

We should be nice and interpret the string value.

Fixes: https://github.com/containernetworking/cni/issues/877

Signed-off-by: Dan Williams <dcbw@redhat.com>
2022-10-31 16:32:33 +01:00
Bruce Ma 04dce8c7d3 testhelpers: use `go mod tidy` to ensure all necessary dependencies before building
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2022-10-31 16:28:20 +01:00
Dan Williams 307ed01652
Merge pull request #914 from squeed/iso
cdc: update email
2022-10-10 10:52:34 -05:00
Casey Callendrello be9139d588 cdc: update email
Signed-off-by: Casey Callendrello <cdc@redhat.com>
2022-10-10 17:51:55 +02:00
Dan Williams 30fd41546b
Merge pull request #913 from squeed/bump-go
Bump go to v1.19
2022-10-10 10:41:14 -05:00
Casey Callendrello dc22d0462d go.mod: bump to go1.18
Signed-off-by: Casey Callendrello <cdc@redhat.com>
2022-10-10 17:27:50 +02:00
Casey Callendrello 69967699d7 github: bump go version to v1.19
Signed-off-by: Casey Callendrello <cdc@redhat.com>
2022-10-10 17:26:56 +02:00
Casey Callendrello 08fb4605fc go fmt
Signed-off-by: Casey Callendrello <cdc@redhat.com>
2022-10-10 17:26:29 +02:00
s00613818 dbf33e2c59 fix 714-plugin add netns validation reinforcement
Signed-off-by: Poor12 <shentiecheng@huawei.com>
2022-10-10 17:19:31 +02:00
Casey Callendrello 8dba3824fb libcni: add specific type for CHECK not supported
Previously, we returned an arbitrary string error if the given CNI
version didn't support CHECK. This is not useful for downstream
consumption and matching.

So, declare an error variable so that users can use `errors.Is()`
instead of matching on a string.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
2022-09-19 17:13:58 +02:00
Dan Williams 40fa4795fb
Merge pull request #908 from ShubhamTatvamasi/patch-1
Updated Calico project link
2022-08-08 10:06:39 -05:00
Shubham Tatvamasi a710a7b4c1 Updated Calico project link
Signed-off-by: Shubham Tatvamasi <shubhamtatvamasi@gmail.com>
2022-08-03 11:14:34 +05:30
Dan Williams 3363d14368
Merge pull request #904 from brandond/fix_null_output
Fix successfully unmarshalled nil raw result
2022-07-27 10:46:15 -05:00
Brad Davidson 1c7c696779 Fix successfully unmarshalled nil raw result
Properly handle "null" as plugin output. This successfully unmarshals to a nil map, which crashes later when assigning confVersion to the map.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2022-07-15 15:24:07 -07:00
Dan Williams 812a8cfa8a
Merge pull request #902 from drivebyer/drivebyer-patch-1
spec: fix format
2022-07-13 10:41:02 -05:00
Yang Wu 58b77bdf71 spec: fix format
Signed-off-by: drivebyer <wuyangmuc@gmail.com>
2022-07-01 21:45:33 +08:00
Michael C. Cambria 3ec19197ef
Merge pull request #896 from dcbw/empty-result-version-regression
invoke: if Result CNIVersion is empty use netconf CNIVersion
2022-05-25 13:12:46 -04:00
Dan Williams 55fe94e885 invoke: if Result CNIVersion is empty use netconf CNIVersion
The CNI Spec requires plugins to return a CNIVersion in the Result
that is the same as the CNIVersion of the incoming CNI config.

Empty CNIVersions are specified to map to 0.1.0 (since the first
CNI spec didn't have versioning) and libcni handles that automatically.

Unfortunately some versions of Weave don't do that and depend on
a libcni <= 0.8 quirk that used the netconf version if the result
version was empty. This is technically a libcni regression, though
the plugin itself is violating the specification.

Thus for backwards compatibility assume that if the Result
CNIVersion is empty, the netconf CNIVersion should be used as
the Result version.

Fixes: https://github.com/containernetworking/cni/issues/895

Signed-off-by: Dan Williams <dcbw@redhat.com>
2022-05-25 10:57:53 -05:00
Dan Williams 940e662699
Merge pull request #894 from fujitatomoya/bugfix-20220503-golint-error-cnitool
cnitool: address golint error
2022-05-11 10:43:46 -05:00
Tomoya Fujita 99eac24911 cnitool: address golint error
exported const EnvCNIPath should have comment (or a comment on this block) or be unexported

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
2022-05-03 15:23:55 -07:00
Dan Williams 08f8596ff3
Merge pull request #893 from squeed/handle-empty-version
libcni: handle empty version when parsing version
2022-04-27 14:52:20 -05:00
Casey Callendrello 1054f8ead7 libcni: handle empty version when parsing version
Without this Delete failed for empty-version configs.

Update the tests to catch this case.

Signed-off-by: Casey Callendrello <cdc@redhat.com>
2022-04-27 21:47:32 +02:00
Dan Williams f32e3df6fb
Merge pull request #884 from jeefy/add-security-header
Add security heading to README
2022-04-13 10:43:50 -05:00
Casey Callendrello c9114c284a
Merge branch 'main' into add-security-header 2022-03-30 18:09:04 +02:00
Sascha Grunert 54f1587d67 Switch to ginkgo/v2
Update ginkgo to the next major version which has been released a while
ago.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-03-30 18:05:12 +02:00
Casey Callendrello bb46e27465
Merge branch 'main' into add-security-header 2022-03-23 16:52:18 +01:00
Dan Williams e6dea17746
Merge pull request #885 from squeed/mz2maint
Maintainers: add Mike Zappa
2022-03-23 10:51:13 -05:00
Jeffrey Sica aba8f8b1fb add security heading to README
Signed-off-by: Jeffrey Sica <me@jeefy.dev>
2022-03-16 22:44:09 -05:00
Casey Callendrello 4b46fe6d73 Maintainers: add Mike Zappa
Signed-off-by: Casey Callendrello <cdc@redhat.com>
2022-03-16 16:38:32 +01:00
Bruce Ma 2f6d8b1930 introduce hybridnet to thrid-party plugins
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2022-03-09 17:56:18 +01:00
Dan Williams 35efaabf93
Merge pull request #875 from netlox-dev/master
Updated README to reflect loxilight CNI plugin provided by netlox.io
2022-03-02 10:39:29 -06:00
NetLOX e4a9f965d0
Merge branch 'containernetworking:master' into master 2022-03-01 20:28:28 +09:00
Dan Williams 96a1883818
Merge pull request #880 from howardjohn/json/unmarshal-pointer
Fix incorrect pointer inputs to `json.Unmarshal`
2022-02-23 10:42:06 -06:00
John Howard 3e49ce16b5 Fix incorrect pointer inputs to `json.Unmarshal`
See https://github.com/howardjohn/go-unmarshal-double-pointer for more
info on why this is not safe and how this is detected.

Signed-off-by: John Howard <howardjohn@google.com>
2022-02-22 12:59:59 -08:00
NetLOX 96425dafeb
Merge branch 'containernetworking:master' into master 2022-02-10 09:57:13 +09:00
yanghesong b92c836f3a fix version of cni
v0.8.1 does not have a directory of github.com/containernetworking/cni/pkg/types/100
refer to https://github.com/containernetworking/cni/tree/v0.8.1/pkg/types

Signed-off-by: yanghesong <hesong.yang@foxmail.com>
2022-01-19 10:46:50 -06:00
Andreas Karis 269bf6103d Spec: Container runtime shall tear down namespaces
Explicitly state that the container runtime, not the plugin, shall tear
down network namespaces.

Signed-off-by: Andreas Karis <ak.karis@gmail.com>
2022-01-12 18:23:42 +01:00
NetLOX 48fac6a491 Update README.md
Signed-off-by: netlox-io <admin@netlox.io>
2022-01-05 12:19:52 +09:00
NetLOX 798e63d83f Updated README.md to include Netlox loxilight CNI
Signed-off-by: netlox-io <admin@netlox.io>
2022-01-05 12:19:52 +09:00
Dan Williams 4756a3616c
Merge pull request #865 from pkit/pkit/exec_plugins
[exec-plugins]: support plugin lists
2021-11-17 10:38:18 -06:00
Dan Williams cff680034b
Merge branch 'master' into pkit/exec_plugins 2021-11-17 10:34:15 -06:00
Dan Williams 10f777cb7d
Merge pull request #868 from kpaschen/multus-readme
documentation: update Multus link in README.md
2021-11-17 10:33:48 -06:00
Developer 9070cb3eec documentation: update Multus link in README.md to point to the k8snetworkplumbingwg repository
Signed-off-by: kpaschen <kathrin.paschen@gmail.com>
2021-11-16 14:07:48 +01:00
Bruce Ma 1d9f32dc0e
Merge pull request #864 from tklauser/skel-superfluous-err-nil-check
skel: remove superfluous err nil check in (*dispatcher).pluginMain
2021-11-08 15:37:44 +08:00
Constantine Peresypkin 21cd5f0c1f [exec-plugins]: support plugin lists
add ability to run configurations with plugin lists/chaning
see SPEC >= 0.3.1

Signed-off-by: Constantine Peresypkin <constantine@caspiandb.com>
2021-10-31 17:51:23 +02:00
Tobias Klauser c3625975b3 skel: remove superfluous err nil check in (*dispatcher).pluginMain
There is no need to check err against nil, just return it.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2021-10-25 15:23:12 +02:00
Dan Williams 6a92df875a
Merge pull request #863 from rosenhouse/remove-gabe
Remove Gabe Rosenhouse as maintainer
2021-10-06 10:31:34 -05:00
Gabriel Rosenhouse 42f24747b7 Remove Gabe Rosenhouse as maintainer
Signed-off-by: Gabriel Rosenhouse <grosenhouse@vmware.com>
2021-09-28 16:37:03 -07:00
Bruce Ma 5725f27869
Merge pull request #860 from squeed/help-print-version
skel: print out CNI versions supported in help text.
2021-09-09 09:39:28 +08:00
Casey Callendrello 2e4887bf8a skel: print out CNI versions supported in help text.
Signed-off-by: Casey Callendrello <cdc@redhat.com>
2021-09-08 15:31:29 +02:00
Dan Williams 1694fd7b57
Merge pull request #858 from squeed/version-from
pkg/version: add VersionsFrom function
2021-09-07 08:04:59 -05:00
Casey Callendrello c7f5f70554 pkg/version: add VersionsFrom function
So plugins can easily declare support for "from version 0.3 and
beyond".

Signed-off-by: Casey Callendrello <cdc@redhat.com>
2021-09-07 11:44:54 +02:00
Dan Williams 5608690f77 spec: bump to 1.0.0
Signed-off-by: Dan Williams <dcbw@redhat.com>
2021-08-04 18:01:03 +02:00
Dan Williams 699ad28878
Merge pull request #853 from squeed/bump-spec-upgrades
Docs: bump spec version information
2021-08-04 10:59:48 -05:00
Casey Callendrello 30e06a8b76 Docs: bump spec version information
Signed-off-by: Casey Callendrello <cdc@redhat.com>
2021-08-04 17:58:20 +02:00
Dan Williams 0dfe02421e
Merge pull request #851 from DrmagicE/master
docs: correct the extension name of the configuration file
2021-08-04 10:22:43 -05:00
DrmagicE a9562466f1 docs: revise cnitool docs
Signed-off-by: DrmagicE <379342542@qq.com>
2021-07-24 16:33:41 +08:00
Paul Holzinger 63a3bca188 wrap returned errors
fmt.Errorf errors should wrap the original error with %w.
This allows the caller to check the errors with `errors.Is()`.

see: https://blog.golang.org/go1.13-errors

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-07-21 17:56:49 +02:00
DrmagicE b277ec1bc2 docs: correct the extension name of the configuration file
Signed-off-by: DrmagicE <379342542@qq.com>
2021-07-18 20:51:40 +08:00
Bruce Ma 34a8a464e1 chore: standardize documentation on IP assignment
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2021-07-07 17:12:04 +02:00
Dan Williams 76bf3de7f8 types: ensure empty CNIVersion always creates/converts to 0.1.0
Signed-off-by: Dan Williams <dcbw@redhat.com>
2021-06-30 18:01:14 +02:00
Dan Williams b4e078af7a
Merge pull request #845 from jayunit100/patch-1
Add breadcrumbs to the api.go
2021-06-23 10:04:41 -05:00
jay vyas 4feedb9dde Add breadcrumbs for CNI.go
Signed-off-by: jay vyas <jvyas@vmware.com>
2021-06-16 11:36:18 -04:00
Dan Williams 57cf1cee7d types/create: add CreateFromBytes()
Turns out a number of users want to read in JSON and
create a Result object from it, and CNI didn't have
a function to do that in one call. Instead you had to
create a ConfigDecoder first, then create a Result
from the given version.

That's silly, let's just make a function to do that
and let everyone do less work.

Signed-off-by: Dan Williams <dcbw@redhat.com>
2021-06-16 17:28:23 +02:00
Bruce Ma 4fdc5f62c9 chore: support both value type and pointer type in LoadArgs
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2021-06-02 17:45:22 +02:00
Dan Williams 3a8fc073b5
Merge pull request #842 from containernetworking/remove-bryan
Remove Bryan Boreham as maintainer
2021-05-26 10:25:32 -05:00
Bryan Boreham f30a8249fd Remove Bryan Boreham as maintainer
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2021-05-21 14:46:40 +00:00
Tomofumi Hayashi c63d850d60
Add debug plugin to help debugging/troubleshooting (#818)
This change introduces debug plugin to help to develop CNI plugins.

Signed-off-by: Tomofumi Hayashi <tohayash@redhat.com>
2021-05-19 11:22:44 -04:00
Dan Williams 37ce8d6fbe
Merge pull request #839 from Nordix/spec-updates
spec: Some minor corrections
2021-05-05 10:34:04 -05:00
Björn Svensson 9546b704c8 spec: Some minor corrections
Corrected typos, links, formatting and added some details.

Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
2021-04-30 23:50:24 +02:00
Michael C. Cambria 7ba00c594c
Merge pull request #838 from squeed/no-args-env
Spec: Bring 1.0's treatment of "args" in line with 0.4.0
2021-04-28 11:26:23 -04:00
Casey Callendrello 3a13f6854d Spec: Bring 1.0's treatment of "args" in line with 0.4.0
The spec deviated from the existing behavior, and it was never actually
implemented in libcni. So this is a no-op.

Signed-off-by: Casey Callendrello <cdc@redhat.com>
2021-04-28 11:23:56 -04:00
Dan Williams 05ea7269e1
Merge pull request #835 from hs0210/work
Fix typo in SPEC.md
2021-04-28 10:20:51 -05:00
Bruce Ma 16f664ce57
Merge pull request #836 from cuirunxing-hub/master
upgrade kube-ovn new github site
2021-04-26 10:25:43 +08:00
cuirunxing-hub c92642bda0 upgrade kube-ovn new github site
Signed-off-by: cuirunxing-hub <cuirunxing@inspur.com>
2021-04-25 19:07:50 +08:00
Hu Shuai 67ec90448e Fix typo in SPEC.md
Signed-off-by: Hu Shuai <hus.fnst@cn.fujitsu.com>
2021-04-25 13:24:29 +08:00
Bryan Boreham e33f449ec9
Merge pull request #833 from cuirunxing-hub/master
typos correct
2021-04-19 13:59:50 +01:00
cuirunxing-hub 0555966685 typos correct
Signed-off-by: cuirunxing-hub <cuirunxing@inspur.com>
2021-04-15 17:55:08 +08:00
Casey Callendrello 8b25a7bf9e
Merge pull request #805 from squeed/spec-rewrite
Rewrite spec.md for 1.0.0
2021-03-31 17:15:48 +02:00
Casey Callendrello 8ad568b543 Rewrite spec.md for 1.0.0
The protocol is unchanged, but the specification was badly in need of a
rewrite.

Signed-off-by: Casey Callendrello <cdc@redhat.com>
2021-03-31 17:14:35 +02:00
Bruce Ma ea59a90103
Merge pull request #819 from chandanAggarwal/update_azure_cni_reference
Adding reference to Azure CNI as 3rd party plugin in README
2021-03-26 14:51:12 +08:00
Chandan Aggarwal 00169178ed Adding reference to Azure CNI as 3rd party plugin in readme
Signed-off-by: Chandan Aggarwal <caggar@microsoft.com>
2021-03-22 12:59:28 -07:00
Dan Williams c2f6afa41f
Merge pull request #802 from fasaxc/log-plugin-name
Log out the plugin name on ADD/DEL failure.
2021-03-03 10:16:29 -06:00
Bryan Boreham 9c075a3e40
Merge branch 'master' into log-plugin-name 2021-03-03 16:10:03 +00:00
Dan Williams 23b841a269
Merge pull request #813 from dcbw/020-no-ip-testcase
types/040: add testcase for <= 0.2.0 Result requirement of one or more IPs
2021-02-17 11:33:32 -06:00
Dan Williams e00ed00197
Merge branch 'master' into 020-no-ip-testcase 2021-02-17 10:21:57 -06:00
Dan Williams ad59be0959 types/040: add testcase for <= 0.2.0 Result requirement of one or more IPs
The 0.2.0 spec strongly suggests via lack of the "(optional)" tag that
a Result must contain one or two IP addresses. We already throw an
error for that case when down-converting a 0.3.0+ Result to <= 0.2.0,
but we didn't have a testcase for it.

Signed-off-by: Dan Williams <dcbw@redhat.com>
2021-02-10 10:49:48 -06:00
Dan Williams b5ab16f010
Merge pull request #810 from squeed/github-action
Switch from Travis to GH Actions
2021-02-03 10:52:38 -06:00
Casey Callendrello e32b586636 remove build badges from homepage
Signed-off-by: Casey Callendrello <cdc@redhat.com>
2021-02-03 17:48:45 +01:00
Casey Callendrello 296290a913 Switch from Travis to GH Actions
Signed-off-by: Casey Callendrello <cdc@redhat.com>
2021-02-03 17:48:44 +01:00
Casey Callendrello a199e6aa75 go fmt
Signed-off-by: Casey Callendrello <cdc@redhat.com>
2021-02-01 13:26:11 +01:00
Dan Williams a5c35b1d17
Merge pull request #808 from squeed/plugin-name
tighten up plugin-finding logic
2021-01-20 11:08:45 -06:00
Casey Callendrello ada67263b1 tighten up plugin-finding logic
Signed-off-by: Casey Callendrello <cdc@redhat.com>
2021-01-20 18:04:44 +01:00
Dan Williams 15391a8c4a
Merge pull request #801 from mccv1r0/alias
Add "alias" to conventions
2021-01-20 11:01:10 -06:00
Michael Cambria eec3755640 Add "alias" to conventions
Signed-off-by: Michael Cambria <mcambria@redhat.com>
2021-01-20 11:59:17 -05:00
Dan Williams 216a7099cb
Merge pull request #807 from hs0210/work
Fix typo in pkg/types/internal/convert.go
2021-01-19 11:06:47 -06:00
Hu Shuai 867451c7a0 Fix typo in pkg/types/internal/convert.go
Signed-off-by: Hu Shuai <hus.fnst@cn.fujitsu.com>
2021-01-15 09:47:40 +08:00
Dan Williams 77cd8fe3d6
Merge pull request #803 from champtar/maintainers-typo
maintainers: fix typo
2021-01-06 10:27:10 -06:00
Dan Williams 75e7788841
Merge pull request #804 from Ashon/issues/fix-typo-in-convention
Fix typo in CONVENTIONS.md
2021-01-06 10:10:32 -06:00
ashon 679ed9d310 Fix typo in CONVENTIONS.md
Signed-off-by: ashon <ashon8813@gmail.com>
2020-12-30 23:17:53 +09:00
Etienne Champetier 6d8228e1d3 maintainers: fix typo
Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
2020-12-29 17:25:04 -05:00
Shaun Crampton c7357803b1 Markups.
Signed-off-by: Shaun Crampton <shaun@tigera.io>
2020-12-23 15:15:17 +00:00
Shaun Crampton b678c260c4 Log out the plugin name on ADD/DEL failure.
Makes it easier to diagnose conf lists when one plugin fails.

Signed-off-by: Shaun Crampton <shaun@tigera.io>
2020-12-21 11:01:14 +00:00
Casey Callendrello 62e54113f4
Merge pull request #800 from dcbw/100-remove-SupportedVersions
types: unexport SupportedVersions
2020-12-16 17:46:44 +01:00
Dan Williams e781c94eea types: remove SupportedVersions
SupportedVersions isn't really needed outside the types themselves.

Signed-off-by: Dan Williams <dcbw@redhat.com>
2020-12-16 08:52:57 -06:00
Dan Williams d1e1ae3c34
Merge pull request #783 from dcbw/100
types changes for 1.0.0
2020-11-19 07:59:36 -06:00
Dan Williams 7555ca3250 spec: bump to 1.0.0-pre-release and remove 'version' from Result addresses
Redundant and easily determined from the address itself.

Signed-off-by: Dan Williams <dcbw@redhat.com>
2020-11-18 11:10:51 -06:00
Dan Williams 6823eba0ec tests: small cleanup and removal of one useless testcase
The testcase checking if a prevResult was invalid is not actually
useful, because it was testing that an empty prevResult could be
unmarshalled. But due to an oversight, prevResults may not have
a CNIVersion key, which is all we can check for validity.

Signed-off-by: Dan Williams <dcbw@redhat.com>
2020-11-11 11:03:15 -06:00
Dan Williams 3805b13a3b types: add 1.0.0
Only change this time is removal of the IPConfig "Version" field
which was deemed redundant.

Signed-off-by: Dan Williams <dcbw@redhat.com>
2020-11-11 11:03:15 -06:00
Dan Williams 0050bfa528 types: implement convert module and make types use it
Moving to spec 1.0.0 requires more complicated conversions, so
put the converter determination logic in a separate module that
any of the types can call to convert between arbitrary versions.
This is necessary to ensure the types don't have import cycles.

This also implements downconversion, which we never claimed
*not* to support, but didn't implement.

It also verifies that the Result object unmarshalled by
each result type's NewResult() function is actually supported
by the result type. This is a potentially breaking change as
this was not previously done, and for example may now fail
attempts to read a cached PrevResult written by a previous
version.

Signed-off-by: Dan Williams <dcbw@redhat.com>
2020-10-28 12:16:07 -05:00
Dan Williams 6fc72a49e9
Merge pull request #781 from dcbw/go-113
Bump release build Go version to 1.14
2020-08-05 14:43:21 -05:00
Dan Williams 90311ea2b0 Bump release build Go version to 1.14
Signed-off-by: Dan Williams <dcbw@redhat.com>
2020-08-05 10:58:15 -05:00
Dan Williams e91547363e
Merge pull request #780 from containernetworking/add-security-info
Add security reporting info
2020-08-05 10:48:31 -05:00
Bryan Boreham f9b5c9b162 Add security reporting info
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2020-08-05 15:39:57 +00:00
Bryan Boreham 17b2a04fa4
Merge pull request #776 from clebio/revert_error_codes
Revert formatting of error codes
2020-07-08 16:08:16 +01:00
Caleb Hyde e5c65a5bf3 Revert formatting of error codes
In a prior change, reformatting of the errors codes within the
specification changed their values from positive to negative integers.

Signed-off-by: Caleb Hyde <caleb.hyde@gmail.com>
2020-07-03 14:49:25 -07:00
Dan Williams 6b482fdc76
Merge pull request #774 from squeed/go-mod
Switch to go modules
2020-07-01 10:13:30 -05:00
Casey Callendrello 65bf6884d1 Travis: bump go versions
Drop 1.11, 1.12, add 1.14.

Signed-off-by: Casey Callendrello <cdc@redhat.com>
2020-06-30 10:37:04 +02:00
Casey Callendrello a7cceb916d add go.mod
Signed-off-by: Casey Callendrello <cdc@redhat.com>
2020-06-30 10:37:04 +02:00
Casey Callendrello 93a7425495 testhelpers: clean up how we build against old libcni targets
Now that go has modules, we don't need to do anything particularly
special to build against old cni revisions. Just let `go get` sort it
out for us.

Signed-off-by: Casey Callendrello <cdc@redhat.com>
2020-06-30 10:37:01 +02:00
Casey Callendrello 11db36c11b
Merge pull request #768 from asears/md-doc-lint-updates-3
Fix linting issues in docs, add headers to json example, update errors into table
2020-06-10 17:43:06 +02:00
Casey Callendrello 9ec274acd6
Merge branch 'master' into md-doc-lint-updates-3 2020-06-10 17:38:01 +02:00
Bryan Boreham 0016c95d2e
Merge pull request #769 from caboteria/readme-tweaks
Readme tweaks
2020-06-10 16:36:33 +01:00
toby cabot c78d465e9f Replace 2019 conference announcement with links to the recordings
While KubeCon/CloudNativeCon 2019 is in the past the recordings of the
sessions are helpful.

Signed-off-by: toby cabot <toby@caboteria.org>
2020-06-07 18:12:05 -04:00
toby cabot fc1de42c01 Sync contact methods in README and CONTRIBUTING
Now that the CNI slack has been in use for ~7 months it's no longer
necessary to have it as a top-level banner headline.  It should be in
CONTRIBUTING.md, though, with the other project contact channels.

Signed-off-by: toby cabot <toby@caboteria.org>
2020-06-07 18:12:05 -04:00
asears c815aca145
Update the SPEC, CODE-OF-CONDUCT, CONTRIBUTING, RELEASING with minor formatting changes and linting updates.
Signed-off-by: asears <asears@users.noreply.github.com>
2020-06-03 21:41:13 -04:00
Casey Callendrello f92762a8bf
Merge pull request #765 from rkamudhan/patch-4
adding OVN4NFV-K8s-Plugin as 3rd party plugin
2020-05-13 17:13:39 +02:00
Kuralamudhan Ramakrishnan 17a6379deb Update README.md
Signed-off-by: r.kuralamudhan <kuralamudhan.ramakrishnan@intel.com>
2020-05-06 21:12:32 -07:00
Kuralamudhan Ramakrishnan 956c943a7e adding OVN4NFV-K8s-Plugin as 3rd party plugin
Adding [OVN4NFV-K8S-Plugin](https://github.com/opnfv/ovn4nfv-k8s-plugin) is
OVN based CNI controller plugin to provide cloud-native based Service function
chaining(SFC), Multiple OVN overlay networking, dynamic subnet creation,
dynamic creation of virtual networks, VLAN Provider network,
Direct provider network and pluggable with other Multi-network plugins,
ideal for edge-based cloud-native workloads in Multi-cluster networking

Signed-off-by: r.kuralamudhan <kuralamudhan.ramakrishnan@intel.com>
2020-05-06 21:11:32 -07:00
Bryan Boreham 77436456f2
Merge pull request #763 from saschagrunert/version-retry
Retry exec commands on text file busy
2020-04-22 16:55:15 +01:00
Dan Williams acc3dadce9
Merge pull request #764 from adrianchiris/typo-infiniband-guid
Typo fixes for infiniband GUID
2020-04-22 10:53:43 -05:00
Sascha Grunert e2a736653a
Retry exec commands on text file busy
This makes the plugin validation a bit more robust by retrying the
execution if the plugin is in text file busy state. This can happen if
we write the config and the plugin at once. To avoid such races we now
try up to 5 seconds for the plugin validation.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-04-16 09:11:52 +02:00
Adrian Chiris 76b18ea294 Typo fixes for infiniband GUID
- Remove underscore in the Area description of the entry
- Modify the capability name to be camelCase instead of underscores
  to be consistent with other capabilities (e.g `portMappings`, `ipRanges`)

As there was no CNI released and no implementations of this capability
(That i know of) i reckon we can do the attribute name adjustment.

Signed-off-by: Adrian Chiris <adrianc@mellanox.com>
2020-04-16 10:08:07 +03:00
Casey Callendrello bf84331c94
Merge pull request #761 from adrianchiris/device-id_runtime_conf
Add DeviceID attribute to RuntimeConfig
2020-04-08 17:33:34 +02:00
Michael C. Cambria 7d9ec90bff
Merge pull request #760 from dcbw/really-return-stderr
invoke: capture and return stderr if plugin exits unexpectedly
2020-04-08 11:32:44 -04:00
Dan Williams 44dabed6ce invoke: capture and return stderr if plugin exits unexpectedly
The way raw_exec invokes the command doesn't actually pass back
stderr, despite ExitError having that capability.  c.Run()
internally calls c.Wait() but that doesn't capture stderr and
insert it into the returned ExitError. So we have to do that
ourselves.

Fixes: https://github.com/containernetworking/cni/issues/732
Fixes: https://github.com/containernetworking/cni/pull/759

Signed-off-by: Dan Williams <dcbw@redhat.com>
2020-04-08 09:29:41 -05:00
Adrian Chiris 279bc6c21b Add DeviceID attribute to RuntimeConfig
This commit attempts to standardize the consumption
of a device identifier by CNI's for networks that
is associated with a device resource and require its
identifier to perform configurations.

Signed-off-by: Adrian Chiris <adrianc@mellanox.com>
2020-04-08 12:42:13 +03:00
Dan Williams fdcc7b15d7 test: allow specific package testing with PKGS=<x> ./test.sh
Signed-off-by: Dan Williams <dcbw@redhat.com>
2020-04-01 11:52:44 -05:00
Dan Williams cf734d46be
Merge pull request #742 from adrianchiris/master
Add GUID to well known Capabilities
2020-04-01 09:22:49 -05:00
Adrian Chiris ca0082f790 Add Infiniband GUID to well known Capabilities
This commit extends CONVENTION.md Well-known Capabilities
to include `infiniband_guid`. this shall be used by CNI plugins
who wish to set Infiniband GUID address for a network interface.

Change-Id: I3716e0a9ea660937a73feee00ea9c5b1a92ab478
Signed-off-by: Adrian Chiris <adrianc@mellanox.com>
2020-03-12 17:41:08 +02:00
Dan Williams 4fae32b849
Merge pull request #755 from libesz/fix-conflist-samples
Remove extra ',' chars which makes conflist examples invalid.
2020-03-04 10:16:08 -06:00
Gergo Huszty 38353fabbb Remove extra ',' chars which makes conflist examples invalid.
Signed-off-by: Gergo Huszty <gergo.huszty@ibm.com>
2020-02-28 15:18:06 +01:00
Dan Williams 56ace59a9e
Merge pull request #752 from dcbw/maintainers-remove-stefan
maintainers: remove Stefan per personal request
2020-02-19 10:46:25 -06:00
Dan Williams 134f603c67 maintainers: remove Stefan per personal request
We contacted Stefan and he said he could be dropped as a CNI maintainer.

Signed-off-by: Dan Williams <dcbw@redhat.com>
2020-02-19 10:28:21 -06:00
Piotr Skamruk c252795066
Merge pull request #751 from dcbw/mcambria-maintainer
Add Michael Cambria as a CNI maintainer
2020-02-13 11:05:30 +01:00
Dan Williams 1435c6bddb Add Michael Cambria as a CNI maintainer
Signed-off-by: Dan Williams <dcbw@redhat.com>
2020-02-12 10:11:19 -06:00
Piotr Skamruk f69d1f2cab
Merge pull request #745 from truongnh1992/insert_link
Update link freenode.org to freenode.net
2020-01-30 11:15:46 +01:00
Nguyen Hai Truong 6b46a03d2b Update link freenode.org to freenode.net
The domain freenode.org is no longer up-to-date,
use freenode.net instead

Signed-off-by: Nguyen Hai Truong <truongnh@vn.fujitsu.com>
2020-01-30 16:30:46 +07:00
Bryan Boreham 0adeb0ed54
Merge pull request #744 from containernetworking/update-1-0-roadmap
Update roadmap for 1.0 plans
2020-01-29 16:54:22 +00:00
Bryan Boreham 075e303ba8 Update roadmap for 1.0 plans
Signed-off-by: Bryan Boreham <bryan@weave.works>
2020-01-29 16:20:26 +00:00
Bryan Boreham d0fd3ff4e9
Merge pull request #583 from jellonek/resultasstring
Update Result.String implementation to work as declared in interface
2020-01-22 16:31:49 +00:00
Bryan Boreham c2b68cd595
Merge pull request #738 from mars1024/black-box-testing
pkg/utils: utility package should use black-box testing
2020-01-22 16:31:07 +00:00
Bryan Boreham 5c2bade00b
Merge pull request #740 from gavinfish/json_comments
Change language identifier to jsonc for json with comments
2020-01-19 19:01:04 +00:00
gavinfish 0b1c6497ed Change language identifier to jsonc for json with comments
Signed-off-by: gavinfish <drfish.me@gmail.com>
2020-01-17 13:59:17 +08:00
Piotr Skamruk 704c56d291 Update tests
Signed-off-by: Piotr Skamruk <piotr.skamruk@gmail.com>
2020-01-15 12:26:12 +01:00
Piotr Skamruk f208f19fd3 Remove Result.String
Closes #581

Signed-off-by: Piotr Skamruk <piotr.skamruk@gmail.com>
2020-01-15 12:26:12 +01:00
Bruce Ma cc6e8afa5a pkg/utils: utility package should use black-box testing
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2020-01-10 20:36:12 +08:00
Dan Williams a09ec7a992
Merge pull request #736 from q384566678/add-utils-test
pkg/utils: add utils_test
2020-01-08 10:22:03 -06:00
Piotr Skamruk 6680f870ab
Merge pull request #735 from zjj2wry/intercepte-stderr
intercept netplugin std error
2020-01-08 17:12:57 +01:00
Zhou Hao 025e32f89e pkg/utils: add utils_test
Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>
2019-12-27 11:32:54 +08:00
郑佳金 6f29b01658 intercept netplugin std error
Signed-off-by: 郑佳金 <zhengjiajin2016@gmail.com>
Signed-off-by: 郑佳金 <zhengjiajin2016@gmail.com>
2019-12-19 14:08:13 +08:00
Bryan Boreham 4c077d2fec
Merge pull request #730 from oilbeater/add-kube-ovn
Add Kube-OVN to CNI list
2019-12-11 16:08:43 +00:00
Bryan Boreham d65360849f
Merge branch 'master' into add-kube-ovn 2019-12-11 16:08:22 +00:00
Casey Callendrello 340972aad4
Merge pull request #731 from yasensim/master
Add Project Antrea in CNI list
2019-12-11 17:07:30 +01:00
oilbeater 777584fb17 Add Kube-OVN to CNI list
Signed-off-by: oilbeater <liumengxinfly@gmail.com>
2019-12-05 14:24:05 +08:00
Bryan Boreham 7aed59f421
Merge pull request #727 from rktidwell/master
DOCUMENTATION: Address incomplete instructions in CONTRIBUTING.md
2019-12-04 16:34:45 +00:00
Dan Williams dce771e2a0
Merge pull request #725 from containernetworking/new-maintainers
Add Bruce Ma and Piotr Skarmuk as maintainers
2019-12-04 10:09:07 -06:00
yasensim e00fa533de appending antrea to the cni list
Signed-off-by: yasensim <yasensim@gmail.com>
2019-12-03 20:45:50 -08:00
yasensim 7815be7f0a Add Project Antrea in CNI list
Signed-off-by: yasensim <yasensim@gmail.com>
2019-12-02 17:27:29 -08:00
Matt Dupre dcb71ae8c9
Merge pull request #729 from weibeld/master
Add table of contents to SPEC.md
2019-11-27 11:39:56 -05:00
Daniel Weibel f2fa4a3fa0 Add table of contents
Generated wit markdown-toc:

markdown-toc --no-firsth1 --maxdepth=2 SPEC.md

Signed-off-by: Daniel Weibel <danielmweibel@gmail.com>
2019-11-26 19:37:48 +08:00
Ryan Tidwell b36de6e00b
DOCUMENTATION: Address incomplete instructions in CONTRIBUTING.md
This change addresses a few missing steps and out-of-date items in the
contributor docs such as fetching proper dependencies and removing
references to paths that no longer exist.

Fixes #726

Signed-off-by: Ryan Tidwell <rtidwell@suse.com>
2019-11-25 09:34:48 -06:00
Bryan Boreham ade6ad342d
Merge pull request #728 from noironetworks/cisco-cni
Adding Cisco ACI to CNI plugin list
2019-11-25 12:26:09 +00:00
Sumit Naiksatam c35ac21f14 Adding Cisco ACI to CNI plugin list
Signed-off-by: Sumit Naiksatam <sumitnaiksatam@gmail.com>
2019-11-22 10:36:38 -08:00
Bryan Boreham 3eb88acd2a Add Bruce Ma and Piotr Skarmuk as maintainers
Signed-off-by: Bryan Boreham <bryan@weave.works>
2019-11-16 11:45:09 +00:00
Bryan Boreham 46b9d6fa20
Merge pull request #724 from squeed/readme-update
Update README to sunset slack and call out kubecon presentations
2019-11-13 19:28:37 +00:00
Casey Callendrello 6c6a3156c3 Update README to sunset slack and call out kubecon presentations
Signed-off-by: Casey Callendrello <cdc@redhat.com>
2019-11-13 17:36:00 +01:00
Piotr Skamruk c2508f1804
Merge pull request #722 from containernetworking/note-binaries
Add a note to README about where to find the binaries
2019-11-07 12:41:35 +01:00
Bryan Boreham b89eff5321 Add a note to README about where to find the binaries
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2019-11-06 16:56:52 +00:00
Dan Williams 2d4bc3d57a
Merge pull request #721 from mccv1r0/issue720
When CNI version isn't supplied in config, use default.
2019-10-16 11:11:06 -05:00
Michael Cambria 4eec64802d When the CNI version isn't supplied in config, use default.
Signed-off-by: Michael Cambria <mccv1r0@gmail.com>
2019-10-16 11:20:00 -04:00
Bryan Boreham 63202159f1
Merge pull request #712 from mars1024/modify/ifname_validation
add interface name validation
2019-10-09 16:15:59 +01:00
Bruce Ma eefc06974c SPEC: update validation rules for interface name in docs and address some comments
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-10-08 12:01:17 +08:00
Piotr Skamruk 904ce461b0
Merge pull request #715 from mars1024/typo/spec
spec: fix some typo in docs
2019-10-03 22:07:54 +02:00
Dan Williams 8f2d48e6e1
Merge pull request #716 from yuxiaobo96/cni-update3
Correct word spelling mistakes
2019-10-02 10:17:22 -05:00
Bruce Ma b5188cf64f spec: fix some typo in docs
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-09-29 14:11:31 +08:00
yuxiaobo c94fcd742c Perfect annotation: Correct word spelling mistakes
Signed-off-by: yuxiaobo <yuxiaobogo@163.com>
2019-09-26 15:34:44 +08:00
Bryan Boreham 02a25a7635
Merge pull request #713 from janisz/patch-1
Bump golang
2019-09-25 16:08:28 +01:00
Piotr Skamruk 15d37883e6
Merge pull request #710 from hwdef/add-err-handle-p/t/noop
add err handling in plugins/test/noop/
2019-09-24 18:46:20 +02:00
Bruce Ma 7be1ac932d add interface name validation to libcni and skel
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-09-20 11:30:22 +08:00
Bruce Ma 9f4a623222 utils: add validation function for interface name
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-09-20 11:29:05 +08:00
janisz 2a82881b00
Bump golang
Refs:
* https://github.com/containernetworking/plugins/pull/386
* https://golang.org/doc/go1.13

Signed-off-by: Tomasz Janiszewski <janiszt@gmail.com>
2019-09-19 10:15:35 +02:00
Casey Callendrello bd4e822851
Merge pull request #711 from johscheuer/update-cnitool-docs
Update cnitool docs
2019-09-18 14:21:55 +02:00
Johannes M. Scheuermann c0f784d16d Update cnitool docs
Signed-off-by: Johannes M. Scheuermann <joh.scheuer@gmail.com>
2019-09-17 21:45:26 +02:00
hwdef 94399d569c add err handling in plugins/test/noop/
Signed-off-by: hwdef <hwdef97@gmail.com>
2019-09-13 01:30:09 +08:00
Piotr Skamruk 83439463f7
Merge pull request #704 from dcbw/cache-ifname
libcni: also cache IfName
2019-09-04 17:32:31 +02:00
Bryan Boreham bd64c46461
Merge pull request #698 from mccv1r0/issue679
validate containerID and networkName
2019-09-04 16:29:24 +01:00
Dan Williams 9d4429ded4
Merge pull request #705 from dcbw/fix-cache-result-key
libcni: fix cache file 'result' key name
2019-09-04 10:18:19 -05:00
Michael Cambria d8dfb56fd8 validate containerID and networkName
ensure they contain only letters and numbers
2019-09-03 17:54:22 -04:00
Dan Williams e4a11bae33 libcni: cache file operations require full uniqueness tuple in RuntimeConf
We can't generate a cache file path without all of network name,
container ID, and interface name in the RuntimeConf. They should
be there already anyway (otherwise errors will occur) but we should
return those errors earlier.
2019-09-03 11:19:18 -05:00
Dan Williams a83f3cb0f4 libcni: also cache IfName, network name, and container ID
We should have all components of the uniqueness tuple in the cache file
so that they can be read out of the file without trying to parse the
cache file name.
2019-09-03 10:04:18 -05:00
Dan Williams 894863c200 libcni: fix cache file 'result' key name 2019-08-29 20:39:33 -05:00
Dan Williams 13b6ad6447
Merge pull request #699 from mars1024/cleanup/skel
skel: remove needless functions and types
2019-08-21 10:26:33 -05:00
Bruce Ma f3654f3d2d skel: remove needless functions and types
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-08-16 18:18:23 +08:00
Dan Williams 8c6c47d1c7
Merge pull request #686 from mars1024/cleanup/skel_error
skel: clean up errors in skel and add some well-known error codes
2019-08-07 10:13:50 -05:00
Bruce Ma 3e79703c66 modify some well-known errors
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-08-01 11:21:26 +08:00
Dan Williams d19c2358a5
Merge pull request #691 from mars1024/docs/add_some_capabilities
docs: add ips and mac to well-known capabilities and fix some typo
2019-07-25 11:11:49 -05:00
Dan Williams d34f7f4ead
Merge pull request #692 from mars1024/bugfix/validatePlugin
libcni: find plugin in exec
2019-07-25 11:11:35 -05:00
Bruce Ma 1318d7c94c libcni: find plugin in exec
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-07-25 10:16:23 +08:00
Piotr Skamruk df124b22e4
Merge pull request #678 from mccv1r0/pr661
libcni: add config caching [v2]
2019-07-20 11:32:07 +02:00
Michael Cambria 9af40ed73a libcni: add config caching
Cache the config JSON, CNI_ARGs, and CapabilityArgs on ADD operations,
    and remove them on DEL. This allows runtimes to retrieve the cached
    information to ensure that the pod is given the same config and options
    on DEL as it was given on ADD.

    Add versioning to beginning of cache file
    Combine cached configuration and results into one file

Signed-off-by: Michael Cambria <mcambria@redhat.com>
2019-07-19 17:49:42 -04:00
Casey Callendrello 461cf2b48f
Merge pull request #690 from BSWANG/master
readme: add Alibaba Cloud CNI plugin 'Terway' to the list
2019-07-17 11:20:17 -04:00
Casey Callendrello b2c510b758
Merge pull request #689 from rosenhouse/bump-linux-version
bump linux to Bionic 18.04 in Travis and Vagrant
2019-07-17 11:12:12 -04:00
Bruce Ma 722a488070 docs: add ips and mac to well-known capabilities and fix some typo
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-07-16 22:50:35 +08:00
Bruce Ma 227c438835 SPEC: add some well-known error codes
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-07-15 22:50:17 +08:00
Bruce Ma ba034ef5da testcases: make testcase use suitable error code
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-07-15 22:33:23 +08:00
Bruce Ma 4b29940c46 skel: clean up typed Errors in skel
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-07-15 21:36:18 +08:00
Bruce Ma 50192c0c4c types : add NewError method
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-07-15 20:04:01 +08:00
bingshen.wbs 0af0477c17 readme: add Alibaba Cloud CNI plugin 'Terway' to the list
Signed-off-by: bingshen.wbs <bingshen.wbs@alibaba-inc.com>
2019-07-11 13:55:48 +08:00
Gabe Rosenhouse b92d83cb59 bump linux to Bionic 18.04 in Travis and Vagrant 2019-07-10 08:32:50 -07:00
Dan Williams 220a58f522
Merge pull request #688 from dholbach/patch-1
add missing comma, fixes syntax error
2019-07-10 10:03:39 -05:00
Daniel Holbach a48337ac26 add missing commas, fix syntax error
Bryan spotted the second one - well spotted
2019-07-05 11:39:39 +02:00
Matt Dupre dc71cd2ba6
Merge pull request #681 from mars1024/clean_up
clean up : fix staticcheck warnings
2019-07-03 16:03:56 +01:00
Michael Cambria 5077b14734 Add stringifyArgs and parseArgs functions to utils.go
Signed-off-by: Michael Cambria <mcambria@redhat.com>
2019-06-28 11:56:55 -04:00
Dan Williams ef03d0458c
Merge pull request #682 from dcbw/cachedir
libcni: add InitCNIConfigWithCacheDir() and deprecate RuntimeConfig.CacheDir
2019-06-26 08:03:07 -05:00
Dan Williams 80ad241eb6 libcni: add InitCNIConfigWithCacheDir() and deprecate RuntimeConfig.CacheDir
CacheDir is a property of the entire CNIConfig object and there is no
point to having it be different between container invocations. It was
originally put in RuntimeConfig to make re-vendoring easier so that
users wouldn't have to update calls to InitCNIConfig.
2019-06-20 09:39:25 -05:00
Bruce Ma 5dbeae87ff clean up : remove useless variable
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-06-19 23:53:31 +08:00
Bruce Ma a03dc28d25 clean up : fix staticcheck warnings
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-06-19 19:45:29 +08:00
Casey Callendrello dc953e2fd9
Merge pull request #668 from adelina-t/patch-1
Docs: Small typo fixes in main README.md
2019-06-12 17:24:20 +02:00
Casey Callendrello 4cfb7b5689
Merge pull request #663 from mars1024/modify/cniargs_for_delegate
delegate : allow delegation funcs override CNI_COMMAND env automatically in heritance
2019-06-05 17:31:12 +02:00
Dan Williams 33bb6067c0
Merge pull request #672 from dcbw/go-v1.12
Release: bump go to v1.12
2019-06-03 08:52:59 -05:00
Dan Williams e3a51e54fd Release: bump go to v1.12 2019-05-29 11:32:55 -05:00
Dan Williams d11ef1fb4e
Merge pull request #669 from mccv1r0/gnlcached
Add GetNetworkListCachedResult method to CNI interface
2019-05-29 10:30:36 -05:00
Michael Cambria 53e9245e7b add GetNetworkListCachedResult to CNI interface 2019-05-17 11:59:05 -04:00
Bruce Ma 1475a6e3c0 add some testcases for invoke/args
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-05-16 17:14:00 +08:00
Bruce Ma e67d6cba0f delegate : allow delegation funcs override CNI_COMMAND env automatically in heritance
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-05-16 16:49:18 +08:00
Bryan Boreham 5bab2c0253
Merge pull request #662 from mars1024/bugfix/cniargs_override
invoke : ensure custom envs of CNIArgs are prepended to process envs
2019-05-15 16:51:49 +01:00
Adelina Tuvenie cbca75246a Docs: Small typo fixes in main README.md 2019-05-15 18:29:54 +03:00
Dan Williams a94ff7bdaf
Merge pull request #666 from s1061123/add_route_override
Add cni-route-override to CNI plugin list
2019-05-15 10:27:46 -05:00
Tomofumi Hayashi 0469a05ab5 Add cni-route-override to CNI plugin list 2019-05-09 15:36:31 +09:00
Bruce Ma e40cce2373 add deduplication in return of CNIArgs
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-05-09 13:57:16 +08:00
Bruce Ma ea274f7629 ensure custom envs of CNIArgs are prepended to process envs
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
2019-05-05 12:34:14 +08:00
Dan Williams f726df9103
Merge pull request #659 from Colstuwjx/cnitool-check-example
Upgrade to cni spec v0.4.0.
2019-05-01 10:05:57 -05:00
Colstuwjx ffc61ed2d3 Upgrade to cni spec v0.4.0. 2019-04-29 18:20:30 +08:00
Casey Callendrello 7d76556571
Merge pull request #658 from squeed/bump-spec-040
SPEC: add references to spec version 0.4.0
2019-04-26 18:00:55 +02:00
Casey Callendrello c47f15614b SPEC: add references to spec version 0.4.0 2019-04-26 14:04:09 +02:00
Dan Williams ec5ec68fa4
Merge pull request #655 from danwinship/error-no-error
Return a better error when the plugin returns none
2019-04-17 10:22:34 -05:00
Dan Williams 530eed4d27
Merge pull request #651 from SataQiu/fix-spell-20190404
Fix some spell errors
2019-04-15 16:45:14 -05:00
Dan Williams 121ab0058f
Merge pull request #652 from SataQiu/fix-link-20190409
Make link point to the correct version
2019-04-15 16:44:47 -05:00
Dan Williams de8cf72507
Merge pull request #653 from SataQiu/fix-spell-error
Fix spell error for configuration json
2019-04-15 16:44:03 -05:00
Dan Winship 59d8d02f67 Return a better error when the plugin returns none 2019-04-12 14:19:01 -04:00
SataQiu 8361cffee2 make link point to the correct version 2019-04-09 17:46:58 +08:00
SataQiu 4461d54929 fix spell error for configuration json 2019-04-09 17:09:24 +08:00
SataQiu 207be7e31e fix some spell errors 2019-04-04 23:36:59 +08:00
Bryan Boreham 0471e018e5
Merge pull request #647 from xichengliudui/fix404notfound
update spec-upgrades.md make it point to a specific web page
2019-04-03 17:02:41 +01:00
Dan Williams c9c5031a1b
Merge pull request #650 from xichengliudui/patch-2
Fix 404 not found
2019-04-03 10:05:58 -05:00
lIuDuI 6bddfcd3bb
Fix 404 not found 2019-03-30 19:09:43 +08:00
Dan Williams fbb95fff8a
Merge pull request #597 from dcbw/conventions-ip-prefix
CONVENTIONS: add support for IP prefixes
2019-03-20 10:58:02 -05:00
Matt Dupre f7e07eec38
Merge pull request #622 from trungnvfet/fix_http_https
Change http to https for security links
2019-03-20 15:52:47 +00:00
Bryan Boreham c976b421df
Merge pull request #627 from longkb/update_deprecated_link
Update deprecated link in doc
2019-03-20 15:51:05 +00:00
Dan Williams 139f460f90
Merge pull request #632 from hnwolf/fix_removed_document_link
Remove incorrect document link
2019-03-20 10:49:31 -05:00
Dan Williams fe0a28d82a
Merge pull request #639 from nagiesek/dnsCapabilityUpdate
Update conventions.md to include dns capability
2019-03-20 10:48:37 -05:00
Dan Williams 2c4013efcd
Merge pull request #621 from truongnh1992/fix-typo
doc: fix typo
2019-03-20 10:43:25 -05:00
Dan Williams 0dba47b1f9
Merge pull request #641 from dcbw/spec-clarify-routes
SPEC.md: clarify meaning of 'routes'
2019-03-20 10:41:23 -05:00
Dan Williams 4554856998 SPEC.md: clarify meaning of 'routes'
Routes are expected to be relevant to the sandbox interface.
2019-03-20 10:38:40 -05:00
Dan Williams f4fdaa2304
Merge pull request #617 from luksa/convert_from_020_gw
Don't copy gw from IP4.Gateway to Route.GW When converting from 0.2.0
2019-03-20 10:35:18 -05:00
1693291525@qq.com f55f75bf0e update spec-upgrades.md 2019-03-20 02:24:27 -04:00
Marko Lukša 83ed2459f7 Add tests provided by Dan Williams (@dbcw) 2019-03-15 10:04:20 +01:00
Marko Lukša 16d174d296 Don't copy gw from IP4.Gateway to Route.GW When converting from 0.2.0
When converting from 0.2.0 to 0.3.x, we used to copy the Gateway defined
under IP4.Gateway to each route that had GW set to nil. This is wrong
because the result of converting from 0.2.0 to 0.3.x and back to 0.2.0
doesn't match the original config.

Also, the spec says the following about routes.gw: "IP of the gateway.
If omitted, a default gateway is assumed (as determined by the CNI
plugin)."

So, it should be up to the CNI plugin to determine what to do when the
gateway in a route isn't specified. Therefore, when converting from
0.2.0 to 0.3.x, we should NOT populate the gateway field.
2019-03-15 10:01:46 +01:00
Kim Bao Long f00ca5f42b Update deprecated link in doc
Currently, the modified **plugins/main** was removed from master branch.
It's only available in **v0.3.0** tag. So this commit aims to update the
deprecated link to the working one.

Signed-off-by: Kim Bao Long <longkb@vn.fujitsu.com>
2019-03-14 08:13:14 +07:00
Casey Callendrello 6896907ab4
Merge pull request #626 from opensvc/arnaudveron-opensvc-addon
Add OpenSVC to the list of container runtimes
2019-03-13 16:42:41 +01:00
Casey Callendrello 3d19d747b6
Merge pull request #635 from longkb/remove_the_deprecated_links
Remove deprecated link in SPEC.md
2019-03-13 16:17:05 +01:00
Dan Williams 203f70b6bb
Merge pull request #636 from andrey-ko/result-print-to
add PrintTo method to Result interface
2019-03-13 10:14:36 -05:00
Dan Williams 2e00c58a3b
Merge pull request #637 from ajacoutot/typo
invoke: fix typo (opensbd -> openbsd)
2019-03-13 10:11:52 -05:00
Nathan Gieseker 5761cff2ef Update conventions.md to include dns capability 2019-03-12 21:44:55 -07:00
Antoine Jacoutot b3342a6e36 invoke: fix typo (opensbd -> openbsd) 2019-02-28 10:06:17 +01:00
akolomentsev 667a69ea9d add PrintTo method to Result interface, in order to allow to marshal result to any writer, not only stdout
Signed-off-by: Andrey Kolomentsev <andrey.kolomentsev@gmail.com>
2019-02-27 20:13:32 -08:00
Nguyen Hung Phuong b69a8d52b6 Remove incorrect document link 2019-02-26 08:39:29 +07:00
Kim Bao Long 8574263c4e Remove deprecated link in SPEC.md
Current, the URLs that link docs of **rkt_networking_proposal** and
**rkt_networking_design** are already dead. So this commit aims to
clean up them from **SPEC.md**.

Co-Authored-By: Nguyen Phuong An <AnNP@vn.fujitsu.com>
Signed-off-by: Kim Bao Long <longkb@vn.fujitsu.com>
2019-02-25 11:22:43 +07:00
Arnaud Veron b1838c7f90
Add OpenSVC to the list of container runtimes 2019-02-21 15:49:41 +01:00
Nguyen Hai Truong f36276e1bc doc: fix typo
Although it is spelling mistakes, it might make
affects while reading.

Signed-off-by: Nguyen Hai Truong <truongnh@vn.fujitsu.com>
2019-02-20 20:11:01 -08:00
Matt Dupre 8fa373b4fd
Merge pull request #624 from annp1987/remove_duplicate_worlds
Remove duplicate word 'the the'.
2019-02-20 16:30:19 +00:00
Matt Dupre 405805692c
Merge pull request #625 from huynq0911/fix_http_https
Change http to https for security links
2019-02-20 16:29:46 +00:00
Nguyen Quang Huy c96f9d1d95 Change http to https for security links
For security, we should change http into https links.
2019-02-20 15:07:48 +07:00
Nguyen Phuong An 5ba9bb8fa0 Remove duplicate word 'the the'.
Signed-off-by: Nguyen Phuong An <AnNP@vn.fujitsu.com>
2019-02-20 13:56:29 +07:00
Nguyen Van Trung ab0ee6fa98 Change http to https for security links
Signed-off-by: Nguyen Van Trung <trungnv@vn.fujitsu.com>
2019-02-15 10:18:04 +07:00
Bryan Boreham 7aacc67f18
Merge pull request #619 from annp1987/master
Use /usr/bin/env bash in shebang for docker-run.sh
2019-02-13 16:57:51 +00:00
Nguyen Phuong An bfcd424c0e Use /usr/bin/env bash in shebang for docker-run.sh 2019-02-13 15:26:08 +07:00
Bryan Boreham 51885a9b69
Merge pull request #618 from SchSeba/small_fix
Fix cnitool readme
2019-02-07 17:16:36 +00:00
Sebastian Sch c9bc5b79ec Fix cnitool readme.
build.sh script doesn't exist anymore change to build_linux.sh or
build_windows.sh
2019-02-07 12:18:41 +02:00
Dan Williams 8e8abe455b
Merge pull request #616 from JoeWrightss/patch-4
Fix some typos in SPEC.md
2019-02-06 10:15:30 -06:00
Bryan Boreham 4425e7e337
Merge pull request #615 from squeed/update-maint
Update Casey's email address.
2019-01-31 14:47:32 +00:00
Casey Callendrello 93bfd62fb1 Update Casey's email address. 2019-01-31 15:26:25 +01:00
zhoulin xie 06b37e1ff5 Fix some typos in SPEC.md
Signed-off-by: zhoulin xie <zhoulin.xie@daocloud.io>
2019-01-31 22:25:12 +08:00
Dan Williams 0cf415d434
Merge pull request #613 from bradmbock/add-vmwnsx-cni
Added VMware NSX CNI plugin to CNI plugin list.
2019-01-30 10:33:20 -06:00
Dan Williams 0126b26304
Merge pull request #614 from yeya24/patch/fixtypo
fix some typos
2019-01-30 10:05:05 -06:00
yeya24 afdc49d0a6 fix some typos 2019-01-29 22:55:01 +08:00
Bradley Bock d6ffc8d74f Added VMware NSX CNI plugin to CNI plugin list. 2019-01-28 14:17:37 -08:00
Bryan Boreham 762bb8ae5d
Merge pull request #602 from liucimin/fix_version_ParseVersion_function
fix the ParseVersion when the version is  will get fnAtoi
2019-01-23 16:29:37 +00:00
Matt Dupre 1c35013cf4
Merge pull request #612 from JoeWrightss/patch-3
Fix some typos in comment
2019-01-23 16:07:50 +00:00
zhoulin xie ce8938617e Fix some typos in comment
Signed-off-by: zhoulin xie <zhoulin.xie@daocloud.io>
2019-01-17 19:38:40 +08:00
Casey Callendrello ce46ad0130
Merge pull request #609 from containernetworking/community-20190130
Announce next community meeting in Jan 2019
2019-01-09 21:41:49 -08:00
Bryan Boreham b74b969c00 Announce next community meeting in Jan 2019
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2019-01-09 16:34:24 +00:00
Dan Williams e2bdb13345
Merge pull request #607 from rst0git/master
readme: Update CNI plugins install example
2019-01-09 09:52:05 -06:00
liucimin 94bf13891a fix the ParseVersion when the version is will get fnAtoi 2018-12-25 14:31:39 +08:00
Radostin Stoyanov d6ed2fd5a3 readme: Update CNI plugins install example
Commit containernetworking/plugins@4e1f780 (Split build.sh into two
OS-specific scripts) removes the build.sh file. Now we have
build_linux.sh and build_windows.sh

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2018-12-20 21:53:17 +00:00
Casey Callendrello 213b3fdea2
Merge pull request #600 from nak3/valid-args-num
Validate correct number of args in cnitool
2018-12-19 11:51:28 -05:00
Dan Williams b7ae50cbb4
Merge pull request #604 from JoeWrightss/patch-1
Fix some typos
2018-12-19 10:40:27 -06:00
Dan Williams 3de1875e27
Merge pull request #603 from containernetworking/bboreham-patch-1
Update roadmap with change from GET to CHECK
2018-12-19 10:40:04 -06:00
JoeWrightss 3a3a701be0 Fix some typos
Signed-off-by: JoeWrightss <zhoulin.xie@daocloud.io>
2018-12-07 23:19:51 +08:00
Bryan Boreham 34a6112b3b
Update roadmap with change from GET to CHECK 2018-12-06 12:42:47 +00:00
Kenjiro Nakayama 3d6117d63e Validate correct number of args in cnitool
Currently, cnitool command needs 4 args - e.g cnitool add <net>
<netns>. This patch changes to the number of valide args to 4 from 3.
2018-11-29 17:20:24 +09:00
Dan Williams 66dafdf3e9 CONVENTIONS: add support for IP prefixes
While many plugins already have IPAM range info not all do. Without
a range/subnet in configuration, passing a plain IP address in
CNI_ARGS or via 'args' does not provide enough information.
2018-11-28 16:04:33 -06:00
Dan Williams fdcc5db51b
Merge pull request #596 from nak3/update-go-version
Update supported Go version statement
2018-11-28 10:08:47 -06:00
Kenjiro Nakayama 297457de48 Update supported Go version statement 2018-11-28 16:13:03 +09:00
Dan Williams dba13c4822
Merge pull request #593 from Levovar/add_danm
README: expands list of 3rd party plugins with DANM
2018-11-14 10:12:16 -06:00
Levente Kale c744c26d2e README: expands list of 3rd party plugins with a new option
DANM -a K8s networking solution using CNI- was recently made opensource.
PR expands the list of 3rd party plugins with the reference to the project.
2018-11-10 13:19:32 +01:00
Dan Williams 951c0fb806
Merge pull request #592 from rosenhouse/bump-to-go-1.11
bump travis and vagrantfile to go 1.11
2018-11-07 09:28:20 -06:00
Gabe Rosenhouse b271ce351d bump travis and vagrantfile to go 1.11 2018-10-31 08:39:54 -07:00
Dan Williams 47f042a96e
Merge pull request #590 from containernetworking/move-del-text
Move spec text about DEL and errors
2018-10-31 10:33:24 -05:00
Bryan Boreham a8a44a721a
Merge pull request #591 from containernetworking/eagain
Add a well-known error for "try again"
2018-10-28 18:18:44 +02:00
Bryan Boreham cc562d1b44 Add a well-known error for "try again" 2018-10-17 15:37:38 +00:00
Bryan Boreham 24aa1f4030 Move spec text about DEL and errors
This paragraph was under a heading specifically about configuration
lists, but it applies to all DEL operations whether in a list or not.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2018-10-17 15:31:04 +00:00
Dan Williams 1dba71945f
Merge pull request #588 from GodloveD/add-singularity-to-readme
Added Singularity to the README.md.
2018-10-17 10:25:04 -05:00
GodloveD f301e8fe68 Added Singularity to the README.md. It began supporting cni in 3.0. 2018-10-09 17:08:42 -04:00
Dan Williams 777324ca6b
Merge pull request #584 from dcbw/get-to-check
skel,invoke,libcni: GET -> CHECK
2018-09-26 11:43:02 -05:00
Dan Williams df75bcfdbe libcni: caching should use new uniqueness tuple (netname, containerid, ifname) 2018-09-26 11:41:14 -05:00
Dan Williams 89d8d97746 types,libcni: implement DisableCheck 2018-09-26 11:20:47 -05:00
Dan Williams 68c963649f libcni: add GetNetwork[List]CachedResult
Now that GET no longer exists and no longer returns the
cached result, provide a public method to return the cached
result that runtimes can use.
2018-09-26 11:03:05 -05:00
Dan Williams 42e857f0a2 skel,invoke,libcni: GET -> CHECK
Major change is that CHECK no longer returns a Result, per the spec.
2018-09-26 10:51:49 -05:00
Dan Williams f145359def
Merge pull request #568 from liucimin/feature_exec_timeout
libcni/invoke: add context argument to enable cancelation and timeouts
2018-09-26 10:19:17 -05:00
liucimin c5ab1c3fc6 add the timeout context 2018-09-25 09:52:59 +08:00
Dan Williams 7418eded11
Merge pull request #587 from mccv1r0/cnitool
cnitool: Honor interface name supplied via CNI_IFNAME environment variable.
2018-09-24 16:13:51 -05:00
Michael Cambria 626458fb67 gofmt needed 2018-09-24 14:51:38 -04:00
Michael Cambria 01eda4e0cf Use interface name supplied via CNI_IFNAME environment variable, when set. Default to eth0 otherwise 2018-09-24 13:29:28 -04:00
Dan Williams 93b8b11111
Merge pull request #579 from matthewdupre/check-spec
Replace GET action in spec with proposed CHECK action
2018-09-12 10:55:48 -05:00
Casey Callendrello d59bfbf33e SPEC: CHECK: clarify difference between "tracked" and "non-tracked" resources 2018-09-12 17:13:07 +02:00
Gabe Rosenhouse 47cf2da00b
Merge pull request #578 from lifubang/loopback020
when type is loopback, IP4 or IP6 is always nil
2018-08-22 08:22:31 -07:00
Matt Dupre 57da9a82b0 Have GET action not return anything on success 2018-08-22 15:37:56 +01:00
Matt Dupre 97b1f58534 Replace GET action in spec with proposed CHECK action 2018-08-15 15:46:46 +01:00
Lifubang 5ef0e9aa4c when loopback, IP4 or IP6 is always nil
Signed-off-by: Lifubang <lifubang@aliyun.com>
2018-08-13 18:50:23 +08:00
Dan Williams 779dc12496
Merge pull request #570 from dcbw/prev-result-helpers
types/version: add helper to parse PrevResult
2018-08-09 13:33:51 -05:00
Dan Williams d2836a7b59 types/version: add helper to parse PrevResult
Plugins can use the new helpers to parse a prevResult.  When parsing
their NetConf structure, assuming it has a types.NetConf embedded:

  type MyConf struct {
    types.NetConf
    ...
  }

  conf := MyConf{}
  if err := json.Unmarshal(stdin, &conf); err != nil {
    return nil, fmt.Errorf("failed to parse network configuration: %v", err)
  }

  if err := version.ParsePrevResult(&conf.NetConf); err != nil {
    return nil, err
  }

and then when the plugin wishes to access the PrevResult it can transform
conf.PrevResult into any Result version it wants:

  if conf.PrevResult != nil {
    res, err := current.NewResultFromResult(conf.PrevResult)
    if err != nil {
      return nil, fmt.Errorf("could not convert result to current version: %v", err)
    }
    for _, ip := range res.IPs {
      ...
    }
  }
2018-08-09 13:27:57 -05:00
Dan Williams cbd2718984
Merge pull request #572 from dcbw/skel-about
skel: only print about message, not errors
2018-08-08 10:46:45 -05:00
Dan Williams 9c9cc5365d
Merge pull request #574 from xiangpengzhao/add-knitter
List Knitter as 3rd party plugin
2018-08-08 10:32:51 -05:00
Dan Williams 0750650021
Merge pull request #576 from acmcodercom/master
Add name field in 99-loopback.conf because network name is required.
2018-08-08 10:32:19 -05:00
Lifubang 9fc6eb434c Add name field in 99-loopback.conf because network name is required. 2018-08-08 10:30:45 +08:00
xiangpengzhao 478f7b417e List Knitter as 3rd party plugin 2018-08-03 14:16:29 +08:00
Dan Williams 0f6a509e4b
Merge pull request #565 from dcbw/spec-members
spec: be explicit about optional and required structure members
2018-08-02 12:44:13 -05:00
Dan Williams 2ce2c24cc2 skel: only print about message, not errors
Instead of:

CNI_COMMAND env variable missing
<about message here>
{
    "code": 100,
    "msg": "required env variables missing"
}

print:
<about message here>
2018-07-26 10:51:40 -05:00
Dan Williams e67bb289cc
Merge pull request #566 from dineshb-jnpr/master
Add Juniper Contrail to 3rd party plugin list
2018-07-05 16:07:35 -05:00
dineshb-jnpr 9bd516a786 Add Juniper Contrail to 3rd party plugin list
This change is to update the 3rd Party plugin section of README
to include and list the K8s CNI solution from Juniper Networks, INC.
2018-07-02 17:23:29 -07:00
Dan Williams 9a34081fef spec: be explicit about optional and require structure members
Fixes: #564
2018-06-28 13:12:35 -05:00
Dan Williams d974c1dd54
Merge pull request #562 from jingax10/master
Fix broken build for cni introduced by https://github.com/containernetworking/cni/pull/524
2018-06-28 12:02:30 -05:00
Jing Ai 96343561e0 Fix broken build for cni introduced by https://github.com/containernetworking/cni/pull/524. 2018-06-20 22:42:04 -07:00
Dan Williams aed7a2f2a1
Merge pull request #524 from squeed/validate
libcni: add ValidateNetwork and ValidateNetworkList functions
2018-06-20 10:39:28 -05:00
Casey Callendrello 07c1a6da47
Merge pull request #558 from dcbw/libcni-exec-interface
libcni: make exec handling an interface for better downstream testing
2018-06-13 17:08:47 +02:00
Casey Callendrello b34795b3ce libcni: add ValidateNetwork and ValidateNetworkList functions
These perform some static validation on a network configuration,
ensuring it is generally executable.
2018-06-13 16:35:17 +02:00
Dan Williams ffc1e7b446 invoke: fix an existing gofmt complaint 2018-06-11 15:33:53 -05:00
Dan Williams 09dac4ecdc libcni: make exec handling an interface for better downstream testing
When a downstream project just uses libcni, it takes a lot of harness
code to set up binaries on-disk that get called.  Instead we can handle
that by passing an execer interface to libcni APIs that gets called
instead, which the downstreams can use to avoid execing thing entirely
and instead check arguments/environment in code.

Downstream users that currently create a CNIConfig object like this:

    cniconf := libcni.CNIConfig{Path: []string{"foobar"}}

Can now fake out all on-disk binary exec/find operations with:

    cniconf := libcni.NewCNIConfig([]string{"foobar"}, <exec interface>)
2018-06-11 15:33:53 -05:00
Dan Williams 86431d5c16
Merge pull request #557 from containernetworking/if-name-matters
Network interface name matters, updated
2018-05-31 13:41:59 -05:00
Bryan Boreham 6106bbf116 Use explicit identifiers in key tuple 2018-05-30 15:49:04 +00:00
Bryan Boreham df12d88b58 A couple of tests should be testing 0.3.1 explicitly 2018-05-30 15:40:47 +00:00
Casey Callendrello 3ffb039b29
Merge pull request #554 from squeed/skel-plugin-version
skel: add support for plugin version string
2018-05-30 17:34:47 +02:00
Mike Spreitzer 7f05cbb33b First draft that passes tests 2018-05-30 15:16:38 +00:00
Mike Spreitzer b43173e5d2 start drafting change to make ifname matter 2018-05-30 15:11:19 +00:00
Casey Callendrello 35d510c0ee
Merge pull request #556 from squeed/bw-convention
Conventions: add bandwidth limits
2018-05-30 17:07:14 +02:00
Casey Callendrello d2be2fa823 Conventions: add bandwidth limits 2018-05-25 19:09:56 +02:00
Casey Callendrello 197eadbe52 skel: add support for plugin version string 2018-05-24 14:26:42 +02:00
Casey Callendrello 85488fbd8d
Merge pull request #490 from dcbw/get-action
Add a GET action to the CNI spec, packages, and sample plugin
2018-05-23 17:22:32 +02:00
Dan Williams ef2ae62d8f
Merge pull request #553 from dcbw/ovn-kube
README: add ovn-kubernetes to the plugin list
2018-05-22 11:32:32 -05:00
Dan Williams fed8bad0cb libcni: add GET support and result caching
Per the spec, a Result from ADD is cached and provided to GET and DEL
commands.
2018-05-21 16:05:31 -05:00
Dan Williams 49ebeedfbb libcni: use Add/DelNetworkList to implement Add/DelNetwork 2018-05-21 16:05:31 -05:00
Dan Williams 23a5d8e617 spec/invoke/skel: add GET command 2018-05-21 16:05:31 -05:00
Dan Williams 7b8b5da47b spec/pkg: bump version to 0.4.0 2018-05-16 10:21:17 -05:00
Dan Williams eea7a08b3c pkg/version: add some version-handling utility functions 2018-05-16 10:21:15 -05:00
Dan Williams 4372fe2566 README: add ovn-kubernetes to plugin list 2018-05-15 20:34:17 -05:00
Matt Dupre a700ea864b
Merge pull request #543 from qianzhangxa/remove-version-param
spec: remove the version parameter from ADD and DEL commands.
2018-03-07 16:29:29 +00:00
Bryan Boreham 974e2cf668
Merge pull request #546 from mhausenblas/patch-1
fixes the title in specification
2018-03-07 16:20:52 +00:00
Michael Hausenblas cd2d779931
fixes the title in specification
Might be an historical artefact but I believe the correct full name for CNI should be Container Network Interface 

CC: @bboreham
2018-03-06 09:54:24 +00:00
Dan Williams 9aab8b3e9f
Merge pull request #538 from rosenhouse/bump-golang-1.10
travis: bump golang versions
2018-02-28 10:02:33 -06:00
Gabe Rosenhouse 05a3c9c213 travis: bump golang versions
- test against Go 1.10
- stop testing against Go 1.8

since Go language maintainers no longer support 1.8
see: https://golang.org/doc/devel/release.html#policy
2018-02-28 07:00:16 -08:00
Qian Zhang e3b496a3b6 spec: remove the version parameter from ADD and DEL commands.
The CNI spec version passed from runtime to plugin is the `cniVersion`
field in the network configuration rather than a parameter to the ADD
and DEL command. So, remove the version parameter from the spec, and
also describe how the `cniVersion` field in the network configuration
should be used by the plugin.

Fixes #542
2018-02-27 09:59:57 +08:00
Gabe Rosenhouse 142cde0c76
Merge pull request #536 from dcbw/require-network-name
pkg/skel: return error if JSON config has no network name
2018-02-17 19:21:24 -08:00
Gabe Rosenhouse 826f754e82
Merge pull request #535 from dcbw/no-sudo-required
tests: sudo not actually required
2018-02-17 18:55:25 -08:00
Dan Williams d4bae8512a pkg/skel: return error if JSON config has no network name
SPEC.md has indicated that 'name' is required since at least mid-2015,
but that was not enforced in pkg/skel or our unit tests.  That could
lead to configs passing no network name and plugins like host-local
that require the name failing or causing odd behavior.

Since the name is required by the spec, require it in the code too.
2018-02-16 16:14:30 -06:00
Dan Williams c3fc2ae6e4 tests: sudo not actually required
The legacy example plugin and its libcni backwards_compatibility_test.go
just use the noop plugin, which doesn't do anything with the netns path
or make any interfaces inside the netns.  So we can remove anything
netns related from the test, which means we no longer need sudo.
2018-02-16 11:46:03 -06:00
Dan Williams 6cddc9a378
Merge pull request #529 from joerg84/patch-1
Described Mesos as Apache project.
2018-02-07 09:47:58 -06:00
Joerg Schad 55d1c96643
Described Mesos as Apache project. 2018-01-24 21:34:26 +01:00
Casey Callendrello 693cc869fd
Merge pull request #525 from squeed/range-arg
CONVENTIONS: add new `ipRanges` capability.
2018-01-24 18:39:33 +01:00
Gabe Rosenhouse 1773a1f24c
Merge pull request #528 from huangjiuyuan/fix-typo
Fix typo in CONVENTIONS.md
2018-01-19 14:30:55 -08:00
Gabe Rosenhouse d59d5c6cda
Merge pull request #96 from zachgersh/make-ipam-type
pkg/types: Makes IPAM concrete type
2018-01-17 10:42:08 -08:00
huangjiuyuan bb3445a503 Fix typo in CONVENTIONS.md 2018-01-11 10:24:03 +08:00
Bryan Boreham 9ded5d186f
Merge pull request #527 from Intel-Corp/dev/bonding-cni-3rd-party-readme-pr
Adding the Bonding CNI plugin as 3rd party plugin
2018-01-10 16:53:04 +00:00
Kuralamudhan Ramakrishnan 6787bb6591
Update README.md 2017-12-15 18:20:33 +00:00
Kuralamudhan Ramakrishnan 7099c732cb
Adding the Bonding CNI plugin as 3rd party plugin
- Bonding CNI provides a method for aggregating multiple network interfaces into a single logical "bonded" interface.
- Linx Bonding drivers provides various flavour of bonded interface depending on the mode (bonding policies), such as round robin, active aggregation according to the 802.3 ad specification
For more information on the bonding driver. Please refer to [kernel doc(https://www.kernel.org/doc/Documentation/networking/bonding.txt)
2017-12-15 16:41:43 +00:00
Gabe Rosenhouse 97ce633ca1
Merge pull request #526 from davidk01/patch-1
kurma is no longer maintained
2017-12-13 08:24:23 -08:00
david karapetyan 74b3024fa8
kurma is no longer maintained
Kurma is a derelict project so should be removed
2017-12-12 14:09:12 -08:00
Casey Callendrello 68ae5290ea CONVENTIONS: add new `ipRanges` capability.
Also, restructure the document slightly.
2017-12-08 16:28:59 +01:00
Casey Callendrello 9b747fabbd
Merge pull request #516 from rosenhouse/add-appveyor-badge
README: add badge for appveyor (Windows CI) status
2017-12-07 11:51:46 +01:00
Gabriel Rosenhouse f8fb397969 README: add badge for appveyor (Windows CI) 2017-12-03 14:13:21 -08:00
Matt Dupre 869505bebd
Merge pull request #517 from matthewdupre/maintainers-update
Maintainers: replace Tom Denham with Matt Dupre
2017-11-21 17:21:36 +00:00
Gabe Rosenhouse 1f824fbf2c
Merge pull request #521 from rosenhouse/types-tests
backfill some unit tests
2017-11-15 08:08:07 -08:00
Gabriel Rosenhouse cf260a13d7 pks/types/current: backfill a couple more unit tests 2017-11-15 00:33:43 -08:00
Gabriel Rosenhouse 61a8bf2ee1 pkg/types: non-pointer Route marshals as JSON
also: backfill unit tests for JSON and string formatting of custom types
2017-11-15 00:33:43 -08:00
Gabe Rosenhouse a88bf49d86
Merge pull request #520 from aaithal/addECSToReadme
readme: add Amazon ECS to runtimes and plugins list
2017-11-15 00:31:47 -08:00
Aithal 0844a98e03 readme: add Amazon ECS to the list 2017-11-14 15:09:32 -08:00
Gabe Rosenhouse eeded9f55e
Merge pull request #518 from porridge/patch-1
Fix indentation
2017-11-07 20:02:14 -08:00
Marcin Owsiany 525880d8bc
Fix indentation 2017-11-07 20:30:02 +01:00
Matt Dupre 464d07ffdb Maintainers: replace Tom Denham with Matt Dupre 2017-11-01 15:34:48 +00:00
Gabe Rosenhouse 384d8c0b52
Merge pull request #514 from rosenhouse/no-vendor
Remove vendor directory
2017-11-01 08:11:26 -07:00
Gabriel Rosenhouse fa8f141f29 Remove vendor dir, simplify build & test tooling
"Libraries should never vendor their dependencies"
  https://peter.bourgon.org/go-best-practices-2016/#dependency-management
The only thing in there were test-support packages anyhow

Remove Godeps folder, nothing to manage!

Remove build.sh
- not much here to build now that we've split out plugins
   - for non-AMD64 platforms, travis just runs go build directly

Clean up test.sh
- no vendor --> simpler logic for enumerating packages
- use "bash strict mode"
   http://redsymbol.net/articles/unofficial-bash-strict-mode
- coveralls token not required for public repos

Simplify .travis.yml, update to work without vendor
- fewer env vars
- go get -t ./...

Clean up Vagrantfile
- no godep required anymore
- bump Golang version 1.9.2
2017-10-31 22:32:18 -07:00
Gabriel Rosenhouse 7f03ee4537 libcni: fix go vet error 2017-10-31 22:24:53 -07:00
Casey Callendrello 4228ca8928 Merge pull request #508 from squeed/cnitool-cid
cnitool: generate container id from the netns path
2017-10-25 14:58:57 +02:00
Gabe Rosenhouse 97314481b4 Merge pull request #515 from rosenhouse/appveyor
Add CI for Windows
2017-10-23 08:19:28 -07:00
Gabriel Rosenhouse 449ac26e38 ci: add appveyor file for Windows CI coverage 2017-10-22 23:21:14 -07:00
Gabriel Rosenhouse 36a22467d9 Windows compatibility: all tests pass! 2017-10-22 23:21:08 -07:00
Gabe Rosenhouse 40837d1ff0 Merge pull request #510 from squeed/containerid
spec, skel: Make the container ID required and unique.
2017-10-21 12:29:23 -07:00
Casey Callendrello b9995395c0 cnitool: generate container id from the netns path, add docs
We shouldn't be creating networks with a blank containerid. Let's
synthesize one from the netns path.

Also, add a basic README.
2017-10-20 14:28:11 +02:00
Casey Callendrello a0a74bbcd3 spec, skel: Make the container ID required and unique.
Previously, the spec did not require the container id to be set.
However, almost every plugin relies on it being unique, including the
CNI-maintained plugins. So, change the spec to require the use of
containerid and that plugins should treat it as a primary key.
2017-10-20 14:26:18 +02:00
Casey Callendrello 03e5b5ff9e Add "spec containes unreleased changes" warning. 2017-10-20 14:26:18 +02:00
Gabe Rosenhouse 30c6934e5c Merge pull request #499 from rosenhouse/golang-to-1.9
Golang versions: add 1.9, drop 1.7
2017-10-18 15:34:51 -07:00
Gabe Rosenhouse 43744a3fce pkg/invoke: fix test pollution 2017-10-18 14:51:35 -07:00
Gabe Rosenhouse baecfa6fda Golang versions: add 1.9.1, drop 1.7 2017-10-18 14:51:33 -07:00
Casey Callendrello ff7c3e02e3 Merge pull request #509 from containernetworking/update-community-sync
Add 2017-10-04 community sync
2017-09-22 11:39:36 +02:00
Casey Callendrello 4b9e11a526 Add 2017-10-04 community sync 2017-09-22 11:39:09 +02:00
Dan Williams b30c419f96 Merge pull request #497 from squeed/args-add-ip
Conventions: add the "ips" arg
2017-09-20 09:50:34 -05:00
Gabe Rosenhouse 6614adf4a4 Merge pull request #505 from dcbw/op-ordering
spec: add notes about ADD/DEL ordering
2017-09-18 20:20:24 -07:00
Dan Williams c0ca8f4db9 spec: add notes about ADD/DEL ordering 2017-09-18 12:25:30 -05:00
Dan Williams b7c7ec76ed Merge pull request #504 from dcbw/gov-voting
governance: add notes about public voting
2017-09-18 12:24:09 -05:00
Gabe Rosenhouse 5da3960e2b Merge pull request #506 from Intel-Corp/dev/vhostuser3rdparty-pr
README: List vhostuser CNI as a 3rd party plugin
2017-09-18 09:34:26 -07:00
kuralamudhan ramakrishnan a35068121c README: List vhostuser as a 3rd party plugin 2017-09-16 00:47:37 +01:00
Dan Williams a2d35cb6a1 Merge pull request #500 from matthewdupre/spec-language
Use more RFC2119 style language in specification (must, should...)
2017-09-14 14:46:52 -05:00
Dan Williams 27a848cc18 Merge pull request #502 from anfernee/version
skel: VERSION shouldn't block on stdin
2017-09-14 13:25:24 -05:00
Dan Williams 5c552f3ffc governance: add notes about public voting 2017-09-13 17:24:40 -05:00
Yongkun Anfernee Gui f5302a2aa9 VERSION shouldn't block on stdin
Right now, I have to do the following
  $ echo | CNI_COMMAND=VERSION bridge
or
  CNI_COMMAND=VERSION bridge
  ^D
to be able to get the result back.

But VERSION doesn't need to read from stdin.
2017-09-07 22:48:10 -07:00
Gabe Rosenhouse 909fe7d10d Merge pull request #501 from rosenhouse/test-all-packages
Test all non-vendored packages
2017-08-30 19:32:53 -07:00
Gabe Rosenhouse a2b0a28ce5 Test all non-vendored packages 2017-08-30 14:59:16 -07:00
Casey Callendrello 98ace24557 Merge pull request #493 from dcbw/governance
docs: add Governance procedure documentation
2017-08-30 17:14:54 +02:00
Gabe Rosenhouse a677030029 Merge pull request #492 from dcbw/roadmap
roadmap: add 1.0 items and clean things up
2017-08-30 08:12:30 -07:00
Dan Williams 3f72c535ea docs: add Governance procedure documentation 2017-08-30 10:10:11 -05:00
Matt Dupre fa69c6eb6a Use more RFC2119 style language in specification (must, should...) 2017-08-30 15:35:18 +01:00
Gabe Rosenhouse 3477001a1b Merge pull request #489 from squeed/clean-build
Release: clean the builddir when building.
2017-08-23 09:25:12 -07:00
Casey Callendrello 0a0d0da638 Conventions: add the "ips" arg 2017-08-22 18:10:07 +02:00
Dan Williams 80c688516d Merge pull request #494 from dcbw/validate-type
libcni: return error if Type is empty
2017-08-18 12:50:31 -05:00
Dan Williams 9c87b066ce Merge pull request #495 from rosenhouse/spec-list-older-versions
Spec lists git tags pointing to old spec versions
2017-08-18 12:49:39 -05:00
Gabriel Rosenhouse 31e696618c spec: table of git tags to older versions 2017-08-17 20:43:48 -07:00
Dan Williams 95599124da libcni: return error if Type is empty
A network config missing Type is pretty useless since it means we can't
find the plugin to execute.  So return an error if Type isn't given.
2017-08-17 22:34:33 -05:00
Dan Williams 5adb89b6d2 roadmap: add 1.0 items and clean things up 2017-08-16 13:14:10 -05:00
Casey Callendrello 6c680c05dd Release: clean the builddir when building. 2017-08-14 14:27:44 +02:00
Bryan Boreham a7885cb6f8 Merge pull request #487 from John-Lin/readme-add-plugin-linen
README plugins list: add Linen CNI plugin
2017-07-28 14:30:50 +01:00
John-Lin adfecd3434 README plugins list: add Linen CNI plugin 2017-07-27 18:35:42 +08:00
Dan Williams b69e640cc0 Merge pull request #482 from feiskyer/cnitool
cnitool: add support for CNI_ARGS
2017-07-12 10:03:31 -05:00
Pengfei Ni feeb3d4e4e cnitool: add support for CNI_ARGS
Signed-off-by: Pengfei Ni <feiskyer@gmail.com>
2017-07-12 07:06:23 +08:00
Casey Callendrello 2370e65262 Merge pull request #481 from tomdee/s390x
scripts/release.sh: Add in s390x architecture
2017-07-06 19:46:10 +02:00
Tom Denham 269d35531d
scripts/release.sh: Add in s390x architecture 2017-07-06 10:39:44 -07:00
Gabe Rosenhouse a2da8f8d7f Merge pull request #427 from squeed/convention-chaining
Conventions: add convention around chaining interfaces
2017-07-05 08:32:19 -07:00
Casey Callendrello 777d535934 Merge pull request #460 from aaithal/loadArgsPanic
pkg/types: safer typecasting for TextUnmarshaler when loading args
2017-07-05 17:15:23 +02:00
Casey Callendrello 6a6f9d7f5c Merge pull request #473 from tomdee/improve-and-document-release
Update and document release process
2017-06-29 11:06:28 +02:00
Tom Denham 34dfbc5d3c
Update and document release process
Replace the rkt release process with a docker one.
Document the process that we follow for each release.
2017-06-28 08:39:26 -07:00
Dan Williams 49d814cf37 Merge pull request #477 from dcbw/fix-interface-index-marshaling
types: fix marshalling of omitted "interfaces" key in IPConfig JSON
2017-06-22 09:39:14 -05:00
Dan Williams 30ab80517f types: fix marshalling of omitted "interfaces" key in IPConfig JSON
Plugins that don't have knowledge of interfaces, like host-local or
other IPAM plugins, should not set the 'interfaces' key of their
returned "Result" JSON.  This should then not be translated into
an interface index of 0, which it was due to the int marshaling and
omitempty.

Instead, ensure that an omitted 'interface' in JSON ends up being
nil in the IPConfig structure, and that a nil ensures that no 'interfaces'
key is present in the JSON.

Yes, this means that plugins must call the 'current.Int(x)' method
when setting the Interfaces member.  Oh well.

Fixes: https://github.com/containernetworking/cni/issues/404
2017-06-21 09:56:12 -05:00
Casey Callendrello 8a045b00e4 Merge pull request #478 from squeed/community-sync
Update note about next Community Sync, 2017-06-21
2017-06-16 13:43:57 +02:00
Casey Callendrello 1af3421e7f Update note about next Community Sync, 2017-06-21 2017-06-16 13:43:05 +02:00
Gabe Rosenhouse be0ea12b47 Merge pull request #474 from rosenhouse/readme-updates
readme updates
2017-06-12 10:06:42 -07:00
Gabe Rosenhouse 95bdbc9368 Merge pull request #475 from rosenhouse/backfill-test-delegate
pkg/invoke: backfill tests of delegate add & del
2017-06-11 22:04:12 -07:00
Gabe Rosenhouse 396da95a80 pkg/invoke: backfill tests of delegate add & del 2017-06-08 23:09:58 -07:00
Gabe Rosenhouse 831120ae89 readme: update link for Cloud Foundry CNI integration 2017-06-08 21:27:52 -07:00
Gabe Rosenhouse fa94835b04 readme updates
- update some links to the new plugins repo.
- update guidance on golang versions
2017-06-08 21:23:10 -07:00
zachgersh 832a52582b pkg/types: split out NetConf.IPAM into own type 2017-06-08 20:42:22 -07:00
Casey Callendrello 2d3fa8467d Merge pull request #406 from GheRivero/cni_error
Return cni.type.Error instead of plain error
2017-06-08 20:02:11 +02:00
Gabe Rosenhouse 6828d6c444 Merge pull request #472 from caniszczyk/add-cncf-ref
Add CNCF reference in README
2017-06-07 18:05:18 -07:00
Gabe Rosenhouse 4b5fac1edd Merge pull request #471 from rosenhouse/clean-up-vendor
Clean up vendor
2017-06-07 12:19:40 -07:00
Chris Aniszczyk 32c26940ca Add CNCF reference in README
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2017-06-07 11:23:59 -07:00
Gabe Rosenhouse 8b39063724 Merge pull request #470 from rosenhouse/fixup-vagrantfile
Vagrantfile updates
2017-06-07 07:41:19 -07:00
Casey Callendrello 10ba4c5165 Merge pull request #467 from containernetworking/clarify-args-release
Clarify first released spec with 'args' was 0.2.0
2017-06-07 09:57:31 +02:00
Gabe Rosenhouse d63e1e546a vendor: cleanup unused dependencies after plugin split 2017-06-06 21:08:57 -07:00
Gabe Rosenhouse c2034d812f godeps: update Go version to 1.8 2017-06-06 20:58:48 -07:00
Gabe Rosenhouse e5a22d1aaf Vagrantfile updates
- installs latest Golang
2017-06-06 20:49:44 -07:00
Gabe Rosenhouse ce265ef329 Merge pull request #464 from squeed/remove-pkg
pkg: move packages from cni to plugins
2017-06-06 18:58:28 -07:00
Gabe Rosenhouse 438b74fa33 Merge pull request #469 from mcastelino/document_fix
Documentation: Update README.md to reflect plugin split
2017-06-06 18:52:09 -07:00
Gabe Rosenhouse 449bd85e11 Merge pull request #461 from ericchiang/fix-env-order
pkg/invoke: ensure that custom env vars are prepended to the env
2017-06-06 18:48:43 -07:00
Manohar Castelino d44eee2ee7 Documentation: Update README.md to reflect plugin split
Update README.md to call out how to use priv-net-run.sh and
docker-run.sh scripts post plugin split.

Signed-off-by: Manohar Castelino <manohar.r.castelino@intel.com>
2017-06-06 18:37:23 -07:00
Gabe Rosenhouse 5e25038244 pkg/invoke: add unit test for env var ordering in Args.AsEnv 2017-06-06 18:37:04 -07:00
Bryan Boreham f41070deb0 Clarify first released spec with 'args' was 0.2.0 2017-06-03 14:21:43 +01:00
Bryan Boreham 98826b72cc Merge pull request #465 from caniszczyk/add-coc
Add Code of Conduct
2017-06-03 13:47:28 +01:00
Bryan Boreham 86d081b730 Merge pull request #463 from rosenhouse/readme-add-plugin-silk
readme plugins list: add Silk CNI plugin
2017-06-03 13:45:58 +01:00
Chris Aniszczyk 17d4eea2b6 Add Code of Conduct
CNCF projects are expected to follow a CoC.

Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2017-06-02 09:10:25 -07:00
Casey Callendrello fe14708aee pkg: move packages from cni to plugins 2017-06-02 16:25:42 +02:00
Gabe Rosenhouse dd2db4544e readme: add Silk CNI plugin 2017-05-31 11:23:45 -07:00
Aithal c8658027aa pkg/types: modify LoadArgs to return a named error when an unmarshalable condition is detected 2017-05-31 09:11:48 -07:00
Dan Williams 73c65fbe83 Merge pull request #462 from christx2/patch-1
Update Readme.md
2017-05-31 10:14:48 -05:00
ChristophLondon 5ccd280188 Update Readme.md
adding nuage networks cni plugin and repo location
2017-05-31 12:04:23 +01:00
Eric Chiang 49fb84b284 pkg/invoke: ensure that custom env vars are prepended to the env
Ensure that custom values take priority over values defined in the
environment by prepending them to the env, not appending.
2017-05-29 17:32:49 -07:00
Casey Callendrello c71a7c068f Merge pull request #457 from dcbw/move-plugins
plugins: moved to containernetworking/plugins
2017-05-24 18:46:33 +02:00
Dan Williams bc0d09e572 plugins: moved to containernetworking/plugins 2017-05-23 13:37:15 -05:00
Aithal 5b4c559d4d pkg/types: safer typecasting for TextUnmarshaler when loading args
types.LoadArgs does an unsafe typecast for env args key value pairs.
This can cause a panic if the config type fields do not implement
the encoding.TextUnmarshaler interface. This commit modifies it to
do a safe type cast and return an error in such scenarios.
2017-05-22 13:13:57 -07:00
Casey Callendrello 8ea1605c26 Merge pull request #455 from knobunc/docs/add-openshift-to-readme
Add OpenShift to the list of container runtimes that support CNI
2017-05-17 10:52:33 +02:00
Dan Williams 2e9bb5c646 Merge pull request #452 from caniszczyk/add-cni-logo
Add CNI Logo to README
2017-05-16 14:32:03 -05:00
Benjamin Bennett 099bde1f26 Add OpenShift to the list of container runtimes that support CNI
OpenShift uses CNI, so I thought a link to the appropriate docs made
sense in the top-level readme where it lists the other supporting
runtimes.
2017-05-16 08:33:35 -04:00
Chris Aniszczyk 41cff3fdfb Add CNI Logo to README
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2017-05-15 08:18:23 -05:00
Tom Denham 0ebcfe7ea3 Merge pull request #425 from tomdee/small-build-improvements
scripts/release-with-rkt.sh Minor improvements
2017-05-10 14:34:47 -05:00
Casey Callendrello 1a9288c3c0 Merge pull request #450 from gunjan5/spec-version-mismatch
cniVersion and config structure mismatch
2017-05-08 11:12:25 +02:00
Dan Williams e03c76b852 Merge pull request #445 from feiskyer/cniversion
Add cniVersion to Result
2017-05-05 17:47:26 -05:00
gunjan5 efe4f37afa cniVersion and config structure mismatch 2017-05-05 14:50:58 -07:00
Tom Denham b686cad062 Merge pull request #447 from gunjan5/invalid-spec-json
Fix invalid json
2017-05-04 16:06:04 -07:00
gunjan5 5e3be5a44f fix invalid json 2017-05-04 15:59:11 -07:00
Pengfei Ni f197c01b62 Fix testings accross the project
Signed-off-by: Pengfei Ni <feiskyer@gmail.com>
2017-05-03 23:21:44 +08:00
Pengfei Ni 27a5b994c2 Add cniVersion to Result
Signed-off-by: Pengfei Ni <feiskyer@gmail.com>
2017-05-03 21:38:42 +08:00
Dan Williams 231f6c4c53 Merge pull request #433 from dunjut/master
scripts: cleanup() should rm net container in docker-run.sh
2017-04-28 20:58:17 -05:00
Dan Williams a6c96acda4 Merge pull request #440 from feiskyer/cap
cnitool: support capablity args
2017-04-28 20:55:31 -05:00
Dan Williams 010c8a9503 Merge pull request #439 from dnardo/netlink-update
vendor: Update vishvanana/netlink dependency.
2017-04-25 10:24:05 -05:00
Pengfei Ni 73a2d131ee cnitool: support capablity args
Signed-off-by: Pengfei Ni <feiskyer@gmail.com>
2017-04-25 17:35:03 +08:00
Dan Williams 21d96393ea Merge pull request #391 from tangle329/master
Validate rangeStart and rangeEnd specified in conf
2017-04-24 22:00:07 -05:00
Tom Denham 8eddd61fed Merge pull request #435 from micahhausler/patch-1
Fixed table formatting
2017-04-24 11:21:33 -07:00
Daniel Nardo 0de29de33e Update netlink dependency. 2017-04-24 10:31:24 -07:00
Micah Hausler 87fbabeeef Fixed table formatting 2017-04-21 15:22:56 -04:00
du 6ee2048ec2 scripts: cleanup() should rm net container in docker-run.sh 2017-04-21 18:27:46 +08:00
Bryan Boreham 279cae5ec5 Merge pull request #432 from dunjut/master
README: build the plugins using ./build.sh, not ./build
2017-04-21 11:12:49 +01:00
du 43c11dda15 README: build the plugins using ./build.sh, not ./build 2017-04-21 15:29:57 +08:00
Gabe Rosenhouse 4a2f3ddd5d Merge pull request #430 from kris-nova/remove-proposal
Wondering if this is still a proposal?
2017-04-16 11:13:24 -07:00
Kris Nova 392e1bbd10 Changing Proposal->Specification in Spec 2017-04-16 11:01:23 -06:00
Casey Callendrello ddebb44ad8 Conventions: add convention around chaining interfaces 2017-04-11 19:10:56 +02:00
Tom Denham 72dbcda3d6
scripts/release-with-rkt.sh Minor improvements
- Use a new Fedora to get a more up to date Go version
- Don't build so many archives, they are not used.
- Handle the new build.sh script
- Just use host networking with rkt
2017-04-07 13:54:39 -07:00
Gabe Rosenhouse 137b4975ec Merge pull request #419 from asridharan/cnitool
Added documentation for `cnitool`
2017-04-07 10:20:07 -07:00
Avinash Sridharan 382686ed63 Documentation: Added documentation for `cnitool`.
Added documentation to simplify the usage of `cnitool` and the
settings expected to be used with `cnitool`.
2017-04-05 21:40:24 +00:00
Avinash Sridharan d427963784 libcni: Fixed tests that were checking error strings.
Checking error strings makes these tests flaky, especially if the
error string is changed in libcni. Have gone ahead an introduced a new
error type `NoConfigsFoundError` and the Match is against the error
type making it more deterministic.
2017-04-05 21:40:24 +00:00
Avinash Sridharan 5b0d6a0c8f libcni: Improved error messages.
Improved the error reporting to be more descriptive when configuration
files are not filed while using the cni-tool.
2017-04-05 21:40:16 +00:00
Tom Denham 361ec957fb Merge pull request #413 from dcbw/spec-fix-ips
spec/plugins: fix 'ip'->'ips' in the spec, bump to 0.3.1
2017-04-05 14:39:44 -07:00
Dan Williams 9445711fa5 spec/plugins: fix 'ip'->'ips' in the spec, bump to 0.3.1 2017-04-05 12:46:24 -05:00
Gabe Rosenhouse d4bbce1865 Merge pull request #423 from rosenhouse/update-travis
travis: shift forward to Go 1.8 and 1.7
2017-04-05 09:26:49 -07:00
Gabe Rosenhouse ff92701693 Merge pull request #421 from kshafiee/patch-1
Added entry for CNI-Genie
2017-04-05 09:24:21 -07:00
Gabe Rosenhouse a39d6845fa travis: shift forward to Go 1.8 and 1.7 2017-04-05 09:11:35 -07:00
Dan Williams d66edc3180 Merge pull request #400 from lstoll/lstoll-rename-build-script
Rename build script to avoid conflict with bazel
2017-04-05 11:03:23 -05:00
kshafiee aaba1b0224 Added entry for CNI-Genie
CNI-Genie enables orchestrators (kubernetes, mesos) for seamless connectivity to choice of CNI plugins (calico, canal, romana, weave) configured on a Node
2017-04-03 12:00:02 -07:00
Tom Denham 470e86eb8b Update community sync detail 2017-03-31 14:38:48 -07:00
Tom Denham 73c6616946 Merge pull request #414 from kad/s390x
Enable s390x build
2017-03-27 10:10:06 -07:00
Alexander Kanevskiy 61f3b4b315 Enable s390x build 2017-03-23 00:51:29 +02:00
Tom Denham 0799f5732f Merge pull request #412 from tomdee/safe-del
plugins/*: Don't error if the device doesn't exist
2017-03-22 09:47:29 -07:00
Tom Denham 13824487c6
plugins/*: Don't error if the device doesn't exist
I wasn't able to test or update the dhcp plugin but from a code read it
should be fine. All the other plugins are tested and fixed
2017-03-22 08:52:29 -07:00
Tom Denham 699380d687 Merge pull request #407 from aaronlevy/del-err
plugins/meta/flannel: If net config is missing do not return err on DEL
2017-03-21 10:43:40 -07:00
Ghe Rivero e00a647504 Return type.Error instead of plain error
This way, we can use Error.Code attribute to check error type without
needing to regexp the message string
2017-03-18 10:43:02 +01:00
Aaron Levy 74d4cbed76 plugins/meta/flannel: If net config is missing do not return err on DEL 2017-03-17 13:37:33 -07:00
Gabe Rosenhouse b87126377a Merge pull request #396 from cf-container-networking/vendored-types-leakage
pkg/ip: do not leak types from vendored netlink package
2017-03-16 19:20:40 -07:00
Brandon Philips c235b448d4 Merge pull request #401 from chrismarino/patch-1
Added Romana to list of CNI providers...
2017-03-15 12:38:04 -07:00
chrismarino c1c7826922 Added Romana to list of CNI providers...
Added Romana to list of CNI providers.
2017-03-15 12:10:21 -07:00
Lincoln Stoll 1b9caefba5 Rename build script to avoid conflict with bazel
It's difficult to include this repository using bazel, because
the file named "build" conflicts with new_go_repository generation
on case-insensitive filesystems (ref
https://github.com/bazelbuild/rules_go/issues/234). This change
renames the file to something that doesn't conflict, and also
renames the test script for consistency.
2017-03-15 15:59:44 +11:00
Gabe Rosenhouse f51dd618c5 pkg/ip: improve docstring for SetupVeth 2017-03-13 11:27:12 -07:00
Gabe Rosenhouse e4a0583d7a pkg/ip: SetupVeth returns net.Interface 2017-03-10 09:49:46 -08:00
Tang Le 1b65890795 Validate rangeStart and rangeEnd specified in conf
Signed-off-by: Tang Le <tangle3@wanda.cn>
2017-03-10 12:51:05 +08:00
Jay Dunkelberger 58c834c4f3 pkg/ip: do not leak types from vendored netlink package
The exported function SetupVeth now returns a package-defined type.

Signed-off-by: Gabe Rosenhouse <grosenhouse@pivotal.io>
2017-03-09 13:55:15 -08:00
Gabe Rosenhouse 4f36e5994e Merge pull request #393 from containernetworking/community-sync-readme
readme.md: Add link to community sync
2017-03-08 16:46:44 -08:00
Tom Denham 5d5b16f0b3 readme.md: Add link to community sync 2017-03-08 15:54:15 -08:00
Gabe Rosenhouse 4ce9b019aa Merge pull request #366 from ehazlett/ipam-host-local-initial-reserved-ip
Do not error if last reserved not found after initial creation
2017-03-06 07:13:06 -08:00
Evan Hazlett ac50624393
fix unrelated failing tests
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
2017-03-02 15:37:43 -05:00
Evan Hazlett 2678be24d0
add test for ensuring initial subnet creation does not contain an error
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
2017-03-02 15:16:09 -05:00
Evan Hazlett 474ba16901 do not error if last_reserved_ip is missing for host local ipam
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
2017-03-02 13:59:21 -05:00
Tom Denham 1f6efc28b5 Merge pull request #387 from tangle329/master
Check n.IPAM before use it in LoadIPAMConfig function
2017-03-02 09:23:02 -08:00
Dan Williams 75a5cf1bf0 Merge pull request #373 from dcbw/conflist-runtime-config
spec,libcni: add support for injecting runtimeConfig into plugin stdin data
2017-03-02 11:17:00 -06:00
Tang Le 1003822e53 Check n.IPAM before use it in LoadIPAMConfig function
Signed-off-by: Tang Le <tangle3@wanda.cn>
2017-03-02 10:25:19 +08:00
Dan Williams 71c4a60741 spec,libcni: add support for injecting runtimeConfig into plugin stdin data
Add a new CapabilityArgs member to the RuntimeConf struct which runtimes can
use to pass arbitrary capability-based keys to the plugin.  Elements of this
member will be filtered against the plugin's advertised capabilities (from
its config JSON) and then added to a new "runtimeConfig" top-level map added
to the config JSON sent to the plugin on stdin.

Also "runtime_config"->"runtimeConfig" in CONVENTIONS.md to make
capitalization consistent with other CNI config keys like "cniVersion".
2017-03-01 10:49:40 -06:00
Tom Denham 6008de1ffd Merge pull request #382 from rosenhouse/doc-spec-upgrade
Documentation: guidance for upgrading to CNI Spec v0.3.0
2017-03-01 08:45:56 -08:00
Casey Callendrello 09e5feae1f Minor rewording about default config version 2017-02-28 19:44:25 +01:00
Dan Williams 7d8c23dd59 Merge pull request #383 from dcbw/test-fixes
tests: misc test fixes
2017-02-27 16:13:45 -06:00
Dan Williams d6d012b88f Merge pull request #374 from squeed/config-list-upconvert
libcni: up-convert a Config to a ConfigList when no other configs are found.
2017-02-27 15:10:37 -06:00
Dan Williams 1f4a8c2802 Merge pull request #377 from squeed/ptp-sandbox
plugins/main/ptp: set the Sandbox property on the response
2017-02-27 15:06:57 -06:00
Dan Williams fc174a6635 Merge pull request #380 from bboreham/patch-1
Add Bryan Boreham as maintainer
2017-02-27 15:06:26 -06:00
Dan Williams 35153e7de8 pkg/types: misc current types testcase cleanups 2017-02-27 13:28:07 -06:00
Dan Williams 5a984f0dee pkg/testutils: return errors after restoring stdout
Ensures Ginkgo is able to print detailed failure messages instead
of them being captured by the pipe.
2017-02-27 13:27:19 -06:00
Dan Williams 94e02e0768 Merge pull request #375 from aaithal/complieOnNonLinuxPlatforms
pkg/ns: refactored so that builds succeed on non-linux platforms
2017-02-27 11:46:22 -06:00
Gabe Rosenhouse bbc23ea761 docs: table formatting is hard 2017-02-27 07:57:00 -08:00
Gabe Rosenhouse b6e9bf8372 docs: fill-out and correct version conversion table 2017-02-27 07:53:09 -08:00
Gabe Rosenhouse 379d47760c docs: minor improvements to spec-upgrades 2017-02-27 07:17:37 -08:00
Casey Callendrello 119d6f20f5 docs: add small upgrade instructions 2017-02-27 14:57:31 +01:00
Casey Callendrello 70c153eb41 docs: minor improvements to 0.3.0 upgrade guidance 2017-02-27 14:27:56 +01:00
Gabe Rosenhouse fa53446854 docs: Edits to v0.3.0 upgrade guidance 2017-02-26 16:53:52 -08:00
Dan Williams 328ea56e75 docs: CNI versioning for 0.3.0 upgrade 2017-02-26 13:26:14 -08:00
Casey Callendrello 6e6ad53ea8 libcni: up-convert a Config to a ConfigList when no other configs are found. 2017-02-24 19:44:06 +01:00
Tom Denham 1bc8141105 Merge pull request #379 from Intel-Corp/master
README: List multus as 3rd party plugin
2017-02-23 10:40:59 -08:00
Aithal 460e1c5be3 vendor: Update vishvanana/netlink dependency 2017-02-23 09:53:11 -08:00
Aithal 7eeb21a999 pkg/ip: refactored so that builds succeed on non-linux platforms
moved functions that depend on linux packages into a separate file and added
nop methods with a build tag for non-linux platforms in a new file.
2017-02-23 09:52:13 -08:00
Aithal 0dc0845c51 pkg/ns, pkg/types: refactored non linux build fix code to
Make GetCurrentNS platform specific instead of getCurrentThreadNetNSPath
2017-02-23 09:50:48 -08:00
Dan Williams aafc728ec0 Merge pull request #371 from rosenhouse/spec-netconf-routes
spec: Remove `routes` from Network Configuration
2017-02-22 20:32:41 -06:00
Bryan Boreham 32246b315c Replace Michael Bridgen with Bryan Boreham 2017-02-22 17:06:04 +00:00
Kuralamudhan Ramakrishnan 2c33eb4f22 README: List multus as 3rd party plugin
refer #343 issue
2017-02-22 16:13:12 +00:00
Gabe Rosenhouse 9f03c4bc2e Merge pull request #376 from zackhsi/fix-grammar
Fix grammar
2017-02-20 17:51:38 -08:00
Casey Callendrello 7fa16f18d9 plugins/main/ptp: set the Sandbox property on the response 2017-02-21 00:28:19 +01:00
Zack Hsi c783679114 Fix grammar 2017-02-20 11:21:49 -08:00
Aithal c3cde44480 pkg/ns: refactored so that builds succeed on non-linux platforms
moved functions that depend on linux packages (sys/unix) into a separate file
and added nop methods with a build tag for non-linux platforms in a new file.
2017-02-20 10:00:55 -08:00
Gabe Rosenhouse 3ba89873ac Merge pull request #372 from rosenhouse/consolidate-host-local-docs
docs: consolidate host-local documentation
2017-02-20 06:33:32 -08:00
Gabe Rosenhouse eb2ff7fe57 docs: consolidate host-local documentation
- remove the README.md in the plugins/ipam/host-local (no other plugin
  has this)
- merge that info into the main Documentation/host-local.md
2017-02-15 15:20:13 -08:00
Gabe Rosenhouse 31dafa2f7a spec: Remove `routes` from Network Configuration
- this is supported by some IPAM plugins but is not required of all of
  them
2017-02-15 15:02:23 -08:00
Tom Denham 6f3b0abcc7 Merge pull request #369 from containernetworking/port-mapping
CONVENTIONS.md: Update details on port-mappings
2017-02-14 11:47:59 -08:00
Tom Denham e3da6e1cfb
More markups 2017-02-13 10:14:45 -08:00
Tom Denham 95ca9d393a
Update with feedback 2017-02-09 14:12:33 -08:00
Tom Denham 3fbf94a90a CONVENTIONS.md: Update details on port-mappings
After discussion with the CNI maintainers and representatives from Mesos and Kubernetes we've settled on this approach for passing the dynamic port mapping information from runtimes to plugins.

Including it in the plugin config allows "operators" to signal that they expect port mapping information to be passed to a specific plugin (or plugins). This follows the model that config passed in the plugin config should be acted upon by a plugin.

Runtimes can optionally return an error to users if they find no plugin in the chain that supports port mappings.

I'm sure we'd all like to see this merged soon so I'll try to turn any feedback quickly (and I'm happy to get any and all feedback - spellings, unclear working, wrong JSON terminology etc..)
2017-02-08 12:43:04 -08:00
Gabe Rosenhouse f85ac247e6 Merge pull request #361 from ofiliz/issue-360
invoke: Enable plugin file names with extensions
2017-02-08 10:15:49 -08:00
Onur Filiz 271be6c8df invoke: Enable plugin file names with extensions
A CNI network configuration file contains the plugin's executable file name.
Some platforms like Windows require a file name extension for executables.
This causes unnecessary burden on admins as they now have to maintain two
versions of each type of netconfig file, which differ only by the ".exe"
extension. A much simpler design is for invoke package to also look for
well-known extensions on platforms that require it. Existing tests are
improved and new tests are added to cover the new behavior.

Fixes #360
2017-02-04 12:01:47 -08:00
Gabe Rosenhouse fc7de21fe2 Merge pull request #364 from pires/build_tag
pkg/utils/sysctl/sysctl_linux.go: couple fixes
2017-02-03 14:18:39 -05:00
Paulo Pires 4c0b8f7054 pkg/utils/sysctl/sysctl_linux.go: fix typo. 2017-02-03 05:39:04 +00:00
Paulo Pires 246300ccfe
pkg/utils/sysctl/sysctl_linux.go: fix build tag. 2017-02-03 05:38:53 +00:00
Tom Denham e663e98444 Merge pull request #359 from ofiliz/issue-355
libcni, pkg\invoke: Use OS-specific list separator when parsing CNI_PATH
2017-02-02 12:35:07 -08:00
Onur 0d9a1d70f8 spec, libcni, pkg/invoke: Use OS-agnostic separator when parsing CNI_PATH
Hardcoding the list separator character as ":" causes CNI to fail when parsing
CNI_PATH on other operating systems. For example, Windows uses ";" as list
separator because ":" can legally appear in paths such as "C:\path\to\file".
This change replaces use of ":" with OS-agnostic APIs or os.PathListSeparator.

Fixes #358
2017-01-28 16:47:58 -08:00
Gabe Rosenhouse c4271dba67 Merge pull request #145 from dcbw/pass-ifname-back
Pass interface name and MAC back to runtime
2017-01-25 11:20:57 -08:00
Dan Williams d5acb127b8 spec/plugins: return interface details and multiple IP addresses to runtime
Updates the spec and plugins to return an array of interfaces and IP details
to the runtime including:

- interface names and MAC addresses configured by the plugin
- whether the interfaces are sandboxed (container/VM) or host (bridge, veth, etc)
- multiple IP addresses configured by IPAM and which interface they
have been assigned to

Returning interface details is useful for runtimes, as well as allowing
more flexible chaining of CNI plugins themselves.  For example, some
meta plugins may need to know the host-side interface to be able to
apply firewall or traffic shaping rules to the container.
2017-01-25 11:31:18 -06:00
Dan Williams befad17174 pkg/ipam: add testcases 2017-01-25 11:31:18 -06:00
Dan Williams b0b896f79a plugins/flannel: organize test JSON alphabetically
Otherwise the test fails, since Go's JSON marshaller prints
dict items alphabetically in its String() call.
2017-01-25 11:31:18 -06:00
Dan Williams ad2a5ccb61 macvlan/ipvlan: use common RenameLink method 2017-01-25 11:31:18 -06:00
Dan Williams befb95977c types: make Result an interface and move existing Result to separate package 2017-01-25 11:31:18 -06:00
Dan Williams cb4cd0e12c testutils: pass netConf in for version operations; pass raw result out for tests 2017-01-25 11:31:18 -06:00
Gabe Rosenhouse dcadf4f9b5 Merge pull request #355 from rosenhouse/skel-main-errors
skel: adds PluginMainWithError which returns a *types.Error
2017-01-23 07:42:57 -08:00
Gabe Rosenhouse af5c2f303a skel: adds PluginMainWithError which returns a *types.Error
Enables plugins to do their own error-handling and cleanup logic
2017-01-22 16:57:42 -08:00
Gabe Rosenhouse 1acc927ab0 Merge pull request #352 from containernetworking/conventions
Documentation: Add conventions doc
2017-01-20 13:50:24 -08:00
Tom Denham 04f357344d Update CONVENTIONS.md 2017-01-20 12:49:00 -08:00
Gabe Rosenhouse e476ab7189 Merge pull request #346 from dcbw/ordered-chaining
api/plugins: implement ordered plugin chaining
2017-01-20 08:35:37 -08:00
Dan Williams 0c2a034f01 api,libcni: add network config list-based plugin chaining
Using a new ".configlist" file format that allows specifying
a list of CNI network configurations to run, add new libcni
helper functions to call each plugin in the list, injecting
the overall name, CNI version, and previous plugin's Result
structure into the configuration of the next plugin.
2017-01-19 22:28:21 -06:00
Dan Williams 7e16c86a52 spec: add network configuration list specification 2017-01-19 22:28:20 -06:00
Tom Denham 947b79e334
Spec/Conventions: Update to include plugin config 2017-01-19 18:05:28 -08:00
Dan Williams 0a1b48f520 noop: allow specifying debug file in config JSON
Chaining sends different config JSON to each plugin, but the same
environment, and if we want to test multiple noop plugin runs in
the same chain we need a way of telling each run to use a different
debug file.
2017-01-19 09:56:42 -06:00
Tom Denham d716d73444 Documentation: Add conventions doc 2017-01-17 15:53:24 -08:00
Tom Denham 530dd71e19 Merge pull request #334 from squeed/host-local-dns
ipam/host-local: add ResolvConf argument for DNS configuration
2017-01-12 17:06:04 -08:00
Tom Denham fa58dd8889 Merge pull request #350 from rosenhouse/spec-version
spec: notice of version
2017-01-12 13:42:25 -08:00
Gabe Rosenhouse 20fde00ea6 spec: notice of version 2017-01-11 18:49:10 -08:00
Casey Callendrello 5cde14cd7b ipam/host-local: add ResolvConf argument for DNS configuration
This adds the option `resolvConf` to the host-local IPAM configuration.
If specified, the plugin will try to parse the file as a resolv.conf(5)
type file and return it in the DNS response.
2017-01-11 18:48:35 +01:00
Tom Denham 4406607649 Merge pull request #115 from aanm/implementing-ipam-as-lib
ipam/host-local: Move allocator and config to backend
2017-01-10 13:06:46 -08:00
André Martins f60111b093 ipam/host-local: Move allocator and config to backend
Signed-off-by: André Martins <aanm90@gmail.com>
2016-12-21 04:43:21 +00:00
Gabe Rosenhouse 98ff61aac3 Merge pull request #325 from squeed/update-maintainer
MAINTAINERS: hi CaseyC!
2016-12-19 11:02:20 -08:00
Casey Callendrello 6dc01a772b MAINTAINERS: hi CaseyC! 2016-12-19 12:38:29 -05:00
Gabe Rosenhouse e3bcc3e41b Merge pull request #345 from rosenhouse/travis-go-versions
travis: roll forward the versions of Go that we test
2016-12-16 08:06:17 -08:00
Gabe Rosenhouse bc1d61e3db travis: roll forward the versions of Go that we test 2016-12-15 18:41:07 -08:00
Gabe Rosenhouse 652bae1deb Merge pull request #314 from rosenhouse/noop-helpful-message
plugins/noop: return a helpful message for test authors
2016-12-15 18:35:43 -08:00
Gabe Rosenhouse 47f6604b5a Merge pull request #344 from dcbw/interface-checks
all: assert internal objects implement interfaces
2016-12-15 18:34:57 -08:00
Gabe Rosenhouse 1c1cf2faf7 Merge branch 'master' into interface-checks 2016-12-15 18:20:34 -08:00
Gabe Rosenhouse ef00f717a6 Merge pull request #341 from dcbw/host-local-trim
host-local: trim whitespace from container IDs and disk file contents
2016-12-15 18:18:25 -08:00
Dan Williams 5852c60bc4 all: assert internal objects implement interfaces 2016-12-14 17:09:01 -06:00
Dan Williams 20ae9e156d Merge pull request #340 from vzcambria/master
Fix README.md host-local IPAM range start/end typo
2016-12-09 18:22:08 -06:00
Dan Williams 76028d7f8c host-local: trim whitespace from container IDs and disk file contents
It doesn't seem like container IDs should really have whitespace or
newlines in them.  As a complete edge-case, manipulating the host-local
store's IP reservations with 'echo' puts a newline at the end, which
caused matching to fail in ReleaseByID().  Don't ask...
2016-12-09 18:16:38 -06:00
VZ Cambria 2ba6d20007 Fix README.md host-local IPAM range start/end typo 2016-12-06 10:40:55 -05:00
Konstantinos Karampogias accac60053 plugins/noop: return a helpful message for test authors
Signed-off-by: Gabe Rosenhouse <grosenhouse@pivotal.io>
2016-12-02 15:04:01 -08:00
Dan Williams b0808a006a Merge pull request #335 from JulienBalestra/json_ext
libcni conf: support .json file extension
2016-12-02 13:33:36 -06:00
Julien Balestra a85593ce0d libcni conf: support .json file extension
Content of the files are json, the configuration load should support .json
2016-11-23 10:48:32 +01:00
Dan Williams de002ff25a Merge pull request #322 from cf-container-networking/flannel-cni-stateDir
Allow flannel CNI plugin stateDir to be configurable
2016-11-18 15:27:35 -06:00
Mark St.Godard 6eac0ee904 flannel: rename stateDir to dataDir
Rename StateDir to DataDir for flannel CNI plugin
2016-11-17 15:54:29 -06:00
Gabe Rosenhouse 46e3a6b7be Merge pull request #330 from bboreham/ns-warning
Expand description of goroutine+netns problems
2016-11-17 08:00:31 -08:00
Bryan Boreham c20f895fa8 Expand description of goroutine+netns problems 2016-11-17 15:45:38 +00:00
Gabe Rosenhouse ba6c5af5dc Merge pull request #327 from dcbw/host-local-tests
host-local: add DataDir IPAM conf option and use it for testcases
2016-11-14 08:17:40 -08:00
Mark St.Godard 15de81eac6 flannel: updated flannel test to use pkg/testutils
reworked the flannel test to use testutils CmdAddWithResult and
CmdDelWithResult
2016-11-13 12:16:32 -06:00
Gabe Rosenhouse 8b827d74b3 Merge pull request #328 from markstgodard/noop-cni-args
noop plugin: support multiple CNI_ARGS
2016-11-10 22:24:58 -08:00
Mark St.Godard 48d3b46eb2 noop plugin: support multiple CNI_ARGS
Updated noop plugin to parse the CNI_ARGS pairs, to allow more than just
the DEBUG arg.
2016-11-10 16:04:42 -06:00
Dan Williams 7b2006eed8 Merge pull request #324 from lstoll/lstoll-ipvlan-l3s
ipvlan: Support L3-Symmetric mode
2016-11-10 12:53:59 -06:00
Dan Williams e085226f82 host-local: add DataDir IPAM conf option and use it for testcases
Add an e2e host-local plugin testcase, which requires being able
to pass the datadir into the plugin so we can erase it later.
We're not always guaranteed to have access to the default data
dir location, plus it should probably be configurable anyway.
2016-11-10 12:12:16 -06:00
Mark St.Godard e6113c6517 flannel: update flannel documentation
add optional 'stateDir' to flannel docs
2016-11-09 09:34:35 -06:00
Gabe Rosenhouse 79643855f7 Merge pull request #307 from squeed/backwards-compatability-tests
testing: test invocation of newer plugins with an older libcni
2016-11-07 14:25:09 -08:00
Mark St.Godard f0daefa63d flannel: add unit tests for config loading
backfill unit tests to add coverage for loadFlannelNetConf and
loadFlannelSubnetEnv
2016-11-05 23:27:14 -05:00
Lincoln Stoll 9201f3f1d9
ipvlan: Support ipvlan l3s mode.
This landed in kernel in 4fbae7d
2016-11-05 13:41:07 -07:00
Lincoln Stoll 2ad1d04561
vendor: github.com/vishvananda/netlink@a1f8555
Update to current master, to get IPVLAN L3s def.
2016-11-05 13:41:01 -07:00
Mark St.Godard fa264e6e36 flannel: add integration test suite
add new test for flannel plugin that delegates to the noop plugin and
validates that 'storeDir' can be configurable
2016-11-05 10:47:07 -05:00
Mark St.Godard b463642ac0 Allow flannel CNI plugin stateDir to be configurable
- Add optional 'stateDir' to flannel NetConf, if not present default to
/var/lib/cni/flannel

Signed-off-by: Jay Dunkelberger <ldunkelberger@pivotal.io>
2016-11-03 17:10:13 -05:00
Casey Callendrello 8c6f6e0a60 testing: test invocation of newer plugins with an older libcni 2016-10-25 16:33:35 +02:00
Gabe Rosenhouse 0e09ad29df Merge pull request #312 from tomdee/slack
Add slack badge and link
2016-10-24 16:25:48 -07:00
Tom Denham bb8bcf08a8 Add slack badge and link 2016-10-24 16:23:04 -07:00
Gabe Rosenhouse 194f8ce6ea Merge pull request #311 from rkamudhan/patch-2
Update ipvlan.md
2016-10-23 16:23:55 -07:00
Kuralamudhan Ramakrishnan 6e77c7f4f7 Update ipvlan.md
invalid json format
2016-10-23 23:18:44 +01:00
Gabe Rosenhouse bff05e7572 Merge pull request #308 from rosenhouse/fix-skel-tests-containerid
skel tests: correct name of CNI_CONTAINERID in tests of env vars
2016-10-17 15:02:27 -07:00
Gabe Rosenhouse 8be31e1c6f skel tests: correct name of CNI_CONTAINERID in tests of env vars 2016-10-16 17:18:57 -07:00
Gabe Rosenhouse 3450f08611 Merge pull request #305 from yuewko/add_infoblox_link
Add link to Infoblox IPAM plugin
2016-10-16 17:08:51 -07:00
Yue Ko c24fce2ae8 Add link to Infoblox IPAM plugin
Added link to Infoblox IPAM plugin in README.
2016-10-11 11:07:30 -07:00
Gabe Rosenhouse d872391998 Merge pull request #304 from danp/patch-1
docs/ptp: fix markdown formatting
2016-10-09 22:39:31 -07:00
Dan Peterson 85ab5c0f21 docs/ptp: fix markdown formatting 2016-10-09 21:22:27 -03:00
Dan Williams af88b7c6cf Merge pull request #301 from rosenhouse/backwards-compatibility-tests
A test verifies that libcni is backwards compatible with legacy plugins
2016-10-06 10:10:02 -05:00
Gabe Rosenhouse 165ca6f719 travis: git clone at great depth
ensures that git commits referenced by backwards compatibility tests are
always available in CI.
2016-10-05 20:48:53 -07:00
Gabe Rosenhouse 0087f302ea Merge pull request #302 from rosenhouse/readme-3rd-party-plugins
3rd party plugins belong in their own repos
2016-10-03 08:39:23 -07:00
Gabe Rosenhouse b2ef4aa1a7 docs: on contributing plugins to this repo 2016-10-02 23:44:59 -07:00
Gabe Rosenhouse 51b51a0182 testing: adds basic test of backwards compatibility 2016-10-02 22:18:53 -07:00
Dan Williams a29fc24f11 Merge pull request #296 from rosenhouse/plugins-require-versioned-config
Plugins validate cniVersion of NetConf
2016-09-22 17:11:34 -05:00
Dan Williams b5e0a4ef2e Merge pull request #298 from freehan/fix-host-local-30
host-local: fix allocation of last address in a /30
2016-09-22 09:13:32 -05:00
Minhan Xia 52e4358cbd host-local: fix allocation of last address in a /30 2016-09-21 13:10:05 -07:00
Brandon Philips e70e6034d2 Merge pull request #299 from tgraf/cilium-link
List cilium as 3rd party plugin
2016-09-19 14:31:54 -07:00
Gabe Rosenhouse 5b696f3307 skel: use named constant for Incompatible CNI Version error code 2016-09-19 13:25:33 -07:00
Gabe Rosenhouse 0135e2751e versioning: ipam config is not versioned 2016-09-19 13:25:28 -07:00
Gabe Rosenhouse fba37620e0 versioning: plugins require version match with config
infer version 0.1.0 when config is missing an explicit "cniVersion" field
2016-09-19 13:00:49 -07:00
Gabe Rosenhouse 64bbcd8cf7 versioning: add basic version decode for network config 2016-09-19 12:57:08 -07:00
Thomas Graf 75d983ec25 README: List cilium as 3rd party plugin
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2016-09-19 13:45:39 +02:00
Gabe Rosenhouse fd150a4c97 skel: Plugins require a cniVersion in the NetConf 2016-09-18 21:30:57 -07:00
Gabe Rosenhouse 56032390fe Merge pull request #287 from rosenhouse/multi-version
Plugins report a list of supported versions
2016-09-12 13:44:14 -07:00
Gabe Rosenhouse 3f4011b3ec Merge pull request #295 from rosenhouse/update-readme-cloudfoundry-link
readme: update link to CloudFoundry usage of CNI
2016-09-08 00:47:04 -04:00
Gabe Rosenhouse d32ccb1899 readme: update link to CloudFoundry usage of CNI 2016-09-06 23:48:48 -04:00
Gabe Rosenhouse 7958b9f0cc versioning: revert spec version to 0.2.0 2016-09-06 15:37:42 -04:00
Gabe Rosenhouse d5e2e375d4 versioning: misc cleanups
highlights:
 - NetConf struct finally includes cniVersion field
 - improve test coverage of current version report behavior
 - godoc a few key functions
 - allow tests to control version list reported by no-op plugin
2016-09-06 15:35:58 -04:00
Gabe Rosenhouse 07a8a28637 Merge pull request #294 from dcbw/host-local-ranges
Fix handling of host-local IP address ranges
2016-09-05 23:24:42 -04:00
Dan Williams 95a9ea0bd2 host-local: don't allocate the broadcast address or allow invalid networks
There aren't any IPs to allocate in /32 or /31 networks, so don't allow them.
2016-09-02 17:20:09 -05:00
Dan Williams 959af1e6ab host-local: ensure requested IPs are within the given range
And also make sure that RangeStart and RangeEnd are sane.
2016-09-02 16:52:29 -05:00
Dan Williams dfc4f7cd2a host-local: don't allocate past RangeEnd
When RangeEnd is given, a.end = RangeEnd+1.

If when getSearchRange() is called and lastReservedIP equals
RangeEnd, a.nextIP() only compares lastReservedIP (which in this
example is RangeEnd) against a.end (which in this example is
RangeEnd+1) and they clearly don't match, so a.nextIP() returns
start=RangeEnd+1 and end=RangeEnd.

Get() happily allocates RangeEnd+1 because it only compares 'cur'
to the end returned by getSearchRange(), not to a.end, and thus
allocates past RangeEnd.

Since a.end is inclusive (eg, host-local will allocate a.end) the
fix is to simply set a.end equal to RangeEnd.
2016-09-02 16:37:34 -05:00
Gabe Rosenhouse bf31ed1591 invoke: better name and unit test coverage for GetVersionInfo 2016-09-02 16:39:01 -04:00
Gabe Rosenhouse 97192fc979 invoke: correctly infer version for 0.1.0-vintage plugins
Older plugins return a known error when issued the VERSION command.
Capture this error and report it as a 0.1.0 version plugin.
2016-09-02 16:02:07 -04:00
Gabe Rosenhouse deb4466041 versioning: adds tooling to compile a program against a given old CNI version
Allows us to write tests that cover interactions between components of
differing versions
2016-09-02 16:02:02 -04:00
Gabe Rosenhouse dea1c6e44d pkg/invoke: refactor plugin exec and backfill unit tests 2016-09-02 15:59:25 -04:00
Gabe Rosenhouse adf28a84c6 versioning: document meaning of 'Legacy' version support 2016-09-02 11:26:17 -04:00
Gabe Rosenhouse 536cb5b99b versioning: plugins report a list of supported versions
Further progress on versioning support (Issue #266).
Bump CNI spec version to 0.3.0
2016-09-02 11:26:17 -04:00
Gabe Rosenhouse c5e39a87f7 Merge pull request #293 from rosenhouse/backfill-invoke-exec-tests
Backfill tests for plugin execution
2016-08-31 20:49:08 -04:00
Dan Williams e0ea82b229 Merge pull request #290 from asridharan/dcos
Fixed the check for network namespace path.
2016-08-31 18:19:02 -05:00
Avinash Sridharan 7281d5792a pkg/ns: fixed the check for network namespace path.
The expectation on older kernels (< 3.19) was to have the network
namespace always be a directory. This is not true if the network
namespace is bind mounted to a file, and will make the plugin fail
erroneously in such cases. The fix is to remove this assumption
completely and just do a basic check on the file system types being
returned.

Fixes #288
2016-08-31 21:41:00 +00:00
Dan Williams 4d77bc177c Merge pull request #291 from tomdee/SetupVeth
pkg/ip: Ensure that SetupVeth returns correct hostVeth
2016-08-31 16:32:09 -05:00
Tom Denham 726c6b4578 pkg/ip: Ensure that SetupVeth returns correct hostVeth
The veth is moved from the container NS to the host NS.
This is handled by the code that sets the link to UP but the wrong
hostVeth is returned to the calling code.
2016-08-31 14:17:25 -07:00
Gabe Rosenhouse d3ecadb860 invoke: backfill tests for plugin execution 2016-08-30 23:52:47 -04:00
Gabe Rosenhouse 9d5e6e60e7 Merge pull request #241 from luxas/add_platforms
Add arm64 and ppc64le as new platforms
2016-08-13 15:11:28 -07:00
Lucas Käldström 39f8436a8b release: Release binaries for arm, arm64 and ppc64le too
Modify the releasing script to cross-compile for the new architectures, but also keep backwards-compability

ref #209
2016-08-13 12:45:04 +03:00
Lucas Käldström 21d25959ee travis: Cross-compile for arm, arm64 and ppc64le on every build
Cross-compile cni for arm, arm64 and ppc64le with go1.6 only
Allow go tip to fail
Set fast_finish to true, which means travis will instantly return build failure when any of the required builds fail

ref #209
2016-08-13 12:44:45 +03:00
Lucas Käldström fc58b79b45 build: Update the build script to make it possible to build for other architectures
This makes it possible to cross-compile cni like so:
$ GOARCH=arm ./build
$ GOARCH=arm64 ./build
$ GOARCH=ppc64le ./build

ref #209
2016-08-13 12:44:28 +03:00
Lucas Käldström 488db88fd1 vendor: Bump golang.org/x/sys/unix to a newer version
The current vendor of sys/unix is really old, and doesn't work on arm64 and ppc64le
Updating to the latest version might also fix other issues

ref #209
2016-08-13 12:44:04 +03:00
Tom Denham 349d66d51c Merge pull request #267 from rosenhouse/version-cmd
Adds VERSION command
2016-08-12 15:06:22 -07:00
Tom Denham 5a67f5d6fb Merge pull request #273 from zreigz/reconfigure-bridge-ip
Reconfigure bridge IP address
2016-08-12 15:04:22 -07:00
Tom Denham 60bb795c2e Merge pull request #274 from lukasredynk/update_netlink
Update of netlink version
2016-08-12 13:07:26 -07:00
Tom Denham 113dfd61bd Merge pull request #280 from prateekgogia/bug-fix-155
pkg/ip: Return correct error if container name provided exists, and test cases
2016-08-12 13:04:49 -07:00
Prateek Gogia ad8a052dd3 pkg/ip: Return correct error if container name provided exists, and test cases
If interface name for a container provided by a user is already present,
Veth creation fails with incorrect error.
If os.IsExist error is returned by makeVethPair:
* Check for peer name, if exists generate another random peer name,
* else, IsExist error is due to container interface present, return error.

Fixes #155
2016-08-11 18:51:03 +00:00
Lukasz Zajaczkowski 8cb3a9323a libcni: add util function InjectConf 2016-08-08 13:21:25 +02:00
Stefan Junker 7c579af789 Merge pull request #277 from steveeJ/test-allocator-reserveip
ipam/host-local/allocator tests: cover requested IP
2016-08-02 14:43:43 -07:00
Lukasz Zajaczkowski ee64ac74bc documentation: add description for forceAddress parameter 2016-08-02 07:33:44 +02:00
Lukasz Zajaczkowski d09b18dac4 plugins: reconfigure bridge IP address
Add possibility to reconfigure bridge IP address when there is a new value.
New boolean flag added to net configuration to force IP change if it is need.
Otherwise code behaves as previously and throws error
2016-08-02 07:33:17 +02:00
Stefan Junker 054fa9e42d ipam/host-local/allocator tests: cover requested IP
Further:
* improve error handling
2016-08-01 18:13:15 -07:00
Stefan Junker f5ead7969a Merge pull request #254 from steveeJ/ip-based-macaddr
pkg/ipam: IP based macaddr
2016-08-01 17:43:49 -07:00
Stefan Junker c0ac3913a1 pkg/utils/hwaddr tests: cover v4 in v6 addr 2016-08-01 16:50:40 -07:00
Lukas Redynk 35ce5d68e0 Update of netlink version
This is required for
https://github.com/containernetworking/cni/issues/251 because version of
netlink used doesn't support creating tap devices.
2016-08-01 14:04:03 +02:00
Tom Denham c1ff202179 Merge pull request #272 from rosenhouse/types-of-users
README: distinguish between runtimes and plugins
2016-07-25 16:35:58 -07:00
Stefan Junker 5a52316ab5 plugins/{bridge,macvlan} test: ensure hardware addr
* bridge: Test the following interface's hardware address for the CNI specific
prefix:
  - bridge with IP address
  - container veth
* plugins/macvlan test: ensure hardware addr
2016-07-22 15:40:00 -07:00
Stefan Junker f68cea27bc pkg/ip link_test: ensure SetHWAddrByIP has an effect 2016-07-22 15:34:54 -07:00
Stefan Junker 55fd81f775 plugins/ptp: set the host veth hwaddr correctly 2016-07-22 15:34:54 -07:00
Stefan Junker 7d19c01818 pkg/ip: use iface name in SetHWAddrByIP 2016-07-22 15:34:53 -07:00
Stefan Junker 8e1c215116 pkg/ip tests: cover SetupVeth and DelLinkByName* 2016-07-22 15:34:53 -07:00
Stefan Junker 924b30b57d plugins: set MAC addresses based on IP
This will give deterministic MAC addresses for all interfaces CNI
creates and manages the IP for:
* bridge: container veth and host bridge
* macvlan: container veth
* ptp: container veth and host veth
2016-07-22 15:34:53 -07:00
Stefan Junker 3a1354cff6 pkg/utils/hwaddr: migrate code from IPAM pkg 2016-07-22 15:18:38 -07:00
Stefan Junker 96867eae05 pkg/ipam{,test}: improve error handling and tests
* _suite.go and _test.go file should be in the same package, using the
  _test package for that, which requires some fields and methods to be
  exported
* Introduce error type for cleaner error handling
* test adaptions for error type checking
2016-07-22 15:17:22 -07:00
Minhan Xia 1c1424c472 add tests for generateHardwardAddr 2016-07-22 15:01:57 -07:00
Minhan Xia b2e53181d1 configure mac address based on assigned ip 2016-07-22 14:57:52 -07:00
Gabe Rosenhouse 39a8fe4766 Merge pull request #270 from rosenhouse/integration-tests
Add integration tests of libcni
2016-07-22 13:36:20 -07:00
Gabe Rosenhouse c657c61767 plugins: cleanup tests of no-op plugin 2016-07-22 13:30:55 -07:00
Gabe Rosenhouse 424a8b38cf README: distinguish between runtimes and plugins
Adds a link to the 3rd party SR-IOV plugin.
2016-07-22 13:22:35 -07:00
Gabe Rosenhouse dfd2c142ae docs: fix tuning doc, correct the result json
it does not report the version, it never did
2016-07-21 13:06:05 -07:00
Gabe Rosenhouse 7bc96f05bb spec: add version command and increment version to 0.2.0 2016-07-21 12:59:08 -07:00
Gabe Rosenhouse 0506bae8fc spec: remove CNI_VERSION env var, was never been implemented
No one uses this, and it is causing confusion (see #150)
2016-07-20 13:39:51 -07:00
Gabe Rosenhouse bacdc3668d libcni: add integration test coverage 2016-07-15 13:01:08 -07:00
Gabe Rosenhouse 5835c2bbb1 plugins: adds new no-op plugin that may be used as a test-double
Plugin can be configured to record all inputs and to respond with
arbitrary stdout or error message.  Will support upcoming integration
testing.
2016-07-15 12:48:02 -07:00
Gabe Rosenhouse 7f098f7c4a Merge pull request #269 from rosenhouse/skel-dependency-injection
Refactor skel with dependency injection
2016-07-15 12:45:18 -07:00
Gabe Rosenhouse a2aff8c6a8 misc: fix up copyright dates 2016-07-14 16:09:27 -07:00
Tom Denham f484990a00 Merge pull request #263 from feiskyer/ptp-test
plugins/main/ptp: add functional tests
2016-07-14 14:32:05 -06:00
Gabe Rosenhouse 63755d7c57 pkg/skel: plugins now respond to VERSION command
To support CNI spec versioning, plugins must be able to report version
information to container runtimes.
2016-07-14 00:24:32 -04:00
Gabe Rosenhouse f436418525 pkg/skel: improve error message for missing CNI_COMMAND env var
This makes the error message for missing CNI_COMMAND consistent with
that of other required environment variables.
2016-07-14 00:24:32 -04:00
Gabe Rosenhouse c17e700759 pkg/skel: missing env var log lines appear in stderr
Previously, the log lines appeared in stdout before the JSON encoding of
the error message.  That would break JSON parsing of stdout.  Instead, we use
stderr for these unstructured logs, consistent with the CNI spec.
2016-07-14 00:24:27 -04:00
Gabe Rosenhouse 791d259e55 pkg/skel: refactor to use dependency injection
Extract dependencies on os to enable more complete unit test coverage
2016-07-14 00:06:58 -04:00
Pengfei Ni cd14fc0e06 plugins/main/ptp: add functional tests 2016-07-11 09:25:36 +08:00
Gabe Rosenhouse 8a93673209 Merge pull request #264 from rosenhouse/test-with-vagrant
Add Vagrantfile, document how to run test suite in a vagrant VM
2016-07-06 11:33:32 -07:00
Gabe Rosenhouse 0c2b5f5139 Add Vagrantfile, document how to run test suite in a vagrant VM 2016-07-05 23:12:02 -07:00
Tom Denham b8e92ed030 Merge pull request #247 from tomdee/spec-args-field
SPEC: introduce "args" field and new error code
2016-06-14 15:31:23 -07:00
Tom Denham 7b381a1af2 SPEC: introduce "args" field and new error code
Based on previous discussions on the CNI maintainers calls, the spec is
unclear on 1) when CNI_ARGS should be used and 2) the fact the dynamic
config can be passed in through the network JSON.

This PR makes it clear that per-container config can be passed in
through the network JSON, adding a top level `args` field into
which orchestrators can add additional metadata without worrying that
plugins might reject the additional data. It also allows for plugins to
reject unknown fields passed in at the top level.

Using JSON is preferable to CNI_ARGS since it allows namespaced and
structured data. CNI_ARGS is a flat list of KV pairs which has reserved
characters with no escaping rules defined.
CNI_ARGS may still be used by orchestrators that want the simplicity of
passing the network config JSON as specified by the user, unchanged
through to the CNI plugin. But for any kind of structured data, it's
recommended that the `args` field in the JSON is used instead.
2016-06-14 15:02:51 -07:00
Lee Calcote 4666a24b6d README: grammatical corrections 2016-06-14 09:54:15 -07:00
Pengfei Ni 0136a73037 pkg/ns: fix misspelling in comment 2016-06-14 09:52:58 -07:00
Stefan Junker 3bee295ba5 Merge pull request #240 from steveeJ/unmarshall-string
pkg/types: unmarshal string tests
2016-06-13 18:30:24 -07:00
Stefan Junker 3476000725 pkg/types: cover string for unmarshal tests 2016-06-13 18:18:36 -07:00
Stefan Junker 17dcf87589 Merge pull request #238 from tomdee/string-unmarshaller
pkg/types: Add UnmarshallableString type
2016-06-13 18:17:48 -07:00
Stefan Junker c3c0803817 Merge pull request #243 from containernetworking/maintainers-update-email
MAINTAINERS: Update @tomdee email address
2016-06-10 01:41:42 +02:00
Tom Denham 0ffad38994 MAINTAINERS: Update @tomdee email address 2016-06-09 16:32:26 -07:00
Tom Denham 031567c216 pkg/types: Add UnmarshallableString type
Allow strings to be unmarshalled for CNI_ARGS

CNI_ARGS uses types.LoadArgs to populate a struct.
The fields in the struct must meet the TextUnmarshaler interface.

This code adds a UnmarshallableString type to assist with this.
2016-06-09 14:45:58 -07:00
Stefan Junker c6864e1060 Merge pull request #229 from steveeJ/cleanup-travis
travis: cleanup and bump go versions
2016-06-02 20:43:11 +02:00
Minhan Xia 2445a960a9 plugins/ipam: round robin ip allocation for host-local ipam
This changes the ip allocation logic to round robin. Before this, host-local IPAM searched for available IPs from start of subnet. Hence it tends to allocate IPs that had been used recently. This is not ideal since it may cause collisions.
2016-06-02 20:37:05 +02:00
Tom Denham 5c3c171642 Merge pull request #239 from steveeJ/master
MAINTAINERS: remove @zachgersh, add @dcbw
2016-06-02 09:00:07 -07:00
Michael Bridgen 4a292cd451 Merge pull request #218 from steveeJ/roadmap
Add ROADMAP document
2016-06-02 16:51:57 +01:00
Stefan Junker f82af22b10 ROADMAP: initial version 2016-06-02 17:50:14 +02:00
Stefan Junker 4f9faf60bb MAINTAINERS: remove @zachgersh, add @dcbw
Thank you Zach for all the great work done on CNI, farewell!
At the same time we are happy to welcome Dan amongst us who has already
contributed lots of valuable work!
2016-06-02 01:15:24 +02:00
Stefan Junker f44f4cf953 Merge pull request #219 from squaremo/more-contrib
docs: details on PR acceptance policy
2016-06-01 16:03:17 +02:00
Michael Bridgen ddc0ca4791 docs: details on PR acceptance policy 2016-06-01 12:23:21 +01:00
Michael Bridgen e90d8c12b1 Merge pull request #228 from jieyu/add_mesos
Added Mesos to CNI users.
2016-05-30 11:13:34 +01:00
Stefan Junker ffff8ac2fd Merge pull request #231 from steveeJ/ns-verifiy-errors
pkg/ns: introduce error types to indicate NS verification
2016-05-27 15:57:40 +02:00
Stefan Junker 35f3a090b2 pkg/ns: introduce error types indicate NS verification 2016-05-27 13:50:16 +02:00
Stefan Junker 131ecc4055 Merge pull request #230 from steveeJ/netns-optional-on-del
plugins: don't require CNI_NETNS for DEL command
2016-05-27 13:49:05 +02:00
Stefan Junker d582c9ce8f skel/test: add case for empty NETNS 2016-05-27 12:26:42 +02:00
Stefan Junker 72337159c1 plugins: don't require CNI_NETNS for DEL command
This will allow to free up the IPAM allocations when the caller doesn't
have access to the network namespace anymore, e.g. due to a reboot.
2016-05-27 10:57:39 +02:00
Stefan Junker 7f90f9d559 pkg/skel: allow arg requriements specified by CMD 2016-05-27 10:56:24 +02:00
Jie Yu d6674e0f49 README: add Mesos as CNI users 2016-05-26 09:42:10 -07:00
Stefan Junker 3b5d7a3bb0 travis: use go1.5.4 2016-05-26 15:33:58 +02:00
Stefan Junker 572fcc7076 travis: cleanup and bump go versions
* cleanup structure
* explicitly use go-{1.5.3,1.6.2}
2016-05-26 14:43:18 +02:00
Stefan Junker 6f63d9d707 Merge pull request #227 from steveeJ/ns-verify
pkg/ns: consider PROCFS during NS verification
2016-05-26 13:22:29 +02:00
Stefan Junker 3bab8a2805 pkg/ns: consider PROCFS during NS verification
This is an attempt to bring compatibility with Kernel <3.19, where NSFS
where PROCFS was used for network namespaces.
2016-05-26 12:42:50 +02:00
Stefan Junker 6fb30a6700 Merge pull request #222 from steveeJ/ns-check-path
pkg/ns: verify netns when initialized with GetNS
2016-05-25 08:54:10 +02:00
Stefan Junker d6751cea24 pkg/ns: test IsNSFS() 2016-05-24 22:30:49 +02:00
Stefan Junker c43ccc703a pkg/ns: test case for rejecting a non-ns nspath 2016-05-24 22:30:49 +02:00
Stefan Junker 76ea259ff9 pkg/ns: verify netns when initialized with GetNS 2016-05-24 22:30:49 +02:00
Stefan Junker c29cd52628 Merge pull request #223 from steveeJ/ns-respect-close
pkg/ns: don't allow operations after Close()
2016-05-24 22:16:09 +02:00
Stefan Junker 2de97b7e98 pkg/ns: add tests cases for Close()'d NS 2016-05-24 21:15:51 +02:00
Stefan Junker b23895a7c7 pkg/ns: don't allow operations after Close() 2016-05-24 20:52:00 +02:00
Stefan Junker 984ef8117a Merge pull request #217 from steveeJ/fix-go-tip
build: don't be verbose / test: fix bash variable escaping in sudo command
2016-05-21 01:55:57 +02:00
Stefan Junker 54c0cd2cad build: remove -x bash flag 2016-05-21 01:48:26 +02:00
Stefan Junker 232d7c095d test: fix bash variable escaping in sudo command 2016-05-21 01:48:26 +02:00
Stefan Junker 20fa3d35e8 Merge pull request #50 from steveeJ/gwfix
bridge: add isDefaultGateway field
2016-05-21 01:34:21 +02:00
Stefan Junker 8afda5faed tests/bridge: ensure isDefaultGateway works 2016-05-21 01:07:05 +02:00
Stefan Junker 534768fcd4 bridge: add isDefaultGateway field
When isDefaultGateway is true it automatically sets isGateway to true.
The default route will be added via the (bridge's) gateway IP.
If a default gateway has been configured via IPAM in the same
configuration file, the plugin will error out.
2016-05-21 00:38:42 +02:00
Stefan Junker d30040f9f7 Merge pull request #211 from dcbw/e2e-testing
Fix namespace switch issues and add ipvlan, macvlan, and bridge e2e testing
2016-05-21 00:17:45 +02:00
Dan Williams ebf83ffde5 bridge: add e2e testing 2016-05-20 17:10:25 -05:00
Dan Williams 552dc43168 macvlan: add e2e testing 2016-05-20 17:10:25 -05:00
Dan Williams 185e33ebe9 ipvlan: add e2e testing 2016-05-20 17:10:25 -05:00
Dan Williams 31da322f6e testutils: add e2e testing helper code 2016-05-20 17:10:25 -05:00
Dan Williams c0d34c692f ns: add interface, use it, and fix thread-related namespace switch issues
Add a namespace object interface for somewhat cleaner code when
creating and switching between network namespaces.  All created
namespaces are now mounted in /var/run/netns to ensure they
have persistent inodes and paths that can be passed around
between plugin components without relying on the current namespace
being correct.

Also remove the thread-locking arguments from the ns package
per https://github.com/appc/cni/issues/183 by doing all the namespace
changes in a separate goroutine that locks/unlocks itself, instead of
the caller having to track OS thread locking.
2016-05-20 17:10:25 -05:00
Stefan Junker 3e1c3c60da Merge pull request #199 from dcbw/fix-bridge-tx-queue-length
bridge: leave TX queue length as kernel default, not 0
2016-05-19 23:05:08 +02:00
Stefan Junker d29b895932 Merge pull request #212 from squaremo/more-contrib
docs: Mention license headers and doc contributions
2016-05-19 18:38:57 +02:00
Stefan Junker 398710b3c4 Merge pull request #214 from steveeJ/merge-v0.2
Merge v0.2
2016-05-19 15:45:07 +02:00
Stefan Junker 5fa06a39f0 release script: don't run the tests
For two reasons:

1. They're not functional within rkt
2. They rebuild the binaries dynamically
2016-05-19 15:05:29 +02:00
Stefan Junker c72dea5a20 build/release: link all release binaries statically 2016-05-19 15:05:29 +02:00
Stefan Junker 4aaffc2069 scripts: build static releases and create an ACI
* use SHA1 instead of MD5
2016-05-19 15:05:29 +02:00
Stefan Junker e145c60337 scripts: add "release with rkt"
This script uses rkt and a fedora image to build release tarballs.
2016-05-19 15:05:29 +02:00
Michael Bridgen bcc189e1e6 docs: Mention license headers and doc contributions
Closes #174.
2016-05-19 13:42:36 +01:00
Michael Bridgen 991176a64a Merge pull request #200 from squaremo/simplify-readme
Simplify README preamble
2016-05-19 13:21:40 +01:00
Michael Bridgen 8db1f0d503 README: Simplify preamble 2016-05-19 12:52:09 +01:00
Stefan Junker 74790e55ef Merge pull request #175. 2016-05-19 12:08:41 +02:00
Minhan Xia 89ab9299ab plugins/bridge: add support to set hairpin mode 2016-05-19 12:06:37 +02:00
Dan Williams f4eb76318e macvlan: sysctl must be set in macvlan interface's namespace
The macvlan is initially created in a separate network namespace
and the sysctl must be set in that namespace too.
2016-05-19 12:06:37 +02:00
Angus Lees a80bcc0371 pkg/ns: evaluate syscall number at compile-time
Previously this code used a run-time map lookup keyed by
runtime.GOOS/GOARCH.  This version uses conditional compilation to make
this choice at compile time, giving immediate feedback for unsupported
platforms.
2016-05-19 12:06:37 +02:00
Angus Lees 979044ad2f pkg/ns: use correct syscall number on arm 2016-05-19 12:06:37 +02:00
Jonathan Boulle ec78e7cf1e MAINTAINERS: add Tom Denham and Gabe Rosenhouse 2016-05-19 12:06:37 +02:00
Stefan Junker 5d67d22caa plugins/{ptp,bridge}: teardown first
This will allow the IPAM allocations to be cleared in case the
interfaces and iptables rules are non-existent.
2016-05-19 12:06:37 +02:00
Stefan Junker 2c482f433c *: appc/cni -> containernetworking/cni
The project has been moved so internally we simply rename everything.
Consumers are recommended to update their vendored version of cni.
2016-05-19 12:06:36 +02:00
Brandon Philips 419711fee3 README: fix badge links 2016-05-19 12:06:36 +02:00
Brandon Philips 04dbf7ce45 README: fix badges 2016-05-19 12:06:36 +02:00
Vipin Jain 61f20da4f2 README: add contiv to cni supported networking 2016-05-19 12:06:36 +02:00
Iago López Galeiras a993ef5f7f plugins/bridge: clean masquerading rules
In the Add command we set up masquerading rules that didn't have a
corresponding clean-up code in Del.

Add the clean-up code.
2016-05-19 12:06:36 +02:00
Tom Denham 41a5dfac33 Remove reference to policy on accepting PRs
There is to policy
2016-05-19 12:06:36 +02:00
Piotr Skamruk a1dab0aa40 macvlan: set proxy_arp in time of creating interface
Resolves CNI part of https://github.com/coreos/rkt/issues/1765
Second part would be adding similar lines into kvm flavored macvlan
support (in time of creating macvtap device).
2016-05-19 12:06:16 +02:00
Piotr Skamruk 4298aa94a5 pkg/utils: add functions to work with sysctl 2016-05-19 12:06:16 +02:00
Stefan Junker d53ffe1b40 README: clarify what CNI is
The word "standard" does not represent what CNI is actually trying to
be.
2016-05-19 12:06:16 +02:00
Gabe Rosenhouse b5e56b3dab Document use of goroutine and lockosthread in test helpers 2016-05-19 12:06:16 +02:00
Dan Williams 260c7f96bf ns: fix reading net namespace in multi-threaded processes
/proc/self/ns/net gives the main thread's namespace, not necessarily
the namespace of the thread that's running the testcases.  This causes
sporadic failures of the tests.

For example, with a testcase reading inodes after switching netns:

/proc/27686/task/27689/ns/net 4026532565
/proc/self/ns/net 4026531969
/proc/27686/task/27689/ns/net 4026532565

See also:
008d17ae00

Running Suite: pkg/ns Suite
===========================
Random Seed: 1459953577
Will run 6 of 6 specs

• Failure [0.028 seconds]
Linux namespace operations
/cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:167
  WithNetNS
  /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:166
    executes the callback within the target network namespace [It]
    /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:97

    Expected
        <uint64>: 4026531969
    to equal
        <uint64>: 4026532565

    /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:96
------------------------------
•••••

Summarizing 1 Failure:

[Fail] Linux namespace operations WithNetNS [It] executes the callback within the target network namespace
/cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:96

Ran 6 of 6 Specs in 0.564 seconds
FAIL! -- 5 Passed | 1 Failed | 0 Pending | 0 Skipped --- FAIL: TestNs (0.56s)
FAIL
2016-05-19 12:06:16 +02:00
Gabe Rosenhouse b09af2ff91 Fix issues with MakeNetworkNS test helper 2016-05-19 12:06:16 +02:00
Gabe Rosenhouse 1bbc87ab54 Add basic unit tests of testhelpers 2016-05-19 12:06:16 +02:00
Gabe Rosenhouse 4fc8a90277 Extract inode inspection functions into testhelpers 2016-05-19 12:06:16 +02:00
Gabe Rosenhouse 9044dc2831 Extract testhelpers from loopback test suite 2016-05-19 12:06:16 +02:00
Brandon Philips 5019e283b1 README: add some material on what CNI isn't
We get some questions about this stuff from time to time and I want to
acknowledge we have thought about them but aren't currently tackling
them.
2016-05-19 12:06:16 +02:00
Brandon Philips e7ae43e517 README: add some more details on what CNI is
We needed a bit more intro material to scope what CNI does. Here is my
attempt.
2016-05-19 12:06:16 +02:00
Stefan Junker 72e98b97d6 The macvlan is initially created in a separate network namespaceand the sysctl must be set in that namespace too.Fixes #208.
The macvlan is initially created in a separate network namespace
and the sysctl must be set in that namespace too.

Fixes #208.
2016-05-17 21:11:21 +02:00
Angus Lees 8f5194d9b5 pkg/ns: setns syscall number on arm and evaluate them at build time.
Dummy merge due to previous manual merge.
2016-05-17 18:44:33 +02:00
Stefan Junker 31379b8a41 Merge branch 'anguslees-master' 2016-05-17 18:36:38 +02:00
Angus Lees 2b019bfde1 pkg/ns: evaluate syscall number at compile-time
Previously this code used a run-time map lookup keyed by
runtime.GOOS/GOARCH.  This version uses conditional compilation to make
this choice at compile time, giving immediate feedback for unsupported
platforms.
2016-05-17 18:36:29 +02:00
Angus Lees a2f23f5a84 pkg/ns: use correct syscall number on arm 2016-05-17 18:36:22 +02:00
Dan Williams 899c0efd42 bridge: leave TX queue length as kernel default, not 0
Not using NewLinkAttrs() or not initializing TxQLen leaves
the value as 0, which tells the kernel to set a zero-length
tx_queue_len.  That messes up FIFO traffic shapers (like pfifo)
that use the device TX queue length as the default packet
limit.  This leads to a default packet limit of 0, which drops
all packets.
2016-05-12 10:35:50 -05:00
Michael Bridgen e1907bdab7 Merge pull request #201 from jonboulle/master
MAINTAINERS: add Tom Denham and Gabe Rosenhouse
2016-05-12 14:51:37 +01:00
Jonathan Boulle 463e171614 Merge pull request #205 from steveeJ/teardown-fix
plugins/{ptp,bridge}: teardown first
2016-05-12 10:54:47 +02:00
Stefan Junker d91971cbe0 plugins/{ptp,bridge}: teardown first
This will allow the IPAM allocations to be cleared in case the
interfaces and iptables rules are non-existent.
2016-05-11 19:47:55 +02:00
Jonathan Boulle bf8bde8256 MAINTAINERS: add Tom Denham and Gabe Rosenhouse 2016-05-10 12:12:05 +02:00
Stefan Junker 64791dd233 Merge pull request #198 from steveeJ/org-move
*: appc/cni -> containernetworking/cni
2016-05-06 17:58:44 +02:00
Brandon Philips e021964819 README: fix badge links 2016-05-06 08:39:55 -07:00
Brandon Philips 56ddbfd522 README: fix badges 2016-05-06 08:39:21 -07:00
Stefan Junker ed5f8dfeb2 *: appc/cni -> containernetworking/cni
The project has been moved so internally we simply rename everything.
Consumers are recommended to update their vendored version of cni.
2016-05-06 16:40:27 +02:00
Michael Bridgen fb34e4a21d Merge pull request #197 from jainvipin/master
Add Contiv to CNI supported networking
2016-05-05 09:15:15 +01:00
Vipin Jain 914a85c544 README: add contiv to cni supported networking 2016-05-04 20:29:13 -07:00
Michael Bridgen dbcecbcec6 Merge branch 'pr195' (clean up masq rules) 2016-05-04 13:50:09 +01:00
Iago López Galeiras 6aa26f9fd2 plugins/bridge: clean masquerading rules
In the Add command we set up masquerading rules that didn't have a
corresponding clean-up code in Del.

Add the clean-up code.
2016-05-03 12:21:58 +02:00
Dan Williams 99ca41457e macvlan: sysctl must be set in macvlan interface's namespace
The macvlan is initially created in a separate network namespace
and the sysctl must be set in that namespace too.
2016-04-28 11:26:47 -05:00
Michael Bridgen cae660409f Merge pull request #189 from tomdee/patch-2
Remove reference to policy on accepting PRs
2016-04-27 15:47:42 +01:00
Tom Denham 902ee8b992 Remove reference to policy on accepting PRs
There is to policy
2016-04-22 12:52:28 -07:00
Stefan Junker 911d941794 Merge pull request #187 from appc/v0.3.0
merge unneeded branch v0.3.0 into master
2016-04-22 19:25:54 +02:00
Michael Bridgen 8bb41b9d6f Merge pull request #186 from steveeJ/project-clarification
README: clarify what CNI is
2016-04-21 11:54:52 +01:00
Stefan Junker ef251cc6ce README: clarify what CNI is
The word "standard" does not represent what CNI is actually trying to
be.
2016-04-20 20:00:50 +02:00
Zach Gershman 57b28f3936 Merge pull request #182 from rosenhouse/document-lockosthread
Document use of goroutine and LockOSThread in test helpers
2016-04-18 10:45:46 -07:00
Zach Gershman 7383809048 Merge pull request #176 from dcbw/ns-test-fix
ns: fix reading net namespace in multi-threaded processes
2016-04-18 10:44:08 -07:00
Dan Williams 07a993dc7d ns: fix reading net namespace in multi-threaded processes
/proc/self/ns/net gives the main thread's namespace, not necessarily
the namespace of the thread that's running the testcases.  This causes
sporadic failures of the tests.

For example, with a testcase reading inodes after switching netns:

/proc/27686/task/27689/ns/net 4026532565
/proc/self/ns/net 4026531969
/proc/27686/task/27689/ns/net 4026532565

See also:
008d17ae00

Running Suite: pkg/ns Suite
===========================
Random Seed: 1459953577
Will run 6 of 6 specs

• Failure [0.028 seconds]
Linux namespace operations
/cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:167
  WithNetNS
  /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:166
    executes the callback within the target network namespace [It]
    /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:97

    Expected
        <uint64>: 4026531969
    to equal
        <uint64>: 4026532565

    /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:96
------------------------------
•••••

Summarizing 1 Failure:

[Fail] Linux namespace operations WithNetNS [It] executes the callback within the target network namespace
/cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:96

Ran 6 of 6 Specs in 0.564 seconds
FAIL! -- 5 Passed | 1 Failed | 0 Pending | 0 Skipped --- FAIL: TestNs (0.56s)
FAIL
2016-04-18 10:35:23 -05:00
Gabe Rosenhouse 94c4b25698 Document use of goroutine and lockosthread in test helpers 2016-04-17 20:27:02 -07:00
Zach Gershman 616702bcf3 Merge pull request #181 from rosenhouse/testhelpers-extraction
Extract and improve test helpers
2016-04-17 20:20:43 -07:00
Gabe Rosenhouse e3fb7ce3a7 Fix issues with MakeNetworkNS test helper 2016-04-17 19:47:54 -07:00
Gabe Rosenhouse dd3b85c9cc Add basic unit tests of testhelpers 2016-04-17 19:25:39 -07:00
Gabe Rosenhouse 54d7f73092 Extract inode inspection functions into testhelpers 2016-04-17 18:35:49 -07:00
Gabe Rosenhouse 5d932e4716 Extract testhelpers from loopback test suite 2016-04-17 18:28:10 -07:00
Michael Bridgen 9a2801085b Merge pull request #180 from philips/add-more-intro
README: add some more introductory material
2016-04-11 10:12:22 +01:00
Brandon Philips 4c778a63a7 README: add some material on what CNI isn't
We get some questions about this stuff from time to time and I want to
acknowledge we have thought about them but aren't currently tackling
them.
2016-04-10 18:23:06 -07:00
Brandon Philips d5a8ec9029 README: add some more details on what CNI is
We needed a bit more intro material to scope what CNI does. Here is my
attempt.
2016-04-10 18:22:38 -07:00
Stefan Junker 41ee449fb2 Merge pull request #177 from steveeJ/macvlan-arp-proxy
Macvlan arp proxy
2016-04-08 14:53:48 +02:00
Stefan Junker a06a464235 Merge pull request #178 from steveeJ/master
travis: don't go get vet
2016-04-08 14:35:58 +02:00
Stefan Junker 27d37cbdf1 travis: don't go get vet 2016-04-08 14:29:04 +02:00
Stefan Junker bc482febfb travis: don't go get vet 2016-04-08 14:22:20 +02:00
Piotr Skamruk b2f492e8b5 macvlan: set proxy_arp in time of creating interface
Resolves CNI part of https://github.com/coreos/rkt/issues/1765
Second part would be adding similar lines into kvm flavored macvlan
support (in time of creating macvtap device).
2016-04-07 21:40:58 +02:00
Piotr Skamruk 72bec92851 pkg/utils: add functions to work with sysctl 2016-04-07 21:40:51 +02:00
Stefan Junker a15a372021 Merge pull request #173 from jonboulle/master
*: add missing license headers + check
2016-04-02 15:22:40 +02:00
Jonathan Boulle f6135c7ba3 *: add missing license headers + check 2016-04-01 15:35:21 +02:00
Michael Bridgen 0046767be7 Merge pull request #172 from squaremo/readme_more
Readme improvements
2016-04-01 13:23:28 +01:00
Michael Bridgen fcbde68d32 docs: add brief section on contributing, to README 2016-04-01 12:51:39 +01:00
Michael Bridgen 8c860a832f docs: cosmetic edits to README.md 2016-04-01 12:37:39 +01:00
Stefan Junker 42c4cb842d Merge pull request #168 from steveeJ/chain-len
attempt to ensure chain name is unique and at most 29 chars long
2016-03-31 19:25:13 +02:00
Stefan Junker 897766d74b pkg/utils: correct the test's expected chain names 2016-03-31 18:01:32 +02:00
Stefan Junker 6aad63055c *: add comment to iptables rules for ipmasq 2016-03-31 18:01:32 +02:00
Stefan Junker bcef17daac pkg/utils: remove unneeded condition in tests 2016-03-31 18:01:32 +02:00
Stefan Junker 77759626a8 pkg/utils: fix docstring 2016-03-31 18:01:32 +02:00
Stefan Junker 53d9cee00a pkg/utils: split and unexport constants 2016-03-31 18:01:32 +02:00
Stefan Junker bc44d1227d pkg/utils: fix docstring 2016-03-31 18:01:32 +02:00
Stefan Junker 3e6069cab5 pkg/utils: use constant for chain prefix 2016-03-31 18:01:32 +02:00
Stefan Junker 09248dfad9 pkg/utils: use name+id for hash and extend tests 2016-03-31 18:01:32 +02:00
Abhishek Chanda c33daf6706 pkg: add a function to generate chain names
Adds a function to generate chain names for use in iptables and
ports all drivers to use that function. Also adds tests for the
said function.
2016-03-31 18:01:32 +02:00
Zach Gershman bacaa11d2d Merge pull request #171 from steveeJ/bump-cni
vendoring: bump coreos/go-iptables to 0.1.0
2016-03-31 08:46:55 -07:00
Stefan Junker 88d974c562 vendoring: bump coreos/go-iptables to 0.1.0 2016-03-31 17:33:50 +02:00
Michael Bridgen 5362e90c8a Merge pull request #170 from jonboulle/master
README: add Calico and Weave as CNI users
2016-03-31 14:51:30 +01:00
Jonathan Boulle 77a5bf44f4 README: add Calico and Weave as CNI users 2016-03-31 15:44:03 +02:00
Stefan Junker 1e0e105b36 Merge pull request #169 from philips/add-users
README: add a list of CNI users
2016-03-31 10:21:13 +02:00
Brandon Philips 0b4f7d849f README: add a list of CNI users 2016-03-30 15:59:16 -07:00
Zach Gershman 4146443942 Merge pull request #165 from dcbw/go15-vendor
scripts: fix build with go-1.5 after switch to vendor/
2016-03-24 10:44:00 -07:00
Dan Williams ae2f64ec40 scripts: fix build with go-1.5 after switch to vendor/
go-1.6 enables vendor by default, but go-1.5 needs an environment variable.
2016-03-24 11:33:19 -05:00
Zach Gershman 5c79f8bd5d Merge pull request #158 from steveeJ/loadargs
Add generic IgnoreUnknown to valid CNI_ARGS
2016-03-22 22:05:57 -07:00
Stefan Junker 8916a7ea5f pkg/types: add tests for args 2016-03-21 20:40:39 +01:00
Stefan Junker b91aec9a62 Godeps: bump ginkgo for table extensions 2016-03-21 20:36:05 +01:00
Stefan Junker 5a39a168f7 pkg/types: add IgnoreUnknown arg and logic
This commit adds a struct type CommonArgs that is to be embedded in
every plugin's argument struct. It contains a field named
"IgnoreUnknown" which will be parsed as a boolean and can be provided to
ignore unknown arguments passed to the plugin.
2016-03-21 20:36:05 +01:00
Stefan Junker 05c5aea77b plugins/host-local: only call LoadArgs() once 2016-03-21 20:17:47 +01:00
Stefan Junker 122abae03a Merge pull request #162 from zachgersh/remove-workspace
build script: remove the _workspace from GOPATH
2016-03-21 17:48:25 +01:00
zachgersh 8817b1b946 build script: remove the _workspace from GOPATH
Now that we no longer use godeps to manage
dependencies we can safely remove this.
Dependencies in the vendor directory will
automagically be picked up.
2016-03-21 09:32:09 -07:00
Zach Gershman 6ef5ef1ec1 Merge pull request #161 from steveeJ/skel-tests
pkg/skel: add rudimentary unit tests
2016-03-19 18:09:07 -07:00
Stefan Junker a6c5d80661 pkg/skel: add rudimentary unit tests
This is an attempt to testing the PluginMain() function of the skel pkg.
We should be able to do better by using a mockable interface for the
plugins, but this is a start.
2016-03-18 22:34:29 +01:00
Stefan Junker e72674949e Merge pull request #156 from zachgersh/vendor
Moves to go team vendoring solution
2016-03-17 10:02:30 +01:00
Zach Gershman a3038a5bec Merge pull request #157 from achanda/vet
Fix govet warnings
2016-03-16 17:01:57 -07:00
Zachary Gershman 72eddd1cf1 Let go tip fail, add vendor flag for 1.5 2016-03-16 17:00:51 -07:00
Abhishek Chanda 9b2f3380c1 Fix govet warnings 2016-03-16 16:25:41 -07:00
Zachary Gershman 48ff0e472a Moves to official vendoring solution 2016-03-16 08:38:20 -07:00
Zach Gershman d19044896e Merge pull request #154 from rosenhouse/withnetns-errors
WithNetNS restores original namespace when callback errors
2016-03-15 08:39:01 -07:00
Gabe Rosenhouse 2251ee1d0c Update docstring on WithNetNS 2016-03-15 08:37:00 -07:00
Gabe Rosenhouse 9356e23554 WithNetNS restores original namespace when callback errors
- adds test coverage of WithNetNS in BDD-style
2016-03-15 01:51:58 -07:00
Zach Gershman 2b6448f487 Merge pull request #146 from achanda/trusty
Use Ubuntu Trusty in travis
2016-03-14 17:42:03 -07:00
Zach Gershman 78337dcc42 Merge pull request #153 from steveeJ/maintainer-add-zach
MAINTAINERS: welcome Zach!
2016-03-14 15:52:21 -07:00
Stefan Junker 2511a57cb4 MAINTAINERS: welcome Zach!
We are pleased to welcome Zach on board as CNI maintainer.
Happy collaboration!
2016-03-14 22:56:25 +01:00
Stefan Junker d497d6069a Merge pull request #148 from steveeJ/coverage-batches
travis & README: add coveralls coverage report
2016-03-09 17:30:41 +01:00
Stefan Junker c1ee5d00df travis & README: add coveralls coverage report
Also, don't use sudo for the entire test script
2016-03-05 19:07:31 +01:00
Stefan Junker cde7088cbe Merge pull request #144 from squaremo/rename-delegate-execs
Add invoke.Delegate{Add,Del} for use by meta-plugins
2016-03-04 13:20:35 +01:00
Michael Bridgen 719a1db54b Add invoke.Delegate{Add,Del} for use by meta-plugins
The 'flannel' meta plugin delegates to other plugins to do the actual
OS-level work. It used the ipam.Exec{Add,Del} procedures for this
delegation, since those do precisely what's needed.

However this is a bit misleading, since the flannel plugin _isn't_
doing this for IPAM, and the ipam.Exec* procedures aren't doing
something specific to IPAM plugins.

So: anticipating that there may be more meta plugins that want to
delegate in the same way, this commit moves generic delegation
procedures to `pkg/invoke`, and makes the `pkg/ipam` procedures (still
used, accurately, in the non-meta plugins) shims.
2016-03-04 11:01:22 +00:00
Stefan Junker 36c6bcd106 Merge pull request #142 from steveeJ/fix-loopback-result
Fix loopback result
2016-03-03 09:03:51 +01:00
Abhishek Chanda 230a555359 Use Ubuntu Trusty in travis
This boots faster
2016-03-02 20:00:11 -08:00
Stefan Junker 2b278529e5 Merge pull request #143 from zachgersh/more-tests
More tests
2016-03-02 19:01:13 +01:00
Stefan Junker 4a5426b77a tests: loopback DEL 2016-03-02 17:56:44 +01:00
zachgersh f48bd43d8c Adds travis badge, now we have more tests 2016-03-02 11:43:27 -05:00
zachgersh f3f999c20a Make sure invoke tests are running 2016-03-02 11:38:33 -05:00
Stefan Junker 80ab40470c tests: loopback stdout must be JSON 2016-03-02 15:27:05 +01:00
Stefan Junker 52be8aa615 plugins/loopback: take lo down on CmdDel 2016-03-02 15:27:05 +01:00
Stefan Junker e282f6939d plugins/loopback: return empty result
This is needed to conform to the specification and allow successful
unmarshalling in the invoker.
2016-03-02 15:27:00 +01:00
Stefan Junker c44bc010ab Merge pull request #120 from zachgersh/find-better-error
Better error messages when plugin is not found
2016-03-02 11:14:50 +01:00
Stefan Junker 68259e3388 Merge pull request #121 from zachgersh/loopback-plugin
Loopback plugin
2016-03-02 09:32:01 +01:00
zachgersh 1e3d680d13 Handle namespaces with care
- After creating new netns, switch back to main netns
- Lock thread during test and test setup
2016-02-29 12:29:06 -05:00
Zachary Gershman 2708bdf2f5 Create a plugin for up'ing a lo device
- Believe we need sudo to create netns
- Use syscall instead of relying on ip netns
- Add sudo to .travis.yml
- Needs more -E
- Revert Godeps GoVersion to 1.4.2
- in travis, test command is run with all necessary env vars
- Loopback plugin only works on 'lo' interface
- Update README, add loopback plugin config
- note script dependency on jq

Signed-off-by: Gabe Rosenhouse <grosenhouse@pivotal.io>
2016-02-29 12:29:06 -05:00
Zachary Gershman ebd5be8475 Adds ginkgo / gomega as a dependency 2016-02-29 12:27:11 -05:00
Stefan Junker 67f6672414 Merge pull request #135 from achanda/travis
Tweak the travis file
2016-02-25 23:00:00 +01:00
Abhishek Chanda c5f7cc8501 Tweak the travis file
- Build against more versions of Go
- Explicitely specify go versions
2016-02-24 22:32:08 -08:00
Stefan Junker b7ff8ab158 Merge pull request #132 from steveeJ/scripts
scripts: add DEBUG option
2016-02-24 18:28:47 +01:00
Stefan Junker 1461909bcd Merge pull request #117 from kinvolk/alban/net-tuning
new plugin: tuning
2016-02-24 18:12:18 +01:00
Stefan Junker 06ea8c1e1f scripts: add DEBUG option 2016-02-23 19:22:48 +01:00
Stefan Junker 224ac412da Merge pull request #107 from aanm/pretty-result
added the String method to Result type
2016-02-19 18:46:55 +01:00
André Martins 7b53bb9455 added the String method to Result type
Signed-off-by: André Martins <aanm90@gmail.com>
2016-02-19 17:40:46 +00:00
Alban Crequy f49145d5ff new plugin: tuning
Allow users to tune net network parameters such as somaxconn.

With this patch, users can add a new network configuration:

> {
>   "name": "mytuning",
>   "type": "tuning",
>   "sysctl": {
>           "net.core.somaxconn": "500"
>   }
> }

The value /proc/sys/net/core/somaxconn will be set to 500 in the network
namespace but will remain unchanged on the host.

Only sysctl parameters that belong to the network subsystem can be
modified.

Related to: https://github.com/coreos/rkt/pull/2140
2016-02-18 15:29:12 +01:00
Stefan Junker 48849bd3e3 Merge pull request #108 from aanm/fix-ip-json-tag
fixed ipam host-local IP json tag
2016-02-18 14:12:20 +01:00
Zachary Gershman 290717d6fe Better error message when plugin cannot be found 2016-02-10 13:42:10 -08:00
Stefan Junker 2d9695e976 Merge pull request #119 from jonboulle/master
MAINTAINERS: remove Eugene from list
2016-02-10 15:54:58 +01:00
Jonathan Boulle 2ac72cbb12 MAINTAINERS: remove Eugene from list
Eugene is no longer with CoreOS or actively involved with CNI, so remove
him from the current list of maintainers. He'll be gladly welcomed back
if he decides to rejoin the project.
2016-02-10 15:51:11 +01:00
André Martins 33b2de44af fixed ipam host-local IP json tag
Signed-off-by: André Martins <aanm90@gmail.com>
2016-01-31 03:14:53 +00:00
Stefan Junker f04661aca1 Merge pull request #105 from steveeJ/scripts
script/priv-net-run: improve shebang compatibility
2016-01-29 11:20:55 +01:00
Stefan Junker d5c56b8d42 script/priv-net-run: improve shebang compatibility 2016-01-29 11:17:55 +01:00
Stefan Junker b589f29108 Merge pull request #103 from steveeJ/dns
*: DNS information as dictionary, adding domain, search domains and options
2016-01-29 11:16:50 +01:00
Stefan Junker 137dc8a673 *: reflect SPEC's DNS changes in implementation
* DNS is now a type which will result in a JSON dictionary in
  configurations and results
* Minor refactoring, making use of type embedding
2016-01-29 10:39:28 +01:00
Stefan Junker abb6ee1dd1 docs/ptp: update example and DNS description 2016-01-29 10:39:28 +01:00
Stefan Junker 092e8f5c4d SPEC: DNS information as dictionary, adding domain, search domains, options 2016-01-29 10:39:22 +01:00
Jonathan Boulle 09214926ea Merge pull request #104 from dcbw/revendor-go-iptables
Revendor go-iptables to get --wait behavior
2016-01-27 21:18:44 +01:00
Dan Williams 6017d5c8b9 Revendor go-iptables to get --wait behavior 2016-01-27 13:56:53 -06:00
Stefan Junker a4f8407150 Merge pull request #102 from steveeJ/scripts
scripts/exec-plugins: print plugin results if DEBUG>0
2016-01-27 11:14:57 +01:00
Stefan Junker 67e6f68343 scripts/priv-net-run: print plugin results if DEBUG>0 2016-01-27 10:58:01 +01:00
Stefan Junker 59f8bb361a Merge pull request #101 from steveeJ/shebangs
scripts: improve shebang compatibility
2016-01-27 10:51:32 +01:00
Stefan Junker 28d18d3e73 scripts: improve shebang compatibility 2016-01-27 10:31:16 +01:00
Stefan Junker 1da421150c Merge pull request #99 from kinvolk/alban/dns-config
*: add "dns" field to the configuration
2016-01-27 08:49:16 +01:00
Alban Crequy 2f9ef4adb7 *: add "dns" field to the configuration
appc/cni#76 added a "dns" field in the result JSON. But before this
patch, the plugins had no way of knowing which name server to return.

There could be two ways of knowing which name server to return:
1. add it as an extra argument ("CNI_ARGS")
2. add it in the network configuration as a convenience (received via
   stdin)

I chose the second way because it is easier. In the case of rkt, it
means the user could just add the DNS name servers in
/etc/rkt/net.d/mynetwork.conf.
2016-01-26 18:54:56 +01:00
Jonathan Boulle 03d4ba4ffb Merge pull request #98 from apcera/remove-addif
spec: Removed reference to unsupported addIf attribute
2016-01-22 20:33:22 +01:00
Ken Robertson 65060a0e14 spec: Removed reference to unsupported addIf attribute
Removes the "addIf" attribute from the example of a bridge network
definition. This doesn't appear to exist in the implementation.
2016-01-22 10:45:05 -08:00
Jonathan Boulle 6fc3874d57 Merge pull request #92 from ChengTiesheng/patch-1
Update README.md
2016-01-06 18:08:25 +01:00
Tiesheng 54286af90f Update README.md
Highlight bash/shell code in markdown for readability.

Signed-off-by: chengtiesheng <chengtiesheng@huawei.com>
2016-01-06 16:25:02 +08:00
Stefan Junker 4fcf18cb88 Merge pull request #91 from tomdee/patch-1
Fix docker example in README.md
2016-01-05 09:05:09 +01:00
Tom Denham 0a289316d6 Update README.md
No need for full path to ifconfig (and the given path doesn't work...)
2016-01-04 17:06:30 -08:00
Jonathan Boulle 80f87ceb14 Merge pull request #90 from dgonyeo/master
pkg/ip: fix typo in error message, s/iptabes/iptables/
2015-12-16 22:46:05 +01:00
Derek Gonyeo fd64ee6ade pkg/ip: fix typo in error message, s/iptabes/iptables/ 2015-12-16 13:20:19 -08:00
Eugene Yakubovich 11e121cdd5 Merge pull request #80 from eyakubovich/add-version
spec: add cniVersion to results and config
2015-12-09 13:59:47 -08:00
Eugene Yakubovich 420a145719 spec: add cniVersion to results and config
Version all artifacts using semantic versioning
so that plugins and container runtimes coded against
different versions of the spec can interoperate.

Fixes #44
2015-12-02 13:06:20 -08:00
Stefan Junker f777ca50e5 Merge pull request #78 from steveeJ/improve-errormsg-missing-subnet
host-local: detect missing subnet and error out
2015-11-30 20:56:25 +01:00
Stefan Junker 753b10503c host-local: detect missing subnet and error out 2015-11-25 21:18:48 +01:00
Eugene Yakubovich 19c18abdb1 Merge pull request #82 from steveeJ/dhcp-linkfix
dhcp: detect if link is down and attempt to set up
2015-11-20 12:18:18 -08:00
Stefan Junker 6f23757868 dhcp: detect if link is down and attempt to set up
With this we still get the "network is down" error, but after the 2nd
retry the interface is up and the dhcp request works.
2015-11-19 11:11:32 +01:00
Eugene Yakubovich c3388070c3 Merge pull request #76 from eyakubovich/dns
spec: add "dns" field to the result JSON
2015-11-10 16:59:31 -08:00
Eugene Yakubovich 8aeb066a58 spec: add "dns" field to the result JSON
This adds an ability for networks to communicate
about the DNS nameservers they know about to the
container runtime.

Fixes #67
2015-11-10 16:58:01 -08:00
Eugene Yakubovich 442852a861 Merge pull request #73 from eyakubovich/flannel-fix
flannel: doc fix and check for missing subnet.env fields
2015-10-07 18:03:54 -07:00
Eugene Yakubovich 20f1b8694f flannel: doc fix and check for missing subnet.env fields
- Document that flannel outputs FLANNEL_NETWORK b/c we use it
- Check and error out if expecited fields are missing in subnetEnv file

Fixes #72
2015-10-07 15:38:12 -07:00
Michael Bridgen e727d10746 Merge pull request #71 from jonboulle/master
README/CONTRIBUTING: mention cni-dev@ list
2015-10-05 12:10:56 +01:00
Jonathan Boulle d3ca177ee4 README/CONTRIBUTING: mention cni-dev@ list 2015-10-01 12:43:43 -07:00
Eugene Yakubovich f885288a2d Merge pull request #69 from eyakubovich/err-msgs
Route del would fail due to wrong scope; better errors
2015-09-30 11:56:56 -07:00
Eugene Yakubovich b2b2597506 Merge pull request #70 from eyakubovich/copyright
Change copyright from CoreOS to CNI authors
2015-09-30 11:03:46 -07:00
Eugene Yakubovich 0becca2e96 Change copyright from CoreOS to CNI authors
CNI is developed by more than just CoreOS, Inc
and the copyright is retained by all CNI
contributors (for their respective contributed code).
2015-09-29 11:51:33 -07:00
Eugene Yakubovich 5efd3ba883 Route del would fail due to wrong scope; better errors
In some cases the route deletion would fail due to wrong
scope. It should be NOWHERE when deleting (per iproute2).
This also adds more verbose error messages.
2015-09-29 11:27:49 -07:00
Stefan Junker f0266a2717 Merge pull request #65 from steveeJ/fix-veth-setup
Fix veth setup

Fixes #61 #64
2015-09-24 21:53:54 +02:00
Stefan Junker 5b7aa09e52 link: switch to host netns to set up host veth end 2015-09-24 18:49:27 +02:00
Stefan Junker f1c9c632e1 Revert "plugins/ptp: allow host veth to be UP"
This reverts commit 231d2d5a27.
2015-09-24 18:32:18 +02:00
Stefan Junker 39ea97f99d Merge pull request #63 from steveeJ/no-host-local-ptp
Merge host-local and host-local-ptp
2015-09-24 13:10:47 +02:00
Stefan Junker 231d2d5a27 plugins/ptp: allow host veth to be UP 2015-09-24 10:57:36 +02:00
Stefan Junker 6737bc8207 update ptp docs to reflect changes in plugin 2015-09-24 09:43:55 +02:00
Eugene Yakubovich 60be55a7d1 remove host-local-ptp plugin 2015-09-23 11:04:38 +02:00
Eugene Yakubovich 7d8d6b2a7e Use single IP on the host for ptp veths
Instead of allocating a /31 for each container,
use the same IP on the host side for all veths.
This is very similar how real point-to-point
devices work (using donor IPs).
2015-09-23 11:04:38 +02:00
Eugene Yakubovich 94be1cfaab revendoring netlink 2015-09-23 11:04:38 +02:00
Michael Bridgen 2a58bd9379 Merge pull request #60 from eyakubovich/fix-plugin-del
bug fix: exec of DEL cmd caused JSON decode error
2015-09-22 16:39:59 +01:00
Eugene Yakubovich 9ea56937d4 bug fix: exec of DEL cmd caused JSON decode error
When plugin is executed with a DEL command, it does not
print result to stdout unless there is an error. Therefore
it stdout bytes should not be passed to json.Unmarshal.
2015-09-18 10:30:10 -07:00
Michael Bridgen cc918a1aea Merge pull request #59 from squaremo/factor-out-libcni
Factor an API out into a module
2015-09-17 00:06:54 +01:00
Michael Bridgen b88f173c43 Factor an API out into a module
This takes some of the machinery from CNI and from the rkt networking
code, and turns it into a library that can be linked into go apps.

Included is an example command-line application that uses the library,
called `cnitool`.

Other headline changes:

 * Plugin exec'ing is factored out

The motivation here is to factor out the protocol for invoking
plugins. To that end, a generalisation of the code from api.go and
pkg/plugin/ipam.go goes into pkg/invoke/exec.go.

 * Move argument-handling and conf-loading into public API

The fact that the arguments get turned into an environment for the
plugin is incidental to the API; so, provide a way of supplying them
as a struct or saying "just use the same arguments as I got" (the
latter is for IPAM plugins).
2015-09-16 10:14:39 +01:00
Stefan Junker 5da5738456 Merge pull request #58 from steveeJ/remove-ipmasq-ifneedbe
ipvlan/macvlan: remove ipMasq related code
2015-09-10 22:08:57 +02:00
Stefan Junker d896b82816 ipvlan/macvlan: remove ipMasq related code
Luckily the docs haven't mentioned support for ipMasq for both plugins so far.
Even if anyone has attempted to enable the feature in their configuration files it didn't have the desired effect for the network.
2015-09-09 14:16:39 +02:00
Stefan Junker 75657b0aac Merge pull request #57 from eyakubovich/maintainers
Add MAINTAINERS file
2015-09-09 12:05:35 +02:00
Eugene Yakubovich c4808e616d Add MAINTAINERS file 2015-09-08 15:58:00 -07:00
Jonathan Boulle 06967ea734 Merge pull request #53 from NeilW/master
IPAM plugin: improve error messages
2015-09-08 14:26:11 -07:00
Neil Wilson 2d0d4b35e1 plugin/ipam: correct formatting of error message 2015-09-08 18:08:15 +00:00
Neil Wilson 8462a3f607 IPAM plugin: improve error messages
Make it more clear that we failed to find an IPAM plugin.
Check for a missing plugin name and issue a more helpful error.
2015-09-08 18:08:15 +00:00
Jonathan Boulle fb9b8ad1bc Merge pull request #55 from jonboulle/travis
*: add basic test script + travis hook
2015-09-07 16:28:35 -07:00
Jonathan Boulle d10d1a148e *: add basic test script + travis hook
Adds a simple test script, mostly to perform gofmt and govet checking;
currently tests only exist for the DHCP plugin.
2015-09-07 16:21:53 -07:00
Stefan Junker 69d50f545d Merge pull request #54 from jonboulle/master
plugin/ipam: fix typo in error message
2015-09-08 00:49:28 +02:00
Jonathan Boulle 7478744cf5 plugin/ipam: fix typo in error message 2015-09-07 15:43:34 -07:00
Stefan Junker ef820646c5 Merge pull request #51 from steveeJ/plugins-args
CNI_ARGS: use ';' to split args as documented
2015-09-05 19:00:53 +02:00
Stefan Junker 8b634b90da CNI_ARGS: use ';' to split args as documented 2015-09-05 18:58:58 +02:00
Stefan Junker fbd828cf60 Merge pull request #42 from steveeJ/plugins-args
host-local: allow ip request via CNI_ARGS
2015-09-04 01:42:11 +02:00
Stefan Junker 1d398af124 host-local: allow ip request via CNI_ARGS
A specific IP can now be requested via the environment variable CNI_ARGS, e.g.
`CNI_ARGS=ip=1.2.3.4`.
The plugin will try to reserve the specified IP.
If this is not successful the execution will fail.
2015-09-04 01:38:22 +02:00
Eugene Yakubovich 59f58fb974 Merge pull request #49 from eyakubovich/dco
Add DCO and CONTRIBUTING.md
2015-09-02 11:01:42 -07:00
Eugene Yakubovich d1ccecf88f Add DCO and CONTRIBUTING.md 2015-09-02 11:00:27 -07:00
Jonathan Boulle 4f6ab3c2ad Merge pull request #43 from alexwlchan/master
Fix a few spelling mistakes in the docs
2015-08-20 09:17:56 -07:00
Alex Chan ac0b5177a4 Fix a few spelling mistakes in the docs 2015-08-20 16:41:25 +01:00
Eugene Yakubovich 34be862dc3 Merge pull request #41 from eyakubovich/flannel-route
flannel: set up route for the entire flannel network
2015-08-15 16:28:09 -07:00
Eugene Yakubovich e38572b967 flannel: set up route for the entire flannel network
Without it, packets leave via default route iface
and come back via interface added by flannel plugin.
If rp_filter=1, the packets are dropped.
2015-08-10 14:13:06 -07:00
Jonathan Boulle 4be9a4f771 Merge pull request #37 from steveeJ/fix-docs
host-local: fix routes in README examples
2015-08-03 15:12:07 -07:00
Stefan Junker d961f6cd39 host-local: fix routes in README examples 2015-08-03 15:37:14 +02:00
351 changed files with 15496 additions and 85498 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Don't rewrite line endings
*.go -text

View File

@ -0,0 +1,7 @@
FROM alpine:3.20
RUN apk add --no-cache curl jq
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@ -0,0 +1,11 @@
name: 'Re-Test'
description: 'Re-Runs the last workflow for a PR'
inputs:
token:
description: 'GitHub API Token'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
env:
GITHUB_TOKEN: ${{ inputs.token }}

45
.github/actions/retest-action/entrypoint.sh vendored Executable file
View File

@ -0,0 +1,45 @@
#!/bin/sh
set -ex
if ! jq -e '.issue.pull_request' ${GITHUB_EVENT_PATH}; then
echo "Not a PR... Exiting."
exit 0
fi
if [ "$(jq -r '.comment.body' ${GITHUB_EVENT_PATH})" != "/retest" ]; then
echo "Nothing to do... Exiting."
exit 0
fi
PR_URL=$(jq -r '.issue.pull_request.url' ${GITHUB_EVENT_PATH})
curl --request GET \
--url "${PR_URL}" \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header "content-type: application/json" > pr.json
ACTOR=$(jq -r '.user.login' pr.json)
BRANCH=$(jq -r '.head.ref' pr.json)
curl --request GET \
--url "https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs?event=pull_request&actor=${ACTOR}&branch=${BRANCH}" \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header "content-type: application/json" | jq '.workflow_runs | max_by(.run_number)' > run.json
RERUN_URL=$(jq -r '.rerun_url' run.json)
curl --request POST \
--url "${RERUN_URL}" \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header "content-type: application/json"
REACTION_URL="$(jq -r '.comment.url' ${GITHUB_EVENT_PATH})/reactions"
curl --request POST \
--url "${REACTION_URL}" \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header "accept: application/vnd.github.squirrel-girl-preview+json" \
--header "content-type: application/json" \
--data '{ "content" : "rocket" }'

27
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,27 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "docker"
directory: "/.github/actions/retest-action"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
groups:
golang:
patterns:
- "*"
- package-ecosystem: "gomod"
directory: "/plugins/debug"
schedule:
interval: "weekly"

17
.github/workflows/commands.yml vendored Normal file
View File

@ -0,0 +1,17 @@
name: commands
on:
issue_comment:
types: [created]
jobs:
retest:
if: github.repository == 'containernetworking/cni'
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Re-Test Action
uses: ./.github/actions/retest-action
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}

40
.github/workflows/scorecard.yml vendored Normal file
View File

@ -0,0 +1,40 @@
name: Scorecard supply-chain security
on:
branch_protection_rule:
push:
branches:
- main
schedule:
- cron: 29 15 * * 0
permissions: read-all
jobs:
analysis:
name: Scorecard analysis
permissions:
id-token: write
security-events: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
persist-credentials: false
- name: Run analysis
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
with:
results_file: results.sarif
results_format: sarif
publish_results: true
- name: Upload artifact
uses: actions/upload-artifact@97a0fba1372883ab732affbe8f94b823f91727db # v3.pre.node20
with:
name: SARIF file
path: results.sarif
retention-days: 5
- name: Upload to code-scanning
uses: github/codeql-action/upload-sarif@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7
with:
sarif_file: results.sarif

96
.github/workflows/test.yaml vendored Normal file
View File

@ -0,0 +1,96 @@
---
name: test
on: ["push", "pull_request"]
env:
GO_VERSION: "1.22"
LINUX_ARCHES: "amd64 386 arm arm64 s390x mips64le ppc64le"
jobs:
lint:
name: Lint
permissions:
contents: read
pull-requests: read
runs-on: ubuntu-latest
steps:
- name: setup go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: ibiqlik/action-yamllint@2576378a8e339169678f9939646ee3ee325e845c # v3.1.1
with:
format: auto
config_file: .yamllint.yaml
- uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
with:
args: --verbose
version: v1.57.1
build:
name: Build all linux architectures
needs: lint
runs-on: ubuntu-latest
steps:
- name: setup go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Build on all supported architectures
run: |
set -e
for arch in ${LINUX_ARCHES}; do
echo "Building for arch $arch"
GOARCH=$arch go build ./...
done
test-linux:
name: Run tests on Linux amd64
needs: build
runs-on: ubuntu-latest
steps:
- name: setup go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Install test binaries
run: |
go install github.com/mattn/goveralls@v0.0.12
go install github.com/modocache/gover@latest
- name: test
run: COVERALLS=1 ./test.sh
- env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Send coverage to coveralls
run: |
PATH=$PATH:$(go env GOPATH)/bin
gover
goveralls -coverprofile=gover.coverprofile -service=github
test-win:
name: Build and run tests on Windows
needs: build
runs-on: windows-latest
steps:
- name: setup go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: test
run: bash ./test.sh

6
.gitignore vendored
View File

@ -1,3 +1,5 @@
bin/ .idea/
gopath/
*.sw[ponm] *.sw[ponm]
.vagrant
release-*
cnitool/cnitool

30
.golangci.yml Normal file
View File

@ -0,0 +1,30 @@
linters:
enable:
- contextcheck
- errcheck
- errorlint
- gci
- ginkgolinter
- gocritic
- gofumpt
- govet
- ineffassign
- misspell
- nolintlint
- nonamedreturns
- predeclared
- staticcheck
- typecheck
- unconvert
- unused
- whitespace
linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/containernetworking)
run:
timeout: 5m

10
.yamllint.yaml Normal file
View File

@ -0,0 +1,10 @@
---
extends: default
rules:
document-start: disable
line-length: disable
truthy:
ignore: |
.github/workflows/*.yml
.github/workflows/*.yaml

3
CODE-OF-CONDUCT.md Normal file
View File

@ -0,0 +1,3 @@
# Community Code of Conduct
CNI follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md).

128
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,128 @@
# How to Contribute
CNI is [Apache 2.0 licensed](LICENSE) and accepts contributions via GitHub
pull requests. This document outlines some of the conventions on development
workflow, commit message formatting, contact points and other resources to make
it easier to get your contribution accepted.
We gratefully welcome improvements to documentation as well as to code.
## Certificate of Origin
By contributing to this project you agree to the Developer Certificate of
Origin (DCO). This document was created by the Linux Kernel community and is a
simple statement that you, as a contributor, have the legal right to make the
contribution. See the [DCO](DCO) file for details.
## Email and Chat
The project uses the cni-dev email list, IRC chat, and Slack:
- Email: [cni-dev](https://groups.google.com/forum/#!forum/cni-dev)
- IRC: #[containernetworking](irc://irc.freenode.net:6667/#containernetworking) channel on [freenode.net](https://freenode.net/)
- Slack: #cni on the [CNCF slack](https://slack.cncf.io/). NOTE: the previous CNI Slack (containernetworking.slack.com) has been sunsetted.
Please avoid emailing maintainers found in the MAINTAINERS file directly. They
are very busy and read the mailing lists.
## Getting Started
- Fork the repository on GitHub
- Read the [README](README.md) for build and test instructions
- Play with the project, submit bugs, submit pull requests!
## Contribution workflow
This is a rough outline of how to prepare a contribution:
- Create a topic branch from where you want to base your work (usually branched from main).
- Make commits of logical units.
- Make sure your commit messages are in the proper format (see below).
- Push your changes to a topic branch in your fork of the repository.
- If you changed code:
- add automated tests to cover your changes, using the [Ginkgo](https://onsi.github.io/ginkgo/) & [Gomega](https://onsi.github.io/gomega/) style
- if the package did not previously have any test coverage, add it to the list
of `TESTABLE` packages in the `test.sh` script.
- run the full test script and ensure it passes
- Make sure any new code files have a license header (this is now enforced by automated tests)
- Submit a pull request to the original repository.
## How to run the test suite
We generally require test coverage of any new features or bug fixes.
Here's how you can run the test suite on any system (even Mac or Windows) using
[Vagrant](https://www.vagrantup.com/) and a hypervisor of your choice:
```bash
vagrant up
vagrant ssh
# you're now in a shell in a virtual machine
sudo su
cd /go/src/github.com/containernetworking/cni
# to run the full test suite
./test.sh
# to focus on a particular test suite
cd libcni
go test
```
## Acceptance policy
These things will make a PR more likely to be accepted:
- a well-described requirement
- tests for new code
- tests for old code!
- new code and tests follow the conventions in old code and tests
- a good commit message (see below)
In general, we will merge a PR once two maintainers have endorsed it.
Trivial changes (e.g., corrections to spelling) may get waved through.
For substantial changes, more people may become involved, and you might get asked to resubmit the PR or divide the changes into more than one PR.
### Format of the Commit Message
We follow a rough convention for commit messages that is designed to answer two
questions: what changed and why. The subject line should feature the what and
the body of the commit should describe the why.
```md
scripts: add the test-cluster command
this uses tmux to setup a test cluster that you can easily kill and
start for debugging.
Fixes #38
```
The format can be described more formally as follows:
```md
<subsystem>: <what changed>
<BLANK LINE>
<why this change was made>
<BLANK LINE>
<footer>
```
The first line is the subject and should be no longer than 70 characters, the
second line is always blank, and other lines should be wrapped at 80 characters.
This allows the message to be easier to read on GitHub as well as in various
git tools.
## 3rd party plugins
So you've built a CNI plugin. Where should it live?
Short answer: We'd be happy to link to it from our [list of 3rd party plugins](README.md#3rd-party-plugins).
But we'd rather you kept the code in your own repo.
Long answer: An advantage of the CNI model is that independent plugins can be
built, distributed and used without any code changes to this repository. While
some widely used plugins (and a few less-popular legacy ones) live in this repo,
we're reluctant to add more.
If you have a good reason why the CNI maintainers should take custody of your
plugin, please open an issue or PR.

120
CONVENTIONS.md Normal file
View File

@ -0,0 +1,120 @@
# Extension conventions
There are three ways of passing information to plugins using the Container Network Interface (CNI), none of which require the [spec](SPEC.md) to be updated. These are
- plugin specific fields in the JSON config
- `args` field in the JSON config
- `CNI_ARGS` environment variable
This document aims to provide guidance on which method should be used and to provide a convention for how common information should be passed.
Establishing these conventions allows plugins to work across multiple runtimes. This helps both plugins and the runtimes.
## Plugins
* Plugin authors should aim to support these conventions where it makes sense for their plugin. This means they are more likely to "just work" with a wider range of runtimes.
* Plugins should accept arguments according to these conventions if they implement the same basic functionality as other plugins. If plugins have shared functionality that isn't covered by these conventions then a PR should be opened against this document.
## Runtimes
* Runtime authors should follow these conventions if they want to pass additional information to plugins. This will allow the extra information to be consumed by the widest range of plugins.
* These conventions serve as an abstraction for the runtime. For example, port forwarding is highly implementation specific, but users should be able to select the plugin of their choice without changing the runtime.
# Current conventions
Additional conventions can be created by creating PRs which modify this document.
## Dynamic Plugin specific fields (Capabilities / Runtime Configuration)
[Plugin specific fields](SPEC.md#network-configuration) formed part of the original CNI spec and have been present since the initial release.
> Plugins may define additional fields that they accept and may generate an error if called with unknown fields. The exception to this is the args field may be used to pass arbitrary data which may be ignored by plugins.
A plugin can define any additional fields it needs to work properly. It should return an error if it can't act on fields that were expected or where the field values were malformed.
This method of passing information to a plugin is recommended when the following conditions hold:
* The configuration has specific meaning to the plugin (i.e. it's not just general meta data)
* the plugin is expected to act on the configuration or return an error if it can't
Dynamic information (i.e. data that a runtime fills out) should be placed in a `runtimeConfig` section. Plugins can request
that the runtime insert this dynamic configuration by explicitly listing their `capabilities` in the network configuration.
For example, the configuration for a port mapping plugin might look like this to an operator (it should be included as part of a [network configuration list](SPEC.md#network-configuration-lists).
```json
{
"name" : "ExamplePlugin",
"type" : "port-mapper",
"capabilities": {"portMappings": true}
}
```
But the runtime would fill in the mappings so the plugin itself would receive something like this.
```json
{
"name" : "ExamplePlugin",
"type" : "port-mapper",
"runtimeConfig": {
"portMappings": [
{"hostPort": 8080, "containerPort": 80, "protocol": "tcp"}
]
}
}
```
### Well-known Capabilities
| Area | Purpose | Capability | Spec and Example | Runtime implementations | Plugin Implementations |
| ----- | ------- | -----------| ---------------- | ----------------------- | --------------------- |
| port mappings | Pass mapping from ports on the host to ports in the container network namespace. | `portMappings` | A list of portmapping entries.<br/> <pre>[<br/> { "hostPort": 8080, "containerPort": 80, "protocol": "tcp" },<br /> { "hostPort": 8000, "containerPort": 8001, "protocol": "udp" }<br /> ]<br /></pre> | kubernetes | CNI `portmap` plugin |
| ip ranges | Dynamically configure the IP range(s) for address allocation. Runtimes that manage IP pools, but not individual IP addresses, can pass these to plugins. | `ipRanges` | The same as the `ranges` key for `host-local` - a list of lists of subnets. The outer list is the number of IPs to allocate, and the inner list is a pool of subnets for each allocation. <br/><pre>[<br/> [<br/> { "subnet": "10.1.2.0/24", "rangeStart": "10.1.2.3", "rangeEnd": 10.1.2.99", "gateway": "10.1.2.254" } <br/> ]<br/>]</pre> | none | CNI `host-local` plugin |
| bandwidth limits | Dynamically configure interface bandwidth limits | `bandwidth` | Desired bandwidth limits. Rates are in bits per second, burst values are in bits. <pre> { "ingressRate": 2048, "ingressBurst": 1600, "egressRate": 4096, "egressBurst": 1600 } </pre> | none | CNI `bandwidth` plugin |
| dns | Dynamically configure dns according to runtime | `dns` | Dictionary containing a list of `servers` (string entries), a list of `searches` (string entries), a list of `options` (string entries). <pre>{ <br> "searches" : [ "internal.yoyodyne.net", "corp.tyrell.net" ] <br> "servers": [ "8.8.8.8", "10.0.0.10" ] <br />} </pre> | kubernetes | CNI `win-bridge` plugin, CNI `win-overlay` plugin |
| ips | Dynamically allocate IPs for container interface. Runtime which has the ability of address allocation can pass these to plugins. | `ips` | A list of `IP` (\<ip\>\[/\<prefix\>\]). <pre> [ "192.168.0.1", 10.10.0.1/24", "3ffe:ffff:0:01ff::2", "3ffe:ffff:0:01ff::1/64" ] </pre> The plugin may require the IP address to include a prefix length. | none | CNI `static` plugin, CNI `host-local` plugin |
| mac | Dynamically assign MAC. Runtime can pass this to plugins which need MAC as input. | `mac` | `MAC` (string entry). <pre> "c2:11:22:33:44:55" </pre> | none | CNI `tuning` plugin |
| infiniband guid | Dynamically assign Infiniband GUID to network interface. Runtime can pass this to plugins which need Infiniband GUID as input. | `infinibandGUID` | `GUID` (string entry). <pre> "c2:11:22:33:44:55:66:77" </pre> | none | CNI [`ib-sriov-cni`](https://github.com/Mellanox/ib-sriov-cni) plugin |
| device id | Provide device identifier which is associated with the network to allow the CNI plugin to perform device dependent network configurations. | `deviceID` | `deviceID` (string entry). <pre> "0000:04:00.5" </pre> | none | CNI `host-device` plugin |
| aliases | Provide a list of names that will be mapped to the IP addresses assigned to this interface. Other containers on the same network may use one of these names to access the container.| `aliases` | List of `alias` (string entry). <pre> ["my-container", "primary-db"] </pre> | none | CNI `alias` plugin |
| cgroup path | Provide the cgroup path for pod as requested by CNI plugins. | `cgroupPath` | `cgroupPath` (string entry). <pre>"/kubelet.slice/kubelet-kubepods.slice/kubelet-kubepods-burstable.slice/kubelet-kubepods-burstable-pod28ce45bc_63f8_48a3_a99b_cfb9e63c856c.slice" </pre> | none | CNI `host-local` plugin |
## "args" in network config
`args` in [network config](SPEC.md#network-configuration) were reserved as a field in the `0.2.0` release of the CNI spec.
> args (dictionary): Optional additional arguments provided by the container runtime. For example a dictionary of labels could be passed to CNI plugins by adding them to a labels field under args.
`args` provide a way of providing more structured data than the flat strings that CNI_ARGS can support.
`args` should be used for _optional_ meta-data. Runtimes can place additional data in `args` and plugins that don't understand that data should just ignore it. Runtimes should not require that a plugin understands or consumes that data provided, and so a runtime should not expect to receive an error if the data could not be acted on.
This method of passing information to a plugin is recommended when the information is optional and the plugin can choose to ignore it. It's often that case that such information is passed to all plugins by the runtime without regard for whether the plugin can understand it.
The conventions documented here are all namespaced under `cni` so they don't conflict with any existing `args`.
For example:
```jsonc
{
"cniVersion":"0.2.0",
"name":"net",
"args":{
"cni":{
"labels": [{"key": "app", "value": "myapp"}]
}
},
// <REST OF CNI CONFIG HERE>
"ipam":{
// <IPAM CONFIG HERE>
}
}
```
| Area | Purpose| Spec and Example | Runtime implementations | Plugin Implementations |
| ----- | ------ | ------------ | ----------------------- | ---------------------- |
| labels | Pass`key=value` labels to plugins | <pre>"labels" : [<br /> { "key" : "app", "value" : "myapp" },<br /> { "key" : "env", "value" : "prod" }<br />] </pre> | none | none |
| ips | Request specific IPs | Spec:<pre>"ips": ["\<ip\>[/\<prefix\>]", ...]</pre>Examples:<pre>"ips": ["10.2.2.42/24", "2001:db8::5"]</pre> The plugin may require the IP address to include a prefix length. | none | host-local, static |
## CNI_ARGS
CNI_ARGS formed part of the original CNI spec and have been present since the initial release.
> `CNI_ARGS`: Extra arguments passed in by the user at invocation time. Alphanumeric key-value pairs separated by semicolons; for example, "FOO=BAR;ABC=123"
The use of `CNI_ARGS` is deprecated and "args" should be used instead. If a runtime passes an equivalent key via `args` (eg the `ips` `args` Area and the `CNI_ARGS` `IP` Field) and the plugin understands `args`, the plugin must ignore the CNI_ARGS Field.
| Field | Purpose| Spec and Example | Runtime implementations | Plugin Implementations |
| ------ | ------ | ---------------- | ----------------------- | ---------------------- |
| IP | Request a specific IP from IPAM plugins | Spec:<pre>IP=\<ip\>[/\<prefix\>]</pre>Example: <pre>IP=192.168.10.4/24</pre> The plugin may require the IP addresses to include a prefix length. | *rkt* supports passing additional arguments to plugins and the [documentation](https://coreos.com/rkt/docs/latest/networking/overriding-defaults.html) suggests IP can be used. | host-local, static |
## Chained Plugins
If plugins are agnostic about the type of interface created, they SHOULD work in a chained mode and configure existing interfaces. Plugins MAY also create the desired interface when not run in a chain.
For example, the `bridge` plugin adds the host-side interface to a bridge. So, it should accept any previous result that includes a host-side interface, including `tap` devices. If not called as a chained plugin, it creates a `veth` pair first.
Plugins that meet this convention are usable by a larger set of runtimes and interfaces, including hypervisors and DPDK providers.

36
DCO Normal file
View File

@ -0,0 +1,36 @@
Developer Certificate of Origin
Version 1.1
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
660 York Street, Suite 102,
San Francisco, CA 94110 USA
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

View File

@ -1,37 +0,0 @@
# bridge plugin
## Overview
With bridge plugin, all containers (on the same host) are plugged into a bridge (virtual switch) that resides in the host network namespace.
The containers receive one end of the veth pair with the other end connected to the bridge.
An IP address is only assigned to one end of the veth pair -- one residing in the container.
The bridge itself can also be assigned an IP address, turning it into a gateway for the containers.
Alternatively, the bridge can function purely in L2 mode and would need to be bridged to the host network interface (if other than container-to-container communication on the same host is desired).
The network configuration specifies the name of the bridge to be used.
If the bridge is missing, the plugin will create one on first use and, if gateway mode is used, assign it an IP that was returned by IPAM plugin via the gateway field.
## Example configuration
```
{
"name": "mynet",
"type": "bridge",
"bridge": "mynet0",
"isGateway": true,
"ipMasq": true,
"ipam": {
"type": "host-local",
"subnet": "10.10.0.0/16"
}
}
```
## Network configuration reference
* `name` (string, required): the name of the network.
* `type` (string, required): "bridge".
* `bridge` (string, optional): name of the bridge to use/create. Defaults to "cni0".
* `isGateway` (boolean, optional): assign an IP address to the bridge. Defaults to false.
* `ipMasq` (boolean, optional): set up IP Masquerade on the host for traffic originating from this network and destined outside of it. Defaults to false.
* `mtu` (integer, optional): explicitly set MTU to the specified value. Defaults to the value chosen by the kernel.
* `ipam` (dictionary, required): IPAM configuration to be used for this network.

19
Documentation/cnitool.md Normal file
View File

@ -0,0 +1,19 @@
# Overview
The `cnitool` is a utility that can be used to test a CNI plugin
without the need for a container runtime. The `cnitool` takes a
`network name` and a `network namespace` and a command to `ADD` or
`DEL`,.i.e, attach or detach containers from a network. The `cnitool`
relies on the following environment variables to operate properly:
* `NETCONFPATH`: This environment variable needs to be set to a
directory. It defaults to `/etc/cni/net.d`. The `cnitool` searches
for CNI configuration files in this directory with the extension
`*.conf` or `*.json`. It loads all the CNI configuration files in
this directory and if it finds a CNI configuration with the `network
name` given to the cnitool it returns the corresponding CNI
configuration, else it returns `nil`.
* `CNI_PATH`: For a given CNI configuration `cnitool` will search for
the corresponding CNI plugin in this path.
For the full documentation of `cnitool` see the [cnitool docs](../cnitool/README.md)

View File

@ -1,35 +0,0 @@
# dhcp plugin
## Overview
With dhcp plugin the containers can get an IP allocated by a DHCP server already running on your network.
This can be especially useful with plugin types such as [macvlan](https://github.com/appc/cni/blob/master/Documentation/macvlan.md).
Because a DHCP lease must be periodically renewed for the duration of container lifetime, a separate daemon is required to be running.
The same plugin binary can also be run in the daemon mode.
## Operation
To use the dhcp IPAM plugin, first launch the dhcp daemon:
```
# Make sure the unix socket has been removed
$ rm -f /run/cni/dhcp.sock
$ ./dhcp daemon
```
Alternatively, you can use systemd socket activation protocol.
Be sure that the .socket file uses /run/cni/dhcp.sock as the socket path.
With the daemon running, containers using the dhcp plugin can be launched.
## Example configuration
```
{
"ipam": {
"type": "dhcp",
}
}
## Network configuration reference
* `type` (string, required): "dhcp"

View File

@ -1,86 +0,0 @@
# flannel plugin
## Overview
This plugin is designed to work in conjunction with [flannel](https://github.com/coreos/flannel), a network fabric for containers.
When flannel daemon is started, it outputs a `/run/flannel/subnet.env` file that looks like this:
```
FLANNEL_SUBNET=10.1.17.0/24
FLANNEL_MTU=1472
FLANNEL_IPMASQ=true
```
This information reflects the attributes of flannel network on the host.
The flannel CNI plugin uses this information to configure another CNI plugin, such as bridge plugin.
## Operation
Given the following network configuration file and the contents of `/run/flannel/subnet.env` above,
```
{
"name": "mynet",
"type": "flannel"
}
```
the flannel plugin will generate another network configuration file:
```
{
"name": "mynet",
"type": "bridge",
"mtu": 1472,
"ipMasq": false,
"isGateway": true,
"ipam": {
"type": "host-local",
"subnet": "10.1.17.0/24"
}
}
```
It will then invoke the bridge plugin, passing it the generated configuration.
As can be seen from above, the flannel plugin, by default, will delegate to the bridge plugin.
If additional configuration values need to be passed to the bridge plugin, it can be done so via the `delegate` field:
```
{
"name": "mynet",
"type": "flannel",
"delegate": {
"bridge": "mynet0",
"mtu": 1400
}
}
```
This supplies a configuration parameter to the bridge plugin -- the created bridge will now be named `mynet0`.
Notice that `mtu` has also been specified and this value will not be overwritten by flannel plugin.
Additionally, the `delegate` field can be used to select a different kind of plugin altogether.
To use `ipvlan` instead of `bridge`, the following configuratoin can be specified:
```
{
"name": "mynet",
"type": "flannel",
"delegate": {
"type": "ipvlan",
"master": "eth0"
}
}
```
## Network configuration reference
* `name` (string, required): the name of the network
* `type` (string, required): "flannel"
* `subnetFile` (string, optional): full path to the subnet file written out by flanneld. Defaults to /run/flannel/subnet.env
* `delegate` (dictionary, optional): specifies configuration options for the delegated plugin.
flannel plugin will always set the following fields in the delegated plugin configuration:
* `name`: value of its "name" field.
* `ipam`: "host-local" type will be used with "subnet" set to `$FLANNEL_SUBNET`.
flannel plugin will set the following fields in the delegated plugin configuration if they are not present:
* `ipMasq`: the inverse of `$FLANNEL_IPMASQ`
* `mtu`: `$FLANNEL_MTU`
Additionally, for the bridge plugin, `isGateway` will be set to `true`, if not present.

View File

@ -1,36 +0,0 @@
# host-local plugin
## Overview
host-local IPAM plugin allocates IPv4 addresses out of a specified address range.
It stores the state locally on the host filesystem, therefore ensuring uniqueness of IP addresses on a single host.
## Example configuration
```
{
"ipam": {
"type": "host-local",
"subnet": "10.10.0.0/16",
"rangeStart": "10.10.1.20",
"rangeEnd": "10.10.3.50",
"gateway": "10.10.0.254",
"routes": [
{ "dst": "0.0.0.0/0" },
{ "dst": "192.168.0.0/16", "gw": "10.10.5.1" }
]
}
}
```
## Network configuration reference
* `type` (string, required): "host-local".
* `subnet` (string, required): CIDR block to allocate out of.
* `rangeStart` (string, optional): IP inside of "subnet" from which to start allocating addresses. Defaults to ".2" IP inside of the "subnet" block.
* `rangeEnd` (string, optional): IP inside of "subnet" with which to end allocating addresses. Defaults to ".254" IP inside of the "subnet" block.
* `gateway` (string, optional): IP inside of "subnet" to designate as the gateway. Defaults to ".1" IP inside of the "subnet" block.
* `routes` (string, optional): list of routes to add to the container namespace. Each route is a dictionary with "dst" and optional "gw" fields. If "gw" is omitted, value of "gateway" will be used.
## Files
Allocated IP addresses are stored as files in /var/lib/cni/networks/$NETWORK_NAME.

View File

@ -1,40 +0,0 @@
# ipvlan plugin
## Overview
ipvlan is a new [addition](https://lwn.net/Articles/620087/) to the Linux kernel.
Like its cousin macvlan, it virtualizes the host interface.
However unlike macvlan which generates a new MAC address for each interface, ipvlan devices all share the same MAC.
The kernel driver inspects the IP address of each packet when making a decision about which virtual interface should process the packet.
Because all ipvlan interfaces share the MAC address with the host interface, DHCP can only be used in conjunction with ClientID (currently not supported by DHCP plugin).
## Example configuration
```
{
"name": "mynet",
"type": "ipvlan",
"master": "eth0",
"ipam": {
"type": "host-local",
"subnet": "10.1.2.0/24",
}
}
```
## Network configuration reference
* `name` (string, required): the name of the network.
* `type` (string, required): "ipvlan".
* `master` (string, required): name of the host interface to enslave.
* `mode` (string, optional): one of "l2", "l3". Defaults to "l2".
* `mtu` (integer, optional): explicitly set MTU to the specified value. Defaults to the value chosen by the kernel.
* `ipam` (dictionary, required): IPAM configuration to be used for this network.
## Notes
* `ipvlan` does not allow virtual interfaces to communicate with the master interface.
Therefore the container will not be able to reach the host via `ipvlan` interface.
Be sure to also have container join a network that provides connectivity to the host (e.g. `ptp`).
* A single master interface can not be enslaved by both `macvlan` and `ipvlan`.

View File

@ -1,34 +0,0 @@
# macvlan plugin
## Overview
[macvlan](http://backreference.org/2014/03/20/some-notes-on-macvlanmacvtap/) functions like a switch that is already connected to the host interface.
A host interface gets "enslaved" with the virtual interfaces sharing the physical device but having distinct MAC addresses.
Since each macvlan interface has its own MAC address, it makes it easy to use with exising DHCP servers already present on the network.
## Example configuration
```
{
"name": "mynet",
"type": "macvlan",
"master": "eth0",
"ipam": {
"type": "dhcp"
}
}
```
## Network configuration reference
* `name` (string, required): the name of the network
* `type` (string, required): "macvlan"
* `master` (string, required): name of the host interface to enslave
* `mode` (string, optional): one of "bridge", "private", "vepa", "passthrough". Defaults to "bridge".
* `mtu` (integer, optional): explicitly set MTU to the specified value. Defaults to the value chosen by the kernel.
* `ipam` (dictionary, required): IPAM configuration to be used for this network.
## Notes
* If are testing on a laptop, please remember that most wireless cards do not support being enslaved by macvlan.
* A single master interface can not be enslaved by both `macvlan` and `ipvlan`.

View File

@ -1,28 +0,0 @@
# ptp plugin
## Overview
The ptp plugin creates a point-to-point link between a container and the host by using a veth device.
One end of the veth pair is placed inside a container and the other end resides on the host.
Both ends receive an IP address out of a /31 range.
The IP of the host end becomes the gateway address inside the container.
Because ptp plugin requires a pair of IP addresses for each container, it should be used in conjuction with host-local-ptp IPAM plugin.
## Example network configuration
```
{
"name": "mynet",
"type": "ptp",
"ipam": {
"type": "host-local-ptp",
"subnet": "10.1.1.0/24"
}
}
## Network configuration reference
* `name` (string, required): the name of the network
* `type` (string, required): "ptp"
* `ipMasq` (boolean, optional): set up IP Masquerade on the host for traffic originating from this network and destined outside of it. Defaults to false.
* `mtu` (integer, optional): explicitly set MTU to the specified value. Defaults to value chosen by the kernel.
* `ipam` (dictionary, required): IPAM configuration to be used for this network.

View File

@ -0,0 +1,294 @@
# How to Upgrade to CNI Specification v1.0
CNI v1.0 has the following changes:
- non-List configurations are removed
- the `version` field in the `interfaces` array was redundant and is removed
## libcni Changes in CNI v1.0
**`/pkg/types/current` no longer exists**
This means that runtimes need to explicitly select a version they support.
This reduces code breakage when revendoring cni into other projects and
returns the decision on which CNI Spec versions a plugin supports to the
plugin's authors.
For example, your Go imports might look like
```go
import (
cniv1 "github.com/containernetworking/cni/pkg/types/100"
)
```
# Changes in CNI v0.4
CNI v0.4 has the following important changes:
- A new verb, "CHECK", was added. Runtimes can now ask plugins to verify the status of a container's attachment
- A new configuration flag, `disableCheck`, which indicates to the runtime that configuration should not be CHECK'ed
No changes were made to the result type.
# How to upgrade to CNI Specification v0.3.0 and later
The 0.3.0 specification contained a small error. The Result structure's `ip` field should have been renamed to `ips` to be consistent with the IPAM result structure definition; this rename was missed when updating the Result to accommodate multiple IP addresses and interfaces. All first-party CNI plugins (bridge, host-local, etc) were updated to use `ips` (and thus be inconsistent with the 0.3.0 specification) and most other plugins have not been updated to the 0.3.0 specification yet, so few (if any) users should be impacted by this change.
The 0.3.1 specification corrects the `Result` structure to use the `ips` field name as originally intended. This is the only change between 0.3.0 and 0.3.1.
Version 0.3.0 of the [CNI Specification](https://github.com/containernetworking/cni/blob/spec-v0.3.0/SPEC.md) provides rich information
about container network configuration, including details of network interfaces
and support for multiple IP addresses.
To support this new data, the specification changed in a couple significant
ways that will impact CNI users, plugin authors, and runtime authors.
This document provides guidance for how to upgrade:
- [For CNI Users](#for-cni-users)
- [For Plugin Authors](#for-plugin-authors)
- [For Runtime Authors](#for-runtime-authors)
**Note**: the CNI Spec is versioned independently from the GitHub releases
for this repo. For example, Release v0.4.0 supports Spec version v0.2.0,
and Release v0.5.0 supports Spec v0.3.0.
----
## For CNI Users
If you maintain CNI configuration files for a container runtime that uses CNI,
ensure that the configuration files specify a `cniVersion` field and that the
version there is supported by your container runtime and CNI plugins.
Configuration files without a version field should be given version 0.2.0.
The CNI spec includes example configuration files for
[single plugins](SPEC.md#example-configurations)
and for [lists of chained plugins](SPEC.md#example-configurations).
Consult the documentation for your runtime and plugins to determine what
CNI spec versions they support. Test any plugin upgrades before deploying to
production. You may find [cnitool](https://github.com/containernetworking/cni/tree/main/cnitool)
useful. Specifically, your configuration version should be the lowest common
version supported by your plugins.
## For Plugin Authors
This section provides guidance for upgrading plugins to CNI Spec Version 0.3.0.
### General guidance for all plugins (language agnostic)
To provide the smoothest upgrade path, **existing plugins should support
multiple versions of the CNI spec**. In particular, plugins with existing
installed bases should add support for CNI spec version 1.0.0 while maintaining
compatibility with older versions.
To do this, two changes are required. First, a plugin should advertise which
CNI spec versions it supports. It does this by responding to the `VERSION`
command with the following JSON data:
```json
{
"cniVersion": "1.0.0",
"supportedVersions": [ "0.1.0", "0.2.0", "0.3.0", "0.3.1", "0.4.0", "1.0.0" ]
}
```
Second, for the `ADD` command, a plugin must respect the `cniVersion` field
provided in the [network configuration JSON](SPEC.md#network-configuration).
That field is a request for the plugin to return results of a particular format:
- If the `cniVersion` field is not present, then spec v0.2.0 should be assumed
and v0.2.0 format result JSON returned.
- If the plugin doesn't support the version, the plugin must error.
- Otherwise, the plugin must return a [CNI Result](SPEC.md#result)
in the format requested.
Result formats for older CNI spec versions are available in the
[git history for SPEC.md](https://github.com/containernetworking/cni/commits/main/SPEC.md).
For example, suppose a plugin, via its `VERSION` response, advertises CNI specification
support for v0.2.0 and v0.3.0. When it receives `cniVersion` key of `0.2.0`,
the plugin must return result JSON conforming to CNI spec version 0.2.0.
### Specific guidance for plugins written in Go
Plugins written in Go may leverage the Go language packages in this repository
to ease the process of upgrading and supporting multiple versions. CNI
[Library and Plugins Release v0.5.0](https://github.com/containernetworking/cni/releases/tag/v0.5.0)
includes important changes to the Golang APIs. Plugins using these APIs will
require some changes now, but should more-easily handle spec changes and
new features going forward.
For plugin authors, the biggest change is that `types.Result` is now an
interface implemented by concrete struct types in the `types/100`,
`types/040`, and `types/020` subpackages.
Internally, plugins should use the latest spec version (eg `types/100`) structs,
and convert to or from specific versions when required. A typical plugin will
only need to do a single conversion when it is about to complete and
needs to print the result JSON in the requested `cniVersion` format to stdout.
The library function `types.PrintResult()` simplifies this by converting and
printing in a single call.
Additionally, the plugin should advertise which CNI Spec versions it supports
via the 3rd argument to `skel.PluginMain()`.
Here is some example code
```go
import (
"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/cni/pkg/types"
current "github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/cni/pkg/version"
)
func cmdAdd(args *skel.CmdArgs) error {
// determine spec version to use
var netConf struct {
types.NetConf
// other plugin-specific configuration goes here
}
err := json.Unmarshal(args.StdinData, &netConf)
cniVersion := netConf.CNIVersion
// plugin does its work...
// set up interfaces
// assign addresses, etc
// construct the result
result := &current.Result{
Interfaces: []*current.Interface{ ... },
IPs: []*current.IPs{ ... },
...
}
// print result to stdout, in the format defined by the requested cniVersion
return types.PrintResult(result, cniVersion)
}
func main() {
skel.PluginMain(cmdAdd, cmdDel, version.All)
}
```
Alternately, to use the result from a delegated IPAM plugin, the `result`
value might be formed like this:
```go
ipamResult, err := ipam.ExecAdd(netConf.IPAM.Type, args.StdinData)
result, err := current.NewResultFromResult(ipamResult)
```
Other examples of spec v0.3.0-compatible plugins are the
[main plugins in this repo](https://github.com/containernetworking/plugins/)
## For Runtime Authors
This section provides guidance for upgrading container runtimes to support
CNI Spec Version 0.3.0 and later.
### General guidance for all runtimes (language agnostic)
#### Support multiple CNI spec versions
To provide the smoothest upgrade path and support the broadest range of CNI
plugins, **container runtimes should support multiple versions of the CNI spec**.
In particular, runtimes with existing installed bases should add support for CNI
spec version 0.3.0 and later while maintaining compatibility with older versions.
To support multiple versions of the CNI spec, runtimes should be able to
call both new and legacy plugins, and handle the results from either.
When calling a plugin, the runtime must request that the plugin respond in a
particular format by specifying the `cniVersion` field in the
[Network Configuration](SPEC.md#network-configuration)
JSON block. The plugin will then respond with
a [Result](SPEC.md#result)
in the format defined by that CNI spec version, and the runtime must parse
and handle this result.
#### Handle errors due to version incompatibility
Plugins may respond with error indicating that they don't support the requested
CNI version (see [Well-known Error Codes](SPEC.md#well-known-error-codes)),
e.g.
```json
{
"cniVersion": "0.2.0",
"code": 1,
"msg": "CNI version not supported"
}
```
In that case, the runtime may retry with a lower CNI spec version, or take
some other action.
#### (optional) Discover plugin version support
Runtimes may discover which CNI spec versions are supported by a plugin, by
calling the plugin with the `VERSION` command. The `VERSION` command was
added in CNI spec v0.2.0, so older plugins may not respect it. In the absence
of a successful response to `VERSION`, assume that the plugin only supports
CNI spec v0.1.0.
#### Handle missing data in v0.3.0 and later results
The Result for the `ADD` command in CNI spec version 0.3.0 and later includes
a new field `interfaces`. An IP address in the `ip` field may describe which
interface it is assigned to, by placing a numeric index in the `interface`
subfield.
However, some plugins which are v0.3.0 and later compatible may nonetheless
omit the `interfaces` field and/or set the `interface` index value to `-1`.
Runtimes should gracefully handle this situation, unless they have good reason
to rely on the existence of the interface data. In that case, provide the user
an error message that helps diagnose the issue.
### Specific guidance for container runtimes written in Go
Container runtimes written in Go may leverage the Go language packages in this
repository to ease the process of upgrading and supporting multiple versions.
CNI [Library and Plugins Release v0.5.0](https://github.com/containernetworking/cni/releases)
includes important changes to the Golang APIs. Runtimes using these APIs will
require some changes now, but should more-easily handle spec changes and
new features going forward.
For runtimes, the biggest changes to the Go libraries are in the `types` package.
It has been refactored to make working with versioned results simpler. The top-level
`types.Result` is now an opaque interface instead of a struct, and APIs exposed by
other packages, such as the high-level `libcni` package, have been updated to use
this interface. Concrete types are now per-version subpackages. The `types/current`
subpackage contains the latest (spec v0.3.0) types.
When up-converting older result types to spec v0.3.0 and later, fields new in
spec v0.3.0 and later (like `interfaces`) may be empty. Conversely, when
down-converting v0.3.0 and later results to an older version, any data in
those fields will be lost.
| From | 0.1 | 0.2 | 0.3 | 0.4 | 1.0 |
|--------|-----|-----|-----|-----|-----|
| To 0.1 | ✔ | ✔ | x | x | x |
| To 0.2 | ✔ | ✔ | x | x | x |
| To 0.3 | ✴ | ✴ | ✔ | ✔ | ✔ |
| To 0.4 | ✴ | ✴ | ✔ | ✔ | ✔ |
| To 1.0 | ✴ | ✴ | ✔ | ✔ | ✔ |
Key:
> ✔ : lossless conversion <br>
> ✴ : higher-version output may have empty fields <br>
> x : lower-version output is missing some data <br>
A container runtime should use `current.NewResultFromResult()` to convert the
opaque `types.Result` to a concrete `current.Result` struct. It may then
work with the fields exposed by that struct:
```go
// runtime invokes the plugin to get the opaque types.Result
// this may conform to any CNI spec version
resultInterface, err := libcni.AddNetwork(ctx, netConf, runtimeConf)
// upconvert result to the current 0.3.0 spec
result, err := current.NewResultFromResult(resultInterface)
// use the result fields ....
for _, ip := range result.IPs { ... }
```

44
GOVERNANCE.md Normal file
View File

@ -0,0 +1,44 @@
# CNI Governance
This document defines project governance for the project.
## Voting
The CNI project employs "organization voting" to ensure no single organization can dominate the project.
Individuals not associated with or employed by a company or organization are allowed one organization vote.
Each company or organization (regardless of the number of maintainers associated with or employed by that company/organization) receives one organization vote.
In other words, if two maintainers are employed by Company X, two by Company Y, two by Company Z, and one maintainer is an un-affiliated individual, a total of four "organization votes" are possible; one for X, one for Y, one for Z, and one for the un-affiliated individual.
Any maintainer from an organization may cast the vote for that organization.
For formal votes, a specific statement of what is being voted on should be added to the relevant github issue or PR, and a link to that issue or PR added to the maintainers meeting agenda document.
Maintainers should indicate their yes/no vote on that issue or PR, and after a suitable period of time, the votes will be tallied and the outcome noted.
## Changes in Maintainership
New maintainers are proposed by an existing maintainer and are elected by a 2/3 majority organization vote.
Maintainers can be removed by a 2/3 majority organization vote.
## Approving PRs
Non-specification-related PRs may be merged after receiving at least two organization votes.
Changes to the CNI Specification also follow the normal PR approval process (eg, 2 organization votes), but any maintainer can request that the approval require a 2/3 majority organization vote.
## Github Project Administration
Maintainers will be added to the containernetworking GitHub organization and added to the GitHub cni-maintainers team, and made a GitHub maintainer of that team.
After 6 months a maintainer will be made an "owner" of the GitHub organization.
## Changes in Governance
All changes in Governance require a 2/3 majority organization vote.
## Other Changes
Unless specified above, all other changes to the project require a 2/3 majority organization vote.
Additionally, any maintainer may request that any change require a 2/3 majority organization vote.

34
Godeps/Godeps.json generated
View File

@ -1,34 +0,0 @@
{
"ImportPath": "github.com/appc/cni",
"GoVersion": "go1.4.2",
"Packages": [
"./..."
],
"Deps": [
{
"ImportPath": "github.com/coreos/go-iptables/iptables",
"Rev": "83dfad0f13fd7310fb3c1cb8563248d8d604b95b"
},
{
"ImportPath": "github.com/coreos/go-systemd/activation",
"Comment": "v2-53-g2688e91",
"Rev": "2688e91251d9d8e404e86dd8f096e23b2f086958"
},
{
"ImportPath": "github.com/d2g/dhcp4",
"Rev": "f0e4d29ff0231dce36e250b2ed9ff08412584bca"
},
{
"ImportPath": "github.com/d2g/dhcp4client",
"Rev": "bed07e1bc5b85f69c6f0fd73393aa35ec68ed892"
},
{
"ImportPath": "github.com/vishvananda/netlink",
"Rev": "ae3e7dba57271b4e976c4f91637861ee477135e2"
},
{
"ImportPath": "golang.org/x/sys/unix",
"Rev": "e11762ca30adc5b39fdbfd8c4250dabeb8e456d3"
}
]
}

5
Godeps/Readme generated
View File

@ -1,5 +0,0 @@
This directory tree is generated automatically by godep.
Please do not edit.
See https://github.com/tools/godep for more information.

2
Godeps/_workspace/.gitignore generated vendored
View File

@ -1,2 +0,0 @@
/pkg
/bin

View File

@ -1,255 +0,0 @@
// Copyright 2015 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package iptables
import (
"bytes"
"fmt"
"log"
"os/exec"
"regexp"
"strconv"
"strings"
"syscall"
)
// Adds the output of stderr to exec.ExitError
type Error struct {
exec.ExitError
msg string
}
func (e *Error) ExitStatus() int {
return e.Sys().(syscall.WaitStatus).ExitStatus()
}
func (e *Error) Error() string {
return fmt.Sprintf("exit status %v: %v", e.ExitStatus(), e.msg)
}
type IPTables struct {
path string
}
func New() (*IPTables, error) {
path, err := exec.LookPath("iptables")
if err != nil {
return nil, err
}
return &IPTables{path}, nil
}
// Exists checks if given rulespec in specified table/chain exists
func (ipt *IPTables) Exists(table, chain string, rulespec...string) (bool, error) {
checkPresent, err := getIptablesHasCheckCommand()
if err != nil {
log.Printf("Error checking iptables version, assuming version at least 1.4.11: %v", err)
checkPresent = true
}
if !checkPresent {
cmd := append([]string{"-A", chain}, rulespec...)
return existsForOldIpTables(table, strings.Join(cmd, " "))
} else {
cmd := append([]string{"-t", table, "-C", chain}, rulespec...)
err := ipt.run(cmd...)
switch {
case err == nil:
return true, nil
case err.(*Error).ExitStatus() == 1:
return false, nil
default:
return false, err
}
}
}
// Insert inserts rulespec to specified table/chain (in specified pos)
func (ipt *IPTables) Insert(table, chain string, pos int, rulespec ...string) error {
cmd := append([]string{"-t", table, "-I", chain, strconv.Itoa(pos)}, rulespec...)
return ipt.run(cmd...)
}
// Append appends rulespec to specified table/chain
func (ipt *IPTables) Append(table, chain string, rulespec ...string) error {
cmd := append([]string{"-t", table, "-A", chain}, rulespec...)
return ipt.run(cmd...)
}
// AppendUnique acts like Append except that it won't add a duplicate
func (ipt *IPTables) AppendUnique(table, chain string, rulespec ...string) error {
exists, err := ipt.Exists(table, chain, rulespec...)
if err != nil {
return err
}
if !exists {
return ipt.Append(table, chain, rulespec...)
}
return nil
}
// Delete removes rulespec in specified table/chain
func (ipt *IPTables) Delete(table, chain string, rulespec ...string) error {
cmd := append([]string{"-t", table, "-D", chain}, rulespec...)
return ipt.run(cmd...)
}
// List rules in specified table/chain
func (ipt *IPTables) List(table, chain string) ([]string, error) {
var stdout, stderr bytes.Buffer
cmd := exec.Cmd{
Path: ipt.path,
Args: []string{ipt.path, "-t", table, "-S", chain},
Stdout: &stdout,
Stderr: &stderr,
}
if err := cmd.Run(); err != nil {
return nil, &Error{*(err.(*exec.ExitError)), stderr.String()}
}
rules := strings.Split(stdout.String(), "\n")
if len(rules) > 0 && rules[len(rules)-1] == "" {
rules = rules[:len(rules)-1]
}
return rules, nil
}
func (ipt *IPTables) NewChain(table, chain string) error {
return ipt.run("-t", table, "-N", chain)
}
// ClearChain flushed (deletes all rules) in the specifed table/chain.
// If the chain does not exist, new one will be created
func (ipt *IPTables) ClearChain(table, chain string) error {
err := ipt.NewChain(table, chain)
switch {
case err == nil:
return nil
case err.(*Error).ExitStatus() == 1:
// chain already exists. Flush (clear) it.
return ipt.run("-t", table, "-F", chain)
default:
return err
}
}
// DeleteChain deletes the chain in the specified table.
// The chain must be empty
func (ipt *IPTables) DeleteChain(table, chain string) error {
return ipt.run("-t", table, "-X", chain)
}
func (ipt *IPTables) run(args... string) error {
var stderr bytes.Buffer
cmd := exec.Cmd{
Path: ipt.path,
Args: append([]string{ipt.path}, args...),
Stderr: &stderr,
}
if err := cmd.Run(); err != nil {
return &Error{*(err.(*exec.ExitError)), stderr.String()}
}
return nil
}
// Checks if iptables has the "-C" flag
func getIptablesHasCheckCommand() (bool, error) {
vstring, err := getIptablesVersionString()
if err != nil {
return false, err
}
v1, v2, v3, err := extractIptablesVersion(vstring)
if err != nil {
return false, err
}
return iptablesHasCheckCommand(v1, v2, v3), nil
}
// getIptablesVersion returns the first three components of the iptables version.
// e.g. "iptables v1.3.66" would return (1, 3, 66, nil)
func extractIptablesVersion(str string) (int, int, int, error) {
versionMatcher := regexp.MustCompile("v([0-9]+)\\.([0-9]+)\\.([0-9]+)")
result := versionMatcher.FindStringSubmatch(str)
if result == nil {
return 0, 0, 0, fmt.Errorf("no iptables version found in string: %s", str)
}
v1, err := strconv.Atoi(result[1])
if err != nil {
return 0, 0, 0, err
}
v2, err := strconv.Atoi(result[2])
if err != nil {
return 0, 0, 0, err
}
v3, err := strconv.Atoi(result[3])
if err != nil {
return 0, 0, 0, err
}
return v1, v2, v3, nil
}
// Runs "iptables --version" to get the version string
func getIptablesVersionString() (string, error) {
cmd := exec.Command("iptables", "--version")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
return "", err
}
return out.String(), nil
}
// Checks if an iptables version is after 1.4.11, when --check was added
func iptablesHasCheckCommand(v1 int, v2 int, v3 int) bool {
if v1 > 1 {
return true
}
if v1 == 1 && v2 > 4 {
return true
}
if v1 == 1 && v2 == 4 && v3 >= 11 {
return true
}
return false
}
// Checks if a rule specification exists for a table
func existsForOldIpTables(table string, ruleSpec string) (bool, error) {
cmd := exec.Command("iptables", "-t", table, "-S")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
return false, err
}
rules := out.String()
return strings.Contains(rules, ruleSpec), nil
}

View File

@ -1,136 +0,0 @@
// Copyright 2015 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package iptables
import (
"crypto/rand"
"math/big"
"reflect"
"testing"
)
func randChain(t *testing.T) string {
n, err := rand.Int(rand.Reader, big.NewInt(1000000))
if err != nil {
t.Fatalf("Failed to generate random chain name: %v", err)
}
return "TEST-" + n.String()
}
func TestChain(t *testing.T) {
chain := randChain(t)
ipt, err := New()
if err != nil {
t.Fatalf("New failed: %v", err)
}
// chain shouldn't exist, this will create new
err = ipt.ClearChain("filter", chain)
if err != nil {
t.Fatalf("ClearChain (of missing) failed: %v", err)
}
// chain now exists
err = ipt.ClearChain("filter", chain)
if err != nil {
t.Fatalf("ClearChain (of empty) failed: %v", err)
}
// put a simple rule in
err = ipt.Append("filter", chain, "-s", "0.0.0.0/0", "-j", "ACCEPT")
if err != nil {
t.Fatalf("Append failed: %v", err)
}
// can't delete non-empty chain
err = ipt.DeleteChain("filter", chain)
if err == nil {
t.Fatalf("DeleteChain of non-empty chain did not fail")
}
err = ipt.ClearChain("filter", chain)
if err != nil {
t.Fatalf("ClearChain (of non-empty) failed: %v", err)
}
// chain empty, should be ok
err = ipt.DeleteChain("filter", chain)
if err != nil {
t.Fatalf("DeleteChain of empty chain failed: %v", err)
}
}
func TestRules(t *testing.T) {
chain := randChain(t)
ipt, err := New()
if err != nil {
t.Fatalf("New failed: %v", err)
}
// chain shouldn't exist, this will create new
err = ipt.ClearChain("filter", chain)
if err != nil {
t.Fatalf("ClearChain (of missing) failed: %v", err)
}
err = ipt.Append("filter", chain, "-s", "10.1.0.0/16", "-d", "8.8.8.8/32", "-j", "ACCEPT")
if err != nil {
t.Fatalf("Append failed: %v", err)
}
err = ipt.AppendUnique("filter", chain, "-s", "10.1.0.0/16", "-d", "8.8.8.8/32", "-j", "ACCEPT")
if err != nil {
t.Fatalf("AppendUnique failed: %v", err)
}
err = ipt.Append("filter", chain, "-s", "10.2.0.0/16", "-d", "8.8.8.8/32", "-j", "ACCEPT")
if err != nil {
t.Fatalf("Append failed: %v", err)
}
err = ipt.Insert("filter", chain, 2, "-s", "10.2.0.0/16", "-d", "9.9.9.9/32", "-j", "ACCEPT")
if err != nil {
t.Fatalf("Insert failed: %v", err)
}
err = ipt.Insert("filter", chain, 1, "-s", "10.1.0.0/16", "-d", "9.9.9.9/32", "-j", "ACCEPT")
if err != nil {
t.Fatalf("Insert failed: %v", err)
}
err = ipt.Delete("filter", chain, "-s", "10.1.0.0/16", "-d", "9.9.9.9/32", "-j", "ACCEPT")
if err != nil {
t.Fatalf("Insert failed: %v", err)
}
rules, err := ipt.List("filter", chain)
if err != nil {
t.Fatalf("List failed: %v", err)
}
expected := []string{
"-N " + chain,
"-A " + chain + " -s 10.1.0.0/16 -d 8.8.8.8/32 -j ACCEPT",
"-A " + chain + " -s 10.2.0.0/16 -d 9.9.9.9/32 -j ACCEPT",
"-A " + chain + " -s 10.2.0.0/16 -d 8.8.8.8/32 -j ACCEPT",
}
if !reflect.DeepEqual(rules, expected) {
t.Fatalf("List mismatch: \ngot %#v \nneed %#v", rules, expected)
}
}

View File

@ -1,52 +0,0 @@
// Copyright 2015 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package activation implements primitives for systemd socket activation.
package activation
import (
"os"
"strconv"
"syscall"
)
// based on: https://gist.github.com/alberts/4640792
const (
listenFdsStart = 3
)
func Files(unsetEnv bool) []*os.File {
if unsetEnv {
defer os.Unsetenv("LISTEN_PID")
defer os.Unsetenv("LISTEN_FDS")
}
pid, err := strconv.Atoi(os.Getenv("LISTEN_PID"))
if err != nil || pid != os.Getpid() {
return nil
}
nfds, err := strconv.Atoi(os.Getenv("LISTEN_FDS"))
if err != nil || nfds == 0 {
return nil
}
files := make([]*os.File, 0, nfds)
for fd := listenFdsStart; fd < listenFdsStart+nfds; fd++ {
syscall.CloseOnExec(fd)
files = append(files, os.NewFile(uintptr(fd), "LISTEN_FD_"+strconv.Itoa(fd)))
}
return files
}

View File

@ -1,82 +0,0 @@
// Copyright 2015 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package activation
import (
"bytes"
"io"
"os"
"os/exec"
"testing"
)
// correctStringWritten fails the text if the correct string wasn't written
// to the other side of the pipe.
func correctStringWritten(t *testing.T, r *os.File, expected string) bool {
bytes := make([]byte, len(expected))
io.ReadAtLeast(r, bytes, len(expected))
if string(bytes) != expected {
t.Fatalf("Unexpected string %s", string(bytes))
}
return true
}
// TestActivation forks out a copy of activation.go example and reads back two
// strings from the pipes that are passed in.
func TestActivation(t *testing.T) {
cmd := exec.Command("go", "run", "../examples/activation/activation.go")
r1, w1, _ := os.Pipe()
r2, w2, _ := os.Pipe()
cmd.ExtraFiles = []*os.File{
w1,
w2,
}
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "LISTEN_FDS=2", "FIX_LISTEN_PID=1")
err := cmd.Run()
if err != nil {
t.Fatalf(err.Error())
}
correctStringWritten(t, r1, "Hello world")
correctStringWritten(t, r2, "Goodbye world")
}
func TestActivationNoFix(t *testing.T) {
cmd := exec.Command("go", "run", "../examples/activation/activation.go")
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "LISTEN_FDS=2")
out, _ := cmd.CombinedOutput()
if bytes.Contains(out, []byte("No files")) == false {
t.Fatalf("Child didn't error out as expected")
}
}
func TestActivationNoFiles(t *testing.T) {
cmd := exec.Command("go", "run", "../examples/activation/activation.go")
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "LISTEN_FDS=0", "FIX_LISTEN_PID=1")
out, _ := cmd.CombinedOutput()
if bytes.Contains(out, []byte("No files")) == false {
t.Fatalf("Child didn't error out as expected")
}
}

View File

@ -1,37 +0,0 @@
// Copyright 2015 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package activation
import (
"net"
)
// Listeners returns a slice containing a net.Listener for each matching socket type
// passed to this process.
//
// The order of the file descriptors is preserved in the returned slice.
// Nil values are used to fill any gaps. For example if systemd were to return file descriptors
// corresponding with "udp, tcp, tcp", then the slice would contain {nil, net.Listener, net.Listener}
func Listeners(unsetEnv bool) ([]net.Listener, error) {
files := Files(unsetEnv)
listeners := make([]net.Listener, len(files))
for i, f := range files {
if pc, err := net.FileListener(f); err == nil {
listeners[i] = pc
}
}
return listeners, nil
}

View File

@ -1,86 +0,0 @@
// Copyright 2015 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package activation
import (
"io"
"net"
"os"
"os/exec"
"testing"
)
// correctStringWritten fails the text if the correct string wasn't written
// to the other side of the pipe.
func correctStringWrittenNet(t *testing.T, r net.Conn, expected string) bool {
bytes := make([]byte, len(expected))
io.ReadAtLeast(r, bytes, len(expected))
if string(bytes) != expected {
t.Fatalf("Unexpected string %s", string(bytes))
}
return true
}
// TestActivation forks out a copy of activation.go example and reads back two
// strings from the pipes that are passed in.
func TestListeners(t *testing.T) {
cmd := exec.Command("go", "run", "../examples/activation/listen.go")
l1, err := net.Listen("tcp", ":9999")
if err != nil {
t.Fatalf(err.Error())
}
l2, err := net.Listen("tcp", ":1234")
if err != nil {
t.Fatalf(err.Error())
}
t1 := l1.(*net.TCPListener)
t2 := l2.(*net.TCPListener)
f1, _ := t1.File()
f2, _ := t2.File()
cmd.ExtraFiles = []*os.File{
f1,
f2,
}
r1, err := net.Dial("tcp", "127.0.0.1:9999")
if err != nil {
t.Fatalf(err.Error())
}
r1.Write([]byte("Hi"))
r2, err := net.Dial("tcp", "127.0.0.1:1234")
if err != nil {
t.Fatalf(err.Error())
}
r2.Write([]byte("Hi"))
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "LISTEN_FDS=2", "FIX_LISTEN_PID=1")
out, err := cmd.Output()
if err != nil {
println(string(out))
t.Fatalf(err.Error())
}
correctStringWrittenNet(t, r1, "Hello world")
correctStringWrittenNet(t, r2, "Goodbye world")
}

View File

@ -1,37 +0,0 @@
// Copyright 2015 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package activation
import (
"net"
)
// PacketConns returns a slice containing a net.PacketConn for each matching socket type
// passed to this process.
//
// The order of the file descriptors is preserved in the returned slice.
// Nil values are used to fill any gaps. For example if systemd were to return file descriptors
// corresponding with "udp, tcp, udp", then the slice would contain {net.PacketConn, nil, net.PacketConn}
func PacketConns(unsetEnv bool) ([]net.PacketConn, error) {
files := Files(unsetEnv)
conns := make([]net.PacketConn, len(files))
for i, f := range files {
if pc, err := net.FilePacketConn(f); err == nil {
conns[i] = pc
}
}
return conns, nil
}

View File

@ -1,68 +0,0 @@
// Copyright 2015 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package activation
import (
"net"
"os"
"os/exec"
"testing"
)
// TestActivation forks out a copy of activation.go example and reads back two
// strings from the pipes that are passed in.
func TestPacketConns(t *testing.T) {
cmd := exec.Command("go", "run", "../examples/activation/udpconn.go")
u1, err := net.ListenUDP("udp", &net.UDPAddr{Port: 9999})
if err != nil {
t.Fatalf(err.Error())
}
u2, err := net.ListenUDP("udp", &net.UDPAddr{Port: 1234})
if err != nil {
t.Fatalf(err.Error())
}
f1, _ := u1.File()
f2, _ := u2.File()
cmd.ExtraFiles = []*os.File{
f1,
f2,
}
r1, err := net.Dial("udp", "127.0.0.1:9999")
if err != nil {
t.Fatalf(err.Error())
}
r1.Write([]byte("Hi"))
r2, err := net.Dial("udp", "127.0.0.1:1234")
if err != nil {
t.Fatalf(err.Error())
}
r2.Write([]byte("Hi"))
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "LISTEN_FDS=2", "FIX_LISTEN_PID=1")
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("Cmd output '%s', err: '%s'\n", out, err)
}
correctStringWrittenNet(t, r1, "Hello world")
correctStringWrittenNet(t, r2, "Goodbye world")
}

View File

@ -1,27 +0,0 @@
Copyright (c) 2013 Skagerrak Software Limited. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Skagerrak Software Limited nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,5 +0,0 @@
# DHCP4 - A DHCP library written in Go.
Warning: This library is still being developed. Function calls will change.
I've removed Server Functionality, for me this project supports the underlying DHCP format not the implementation.

View File

@ -1,121 +0,0 @@
package dhcp4
// OpCodes
const (
BootRequest OpCode = 1 // From Client
BootReply OpCode = 2 // From Server
)
// DHCP Message Type 53
const (
Discover MessageType = 1 // Broadcast Packet From Client - Can I have an IP?
Offer MessageType = 2 // Broadcast From Server - Here's an IP
Request MessageType = 3 // Broadcast From Client - I'll take that IP (Also start for renewals)
Decline MessageType = 4 // Broadcast From Client - Sorry I can't use that IP
ACK MessageType = 5 // From Server, Yes you can have that IP
NAK MessageType = 6 // From Server, No you cannot have that IP
Release MessageType = 7 // From Client, I don't need that IP anymore
Inform MessageType = 8 // From Client, I have this IP and there's nothing you can do about it
)
// DHCP Options
const (
End OptionCode = 255
Pad OptionCode = 0
OptionSubnetMask OptionCode = 1
OptionTimeOffset OptionCode = 2
OptionRouter OptionCode = 3
OptionTimeServer OptionCode = 4
OptionNameServer OptionCode = 5
OptionDomainNameServer OptionCode = 6
OptionLogServer OptionCode = 7
OptionCookieServer OptionCode = 8
OptionLPRServer OptionCode = 9
OptionImpressServer OptionCode = 10
OptionResourceLocationServer OptionCode = 11
OptionHostName OptionCode = 12
OptionBootFileSize OptionCode = 13
OptionMeritDumpFile OptionCode = 14
OptionDomainName OptionCode = 15
OptionSwapServer OptionCode = 16
OptionRootPath OptionCode = 17
OptionExtensionsPath OptionCode = 18
// IP Layer Parameters per Host
OptionIPForwardingEnableDisable OptionCode = 19
OptionNonLocalSourceRoutingEnableDisable OptionCode = 20
OptionPolicyFilter OptionCode = 21
OptionMaximumDatagramReassemblySize OptionCode = 22
OptionDefaultIPTimeToLive OptionCode = 23
OptionPathMTUAgingTimeout OptionCode = 24
OptionPathMTUPlateauTable OptionCode = 25
// IP Layer Parameters per Interface
OptionInterfaceMTU OptionCode = 26
OptionAllSubnetsAreLocal OptionCode = 27
OptionBroadcastAddress OptionCode = 28
OptionPerformMaskDiscovery OptionCode = 29
OptionMaskSupplier OptionCode = 30
OptionPerformRouterDiscovery OptionCode = 31
OptionRouterSolicitationAddress OptionCode = 32
OptionStaticRoute OptionCode = 33
// Link Layer Parameters per Interface
OptionTrailerEncapsulation OptionCode = 34
OptionARPCacheTimeout OptionCode = 35
OptionEthernetEncapsulation OptionCode = 36
// TCP Parameters
OptionTCPDefaultTTL OptionCode = 37
OptionTCPKeepaliveInterval OptionCode = 38
OptionTCPKeepaliveGarbage OptionCode = 39
// Application and Service Parameters
OptionNetworkInformationServiceDomain OptionCode = 40
OptionNetworkInformationServers OptionCode = 41
OptionNetworkTimeProtocolServers OptionCode = 42
OptionVendorSpecificInformation OptionCode = 43
OptionNetBIOSOverTCPIPNameServer OptionCode = 44
OptionNetBIOSOverTCPIPDatagramDistributionServer OptionCode = 45
OptionNetBIOSOverTCPIPNodeType OptionCode = 46
OptionNetBIOSOverTCPIPScope OptionCode = 47
OptionXWindowSystemFontServer OptionCode = 48
OptionXWindowSystemDisplayManager OptionCode = 49
OptionNetworkInformationServicePlusDomain OptionCode = 64
OptionNetworkInformationServicePlusServers OptionCode = 65
OptionMobileIPHomeAgent OptionCode = 68
OptionSimpleMailTransportProtocol OptionCode = 69
OptionPostOfficeProtocolServer OptionCode = 70
OptionNetworkNewsTransportProtocol OptionCode = 71
OptionDefaultWorldWideWebServer OptionCode = 72
OptionDefaultFingerServer OptionCode = 73
OptionDefaultInternetRelayChatServer OptionCode = 74
OptionStreetTalkServer OptionCode = 75
OptionStreetTalkDirectoryAssistance OptionCode = 76
// DHCP Extensions
OptionRequestedIPAddress OptionCode = 50
OptionIPAddressLeaseTime OptionCode = 51
OptionOverload OptionCode = 52
OptionDHCPMessageType OptionCode = 53
OptionServerIdentifier OptionCode = 54
OptionParameterRequestList OptionCode = 55
OptionMessage OptionCode = 56
OptionMaximumDHCPMessageSize OptionCode = 57
OptionRenewalTimeValue OptionCode = 58
OptionRebindingTimeValue OptionCode = 59
OptionVendorClassIdentifier OptionCode = 60
OptionClientIdentifier OptionCode = 61
OptionTFTPServerName OptionCode = 66
OptionBootFileName OptionCode = 67
OptionUserClass OptionCode = 77
OptionClientArchitecture OptionCode = 93
OptionTZPOSIXString OptionCode = 100
OptionTZDatabaseString OptionCode = 101
OptionClasslessRouteFormat OptionCode = 121
)

View File

@ -1,58 +0,0 @@
package dhcp4
import (
"encoding/binary"
"net"
"time"
)
// IPRange returns how many ips in the ip range from start to stop (inclusive)
func IPRange(start, stop net.IP) int {
//return int(Uint([]byte(stop))-Uint([]byte(start))) + 1
return int(binary.BigEndian.Uint32(stop.To4())) - int(binary.BigEndian.Uint32(start.To4())) + 1
}
// IPAdd returns a copy of start + add.
// IPAdd(net.IP{192,168,1,1},30) returns net.IP{192.168.1.31}
func IPAdd(start net.IP, add int) net.IP { // IPv4 only
start = start.To4()
//v := Uvarint([]byte(start))
result := make(net.IP, 4)
binary.BigEndian.PutUint32(result, binary.BigEndian.Uint32(start)+uint32(add))
//PutUint([]byte(result), v+uint64(add))
return result
}
// IPLess returns where IP a is less than IP b.
func IPLess(a, b net.IP) bool {
b = b.To4()
for i, ai := range a.To4() {
if ai != b[i] {
return ai < b[i]
}
}
return false
}
// IPInRange returns true if ip is between (inclusive) start and stop.
func IPInRange(start, stop, ip net.IP) bool {
return !(IPLess(ip, start) || IPLess(stop, ip))
}
// OptionsLeaseTime - converts a time.Duration to a 4 byte slice, compatible
// with OptionIPAddressLeaseTime.
func OptionsLeaseTime(d time.Duration) []byte {
leaseBytes := make([]byte, 4)
binary.BigEndian.PutUint32(leaseBytes, uint32(d/time.Second))
//PutUvarint(leaseBytes, uint64(d/time.Second))
return leaseBytes
}
// JoinIPs returns a byte slice of IP addresses, one immediately after the other
// This may be useful for creating multiple IP options such as OptionRouter.
func JoinIPs(ips []net.IP) (b []byte) {
for _, v := range ips {
b = append(b, v.To4()...)
}
return
}

View File

@ -1,40 +0,0 @@
package dhcp4
type OptionCode byte
type Option struct {
Code OptionCode
Value []byte
}
// Map of DHCP options
type Options map[OptionCode][]byte
// SelectOrderOrAll has same functionality as SelectOrder, except if the order
// param is nil, whereby all options are added (in arbitary order).
func (o Options) SelectOrderOrAll(order []byte) []Option {
if order == nil {
opts := make([]Option, 0, len(o))
for i, v := range o {
opts = append(opts, Option{Code: i, Value: v})
}
return opts
}
return o.SelectOrder(order)
}
// SelectOrder returns a slice of options ordered and selected by a byte array
// usually defined by OptionParameterRequestList. This result is expected to be
// used in ReplyPacket()'s []Option parameter.
func (o Options) SelectOrder(order []byte) []Option {
opts := make([]Option, 0, len(order))
for _, v := range order {
if data, ok := o[OptionCode(v)]; ok {
opts = append(opts, Option{Code: OptionCode(v), Value: data})
}
}
return opts
}
type OpCode byte
type MessageType byte // Option 53

View File

@ -1,149 +0,0 @@
package dhcp4
import (
"net"
"time"
)
// A DHCP packet
type Packet []byte
func (p Packet) OpCode() OpCode { return OpCode(p[0]) }
func (p Packet) HType() byte { return p[1] }
func (p Packet) HLen() byte { return p[2] }
func (p Packet) Hops() byte { return p[3] }
func (p Packet) XId() []byte { return p[4:8] }
func (p Packet) Secs() []byte { return p[8:10] } // Never Used?
func (p Packet) Flags() []byte { return p[10:12] }
func (p Packet) CIAddr() net.IP { return net.IP(p[12:16]) }
func (p Packet) YIAddr() net.IP { return net.IP(p[16:20]) }
func (p Packet) SIAddr() net.IP { return net.IP(p[20:24]) }
func (p Packet) GIAddr() net.IP { return net.IP(p[24:28]) }
func (p Packet) CHAddr() net.HardwareAddr {
hLen := p.HLen()
if hLen > 16 { // Prevent chaddr exceeding p boundary
hLen = 16
}
return net.HardwareAddr(p[28 : 28+hLen]) // max endPos 44
}
// 192 bytes of zeros BOOTP legacy
func (p Packet) Cookie() []byte { return p[236:240] }
func (p Packet) Options() []byte {
if len(p) > 240 {
return p[240:]
}
return nil
}
func (p Packet) Broadcast() bool { return p.Flags()[0] > 127 }
func (p Packet) SetBroadcast(broadcast bool) {
if p.Broadcast() != broadcast {
p.Flags()[0] ^= 128
}
}
func (p Packet) SetOpCode(c OpCode) { p[0] = byte(c) }
func (p Packet) SetCHAddr(a net.HardwareAddr) {
copy(p[28:44], a)
p[2] = byte(len(a))
}
func (p Packet) SetHType(hType byte) { p[1] = hType }
func (p Packet) SetCookie(cookie []byte) { copy(p.Cookie(), cookie) }
func (p Packet) SetHops(hops byte) { p[3] = hops }
func (p Packet) SetXId(xId []byte) { copy(p.XId(), xId) }
func (p Packet) SetSecs(secs []byte) { copy(p.Secs(), secs) }
func (p Packet) SetFlags(flags []byte) { copy(p.Flags(), flags) }
func (p Packet) SetCIAddr(ip net.IP) { copy(p.CIAddr(), ip.To4()) }
func (p Packet) SetYIAddr(ip net.IP) { copy(p.YIAddr(), ip.To4()) }
func (p Packet) SetSIAddr(ip net.IP) { copy(p.SIAddr(), ip.To4()) }
func (p Packet) SetGIAddr(ip net.IP) { copy(p.GIAddr(), ip.To4()) }
// Parses the packet's options into an Options map
func (p Packet) ParseOptions() Options {
opts := p.Options()
options := make(Options, 10)
for len(opts) >= 2 && OptionCode(opts[0]) != End {
if OptionCode(opts[0]) == Pad {
opts = opts[1:]
continue
}
size := int(opts[1])
if len(opts) < 2+size {
break
}
options[OptionCode(opts[0])] = opts[2 : 2+size]
opts = opts[2+size:]
}
return options
}
func NewPacket(opCode OpCode) Packet {
p := make(Packet, 241)
p.SetOpCode(opCode)
p.SetHType(1) // Ethernet
p.SetCookie([]byte{99, 130, 83, 99})
p[240] = byte(End)
return p
}
// Appends a DHCP option to the end of a packet
func (p *Packet) AddOption(o OptionCode, value []byte) {
*p = append((*p)[:len(*p)-1], []byte{byte(o), byte(len(value))}...) // Strip off End, Add OptionCode and Length
*p = append(*p, value...) // Add Option Value
*p = append(*p, byte(End)) // Add on new End
}
// Removes all options from packet.
func (p *Packet) StripOptions() {
*p = append((*p)[:240], byte(End))
}
// Creates a request packet that a Client would send to a server.
func RequestPacket(mt MessageType, chAddr net.HardwareAddr, cIAddr net.IP, xId []byte, broadcast bool, options []Option) Packet {
p := NewPacket(BootRequest)
p.SetCHAddr(chAddr)
p.SetXId(xId)
if cIAddr != nil {
p.SetCIAddr(cIAddr)
}
p.SetBroadcast(broadcast)
p.AddOption(OptionDHCPMessageType, []byte{byte(mt)})
for _, o := range options {
p.AddOption(o.Code, o.Value)
}
p.PadToMinSize()
return p
}
// ReplyPacket creates a reply packet that a Server would send to a client.
// It uses the req Packet param to copy across common/necessary fields to
// associate the reply the request.
func ReplyPacket(req Packet, mt MessageType, serverId, yIAddr net.IP, leaseDuration time.Duration, options []Option) Packet {
p := NewPacket(BootReply)
p.SetXId(req.XId())
p.SetFlags(req.Flags())
p.SetYIAddr(yIAddr)
p.SetGIAddr(req.GIAddr())
p.SetCHAddr(req.CHAddr())
p.SetSecs(req.Secs())
p.AddOption(OptionDHCPMessageType, []byte{byte(mt)})
p.AddOption(OptionServerIdentifier, []byte(serverId))
p.AddOption(OptionIPAddressLeaseTime, OptionsLeaseTime(leaseDuration))
for _, o := range options {
p.AddOption(o.Code, o.Value)
}
p.PadToMinSize()
return p
}
// PadToMinSize pads a packet so that when sent over UDP, the entire packet,
// is 300 bytes (BOOTP min), to be compatible with really old devices.
var padder [272]byte
func (p *Packet) PadToMinSize() {
if n := len(*p); n < 272 {
*p = append(*p, padder[:272-n]...)
}
}

View File

@ -1,354 +0,0 @@
Mozilla Public License, version 2.0
1. Definitions
1.1. “Contributor”
means each individual or legal entity that creates, contributes to the
creation of, or owns Covered Software.
1.2. “Contributor Version”
means the combination of the Contributions of others (if any) used by a
Contributor and that particular Contributors Contribution.
1.3. “Contribution”
means Covered Software of a particular Contributor.
1.4. “Covered Software”
means Source Code Form to which the initial Contributor has attached the
notice in Exhibit A, the Executable Form of such Source Code Form, and
Modifications of such Source Code Form, in each case including portions
thereof.
1.5. “Incompatible With Secondary Licenses”
means
a. that the initial Contributor has attached the notice described in
Exhibit B to the Covered Software; or
b. that the Covered Software was made available under the terms of version
1.1 or earlier of the License, but not also under the terms of a
Secondary License.
1.6. “Executable Form”
means any form of the work other than Source Code Form.
1.7. “Larger Work”
means a work that combines Covered Software with other material, in a separate
file or files, that is not Covered Software.
1.8. “License”
means this document.
1.9. “Licensable”
means having the right to grant, to the maximum extent possible, whether at the
time of the initial grant or subsequently, any and all of the rights conveyed by
this License.
1.10. “Modifications”
means any of the following:
a. any file in Source Code Form that results from an addition to, deletion
from, or modification of the contents of Covered Software; or
b. any new file in Source Code Form that contains any Covered Software.
1.11. “Patent Claims” of a Contributor
means any patent claim(s), including without limitation, method, process,
and apparatus claims, in any patent Licensable by such Contributor that
would be infringed, but for the grant of the License, by the making,
using, selling, offering for sale, having made, import, or transfer of
either its Contributions or its Contributor Version.
1.12. “Secondary License”
means either the GNU General Public License, Version 2.0, the GNU Lesser
General Public License, Version 2.1, the GNU Affero General Public
License, Version 3.0, or any later versions of those licenses.
1.13. “Source Code Form”
means the form of the work preferred for making modifications.
1.14. “You” (or “Your”)
means an individual or a legal entity exercising rights under this
License. For legal entities, “You” includes any entity that controls, is
controlled by, or is under common control with You. For purposes of this
definition, “control” means (a) the power, direct or indirect, to cause
the direction or management of such entity, whether by contract or
otherwise, or (b) ownership of more than fifty percent (50%) of the
outstanding shares or beneficial ownership of such entity.
2. License Grants and Conditions
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
a. under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or as
part of a Larger Work; and
b. under Patent Claims of such Contributor to make, use, sell, offer for
sale, have made, import, and otherwise transfer either its Contributions
or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution become
effective for each Contribution on the date the Contributor first distributes
such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under this
License. No additional rights or licenses will be implied from the distribution
or licensing of Covered Software under this License. Notwithstanding Section
2.1(b) above, no patent license is granted by a Contributor:
a. for any code that a Contributor has removed from Covered Software; or
b. for infringements caused by: (i) Your and any other third partys
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
c. under Patent Claims infringed by Covered Software in the absence of its
Contributions.
This License does not grant any rights in the trademarks, service marks, or
logos of any Contributor (except as may be necessary to comply with the
notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this License
(see Section 10.2) or under the terms of a Secondary License (if permitted
under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its Contributions
are its original creation(s) or it has sufficient rights to grant the
rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under applicable
copyright doctrines of fair use, fair dealing, or other equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
Section 2.1.
3. Responsibilities
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under the
terms of this License. You must inform recipients that the Source Code Form
of the Covered Software is governed by the terms of this License, and how
they can obtain a copy of this License. You may not attempt to alter or
restrict the recipients rights in the Source Code Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
a. such Covered Software must also be made available in Source Code Form,
as described in Section 3.1, and You must inform recipients of the
Executable Form how they can obtain a copy of such Source Code Form by
reasonable means in a timely manner, at a charge no more than the cost
of distribution to the recipient; and
b. You may distribute such Executable Form under the terms of this License,
or sublicense it under different terms, provided that the license for
the Executable Form does not attempt to limit or alter the recipients
rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for the
Covered Software. If the Larger Work is a combination of Covered Software
with a work governed by one or more Secondary Licenses, and the Covered
Software is not Incompatible With Secondary Licenses, this License permits
You to additionally distribute such Covered Software under the terms of
such Secondary License(s), so that the recipient of the Larger Work may, at
their option, further distribute the Covered Software under the terms of
either this License or such Secondary License(s).
3.4. Notices
You may not remove or alter the substance of any license notices (including
copyright notices, patent notices, disclaimers of warranty, or limitations
of liability) contained within the Source Code Form of the Covered
Software, except that You may alter any license notices to the extent
required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on behalf
of any Contributor. You must make it absolutely clear that any such
warranty, support, indemnity, or liability obligation is offered by You
alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
If it is impossible for You to comply with any of the terms of this License
with respect to some or all of the Covered Software due to statute, judicial
order, or regulation then You must: (a) comply with the terms of this License
to the maximum extent possible; and (b) describe the limitations and the code
they affect. Such description must be placed in a text file included with all
distributions of the Covered Software under this License. Except to the
extent prohibited by statute or regulation, such description must be
sufficiently detailed for a recipient of ordinary skill to be able to
understand it.
5. Termination
5.1. The rights granted under this License will terminate automatically if You
fail to comply with any of its terms. However, if You become compliant,
then the rights granted under this License from a particular Contributor
are reinstated (a) provisionally, unless and until such Contributor
explicitly and finally terminates Your grants, and (b) on an ongoing basis,
if such Contributor fails to notify You of the non-compliance by some
reasonable means prior to 60 days after You have come back into compliance.
Moreover, Your grants from a particular Contributor are reinstated on an
ongoing basis if such Contributor notifies You of the non-compliance by
some reasonable means, this is the first time You have received notice of
non-compliance with this License from such Contributor, and You become
compliant prior to 30 days after Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions, counter-claims,
and cross-claims) alleging that a Contributor Version directly or
indirectly infringes any patent, then the rights granted to You by any and
all Contributors for the Covered Software under Section 2.1 of this License
shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
license agreements (excluding distributors and resellers) which have been
validly granted by You or Your distributors under this License prior to
termination shall survive termination.
6. Disclaimer of Warranty
Covered Software is provided under this License on an “as is” basis, without
warranty of any kind, either expressed, implied, or statutory, including,
without limitation, warranties that the Covered Software is free of defects,
merchantable, fit for a particular purpose or non-infringing. The entire
risk as to the quality and performance of the Covered Software is with You.
Should any Covered Software prove defective in any respect, You (not any
Contributor) assume the cost of any necessary servicing, repair, or
correction. This disclaimer of warranty constitutes an essential part of this
License. No use of any Covered Software is authorized under this License
except under this disclaimer.
7. Limitation of Liability
Under no circumstances and under no legal theory, whether tort (including
negligence), contract, or otherwise, shall any Contributor, or anyone who
distributes Covered Software as permitted above, be liable to You for any
direct, indirect, special, incidental, or consequential damages of any
character including, without limitation, damages for lost profits, loss of
goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses, even if such party shall have been
informed of the possibility of such damages. This limitation of liability
shall not apply to liability for death or personal injury resulting from such
partys negligence to the extent applicable law prohibits such limitation.
Some jurisdictions do not allow the exclusion or limitation of incidental or
consequential damages, so this exclusion and limitation may not apply to You.
8. Litigation
Any litigation relating to this License may be brought only in the courts of
a jurisdiction where the defendant maintains its principal place of business
and such litigation shall be governed by laws of that jurisdiction, without
reference to its conflict-of-law provisions. Nothing in this Section shall
prevent a partys ability to bring cross-claims or counter-claims.
9. Miscellaneous
This License represents the complete agreement concerning the subject matter
hereof. If any provision of this License is held to be unenforceable, such
provision shall be reformed only to the extent necessary to make it
enforceable. Any law or regulation which provides that the language of a
contract shall be construed against the drafter shall not be used to construe
this License against a Contributor.
10. Versions of the License
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version of
the License under which You originally received the Covered Software, or
under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a modified
version of this License if you rename the license and remove any
references to the name of the license steward (except to note that such
modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
If You choose to distribute Source Code Form that is Incompatible With
Secondary Licenses under the terms of this version of the License, the
notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file, then
You may include the notice in a location (such as a LICENSE file in a relevant
directory) where a recipient would be likely to look for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - “Incompatible With Secondary Licenses” Notice
This Source Code Form is “Incompatible
With Secondary Licenses”, as defined by
the Mozilla Public License, v. 2.0.

View File

@ -1,8 +0,0 @@
dhcp4client [![GoDoc](https://godoc.org/github.com/d2g/dhcp4client?status.svg)](http://godoc.org/github.com/d2g/dhcp4client) [![Coverage Status](https://coveralls.io/repos/d2g/dhcp4client/badge.svg?branch=HEAD)](https://coveralls.io/r/d2g/dhcp4client?branch=HEAD) [![Codeship Status for d2g/dhcp4client](https://codeship.com/projects/d75d9860-b364-0132-bc79-7e1d8cf367b9/status?branch=master)](https://codeship.com/projects/70187)
===========
DHCP Client
###### Thanks to:
@eyakubovich For AF_PACKET support.

View File

@ -1,366 +0,0 @@
package dhcp4client
import (
"bytes"
"crypto/rand"
"net"
"time"
"github.com/d2g/dhcp4"
)
const (
MaxDHCPLen = 576
)
type Client struct {
hardwareAddr net.HardwareAddr //The HardwareAddr to send in the request.
ignoreServers []net.IP //List of Servers to Ignore requests from.
timeout time.Duration //Time before we timeout.
broadcast bool //Set the Bcast flag in BOOTP Flags
connection connection //The Connection Method to use
}
/*
* Abstracts the type of underlying socket used
*/
type connection interface {
Close() error
Write(packet []byte) error
ReadFrom() ([]byte, net.IP, error)
SetReadTimeout(t time.Duration) error
}
func New(options ...func(*Client) error) (*Client, error) {
c := Client{
timeout: time.Second * 10,
broadcast: true,
}
err := c.SetOption(options...)
if err != nil {
return nil, err
}
//if connection hasn't been set as an option create the default.
if c.connection == nil {
conn, err := NewInetSock()
if err != nil {
return nil, err
}
c.connection = conn
}
return &c, nil
}
func (c *Client) SetOption(options ...func(*Client) error) error {
for _, opt := range options {
if err := opt(c); err != nil {
return err
}
}
return nil
}
func Timeout(t time.Duration) func(*Client) error {
return func(c *Client) error {
c.timeout = t
return nil
}
}
func IgnoreServers(s []net.IP) func(*Client) error {
return func(c *Client) error {
c.ignoreServers = s
return nil
}
}
func HardwareAddr(h net.HardwareAddr) func(*Client) error {
return func(c *Client) error {
c.hardwareAddr = h
return nil
}
}
func Broadcast(b bool) func(*Client) error {
return func(c *Client) error {
c.broadcast = b
return nil
}
}
func Connection(conn connection) func(*Client) error {
return func(c *Client) error {
c.connection = conn
return nil
}
}
/*
* Close Connections
*/
func (c *Client) Close() error {
if c.connection != nil {
return c.connection.Close()
}
return nil
}
/*
* Send the Discovery Packet to the Broadcast Channel
*/
func (c *Client) SendDiscoverPacket() (dhcp4.Packet, error) {
discoveryPacket := c.DiscoverPacket()
discoveryPacket.PadToMinSize()
return discoveryPacket, c.SendPacket(discoveryPacket)
}
/*
* Retreive Offer...
* Wait for the offer for a specific Discovery Packet.
*/
func (c *Client) GetOffer(discoverPacket *dhcp4.Packet) (dhcp4.Packet, error) {
for {
c.connection.SetReadTimeout(c.timeout)
readBuffer, source, err := c.connection.ReadFrom()
if err != nil {
return dhcp4.Packet{}, err
}
offerPacket := dhcp4.Packet(readBuffer)
offerPacketOptions := offerPacket.ParseOptions()
// Ignore Servers in my Ignore list
for _, ignoreServer := range c.ignoreServers {
if source.Equal(ignoreServer) {
continue
}
if offerPacket.SIAddr().Equal(ignoreServer) {
continue
}
}
if len(offerPacketOptions[dhcp4.OptionDHCPMessageType]) < 1 || dhcp4.MessageType(offerPacketOptions[dhcp4.OptionDHCPMessageType][0]) != dhcp4.Offer || !bytes.Equal(discoverPacket.XId(), offerPacket.XId()) {
continue
}
return offerPacket, nil
}
}
/*
* Send Request Based On the offer Received.
*/
func (c *Client) SendRequest(offerPacket *dhcp4.Packet) (dhcp4.Packet, error) {
requestPacket := c.RequestPacket(offerPacket)
requestPacket.PadToMinSize()
return requestPacket, c.SendPacket(requestPacket)
}
/*
* Retreive Acknowledgement
* Wait for the offer for a specific Request Packet.
*/
func (c *Client) GetAcknowledgement(requestPacket *dhcp4.Packet) (dhcp4.Packet, error) {
for {
c.connection.SetReadTimeout(c.timeout)
readBuffer, source, err := c.connection.ReadFrom()
if err != nil {
return dhcp4.Packet{}, err
}
acknowledgementPacket := dhcp4.Packet(readBuffer)
acknowledgementPacketOptions := acknowledgementPacket.ParseOptions()
// Ignore Servers in my Ignore list
for _, ignoreServer := range c.ignoreServers {
if source.Equal(ignoreServer) {
continue
}
if acknowledgementPacket.SIAddr().Equal(ignoreServer) {
continue
}
}
if !bytes.Equal(requestPacket.XId(), acknowledgementPacket.XId()) || len(acknowledgementPacketOptions[dhcp4.OptionDHCPMessageType]) < 1 || (dhcp4.MessageType(acknowledgementPacketOptions[dhcp4.OptionDHCPMessageType][0]) != dhcp4.ACK && dhcp4.MessageType(acknowledgementPacketOptions[dhcp4.OptionDHCPMessageType][0]) != dhcp4.NAK) {
continue
}
return acknowledgementPacket, nil
}
}
/*
* Send a DHCP Packet.
*/
func (c *Client) SendPacket(packet dhcp4.Packet) error {
return c.connection.Write(packet)
}
/*
* Create Discover Packet
*/
func (c *Client) DiscoverPacket() dhcp4.Packet {
messageid := make([]byte, 4)
if _, err := rand.Read(messageid); err != nil {
panic(err)
}
packet := dhcp4.NewPacket(dhcp4.BootRequest)
packet.SetCHAddr(c.hardwareAddr)
packet.SetXId(messageid)
packet.SetBroadcast(c.broadcast)
packet.AddOption(dhcp4.OptionDHCPMessageType, []byte{byte(dhcp4.Discover)})
//packet.PadToMinSize()
return packet
}
/*
* Create Request Packet
*/
func (c *Client) RequestPacket(offerPacket *dhcp4.Packet) dhcp4.Packet {
offerOptions := offerPacket.ParseOptions()
packet := dhcp4.NewPacket(dhcp4.BootRequest)
packet.SetCHAddr(c.hardwareAddr)
packet.SetXId(offerPacket.XId())
packet.SetCIAddr(offerPacket.CIAddr())
packet.SetSIAddr(offerPacket.SIAddr())
packet.SetBroadcast(c.broadcast)
packet.AddOption(dhcp4.OptionDHCPMessageType, []byte{byte(dhcp4.Request)})
packet.AddOption(dhcp4.OptionRequestedIPAddress, (offerPacket.YIAddr()).To4())
packet.AddOption(dhcp4.OptionServerIdentifier, offerOptions[dhcp4.OptionServerIdentifier])
//packet.PadToMinSize()
return packet
}
/*
* Create Request Packet For a Renew
*/
func (c *Client) RenewalRequestPacket(acknowledgement *dhcp4.Packet) dhcp4.Packet {
messageid := make([]byte, 4)
if _, err := rand.Read(messageid); err != nil {
panic(err)
}
acknowledgementOptions := acknowledgement.ParseOptions()
packet := dhcp4.NewPacket(dhcp4.BootRequest)
packet.SetCHAddr(acknowledgement.CHAddr())
packet.SetXId(messageid)
packet.SetCIAddr(acknowledgement.YIAddr())
packet.SetSIAddr(acknowledgement.SIAddr())
packet.SetBroadcast(c.broadcast)
packet.AddOption(dhcp4.OptionDHCPMessageType, []byte{byte(dhcp4.Request)})
packet.AddOption(dhcp4.OptionRequestedIPAddress, (acknowledgement.YIAddr()).To4())
packet.AddOption(dhcp4.OptionServerIdentifier, acknowledgementOptions[dhcp4.OptionServerIdentifier])
//packet.PadToMinSize()
return packet
}
/*
* Create Release Packet For a Release
*/
func (c *Client) ReleasePacket(acknowledgement *dhcp4.Packet) dhcp4.Packet {
messageid := make([]byte, 4)
if _, err := rand.Read(messageid); err != nil {
panic(err)
}
acknowledgementOptions := acknowledgement.ParseOptions()
packet := dhcp4.NewPacket(dhcp4.BootRequest)
packet.SetCHAddr(acknowledgement.CHAddr())
packet.SetXId(messageid)
packet.SetCIAddr(acknowledgement.YIAddr())
packet.AddOption(dhcp4.OptionDHCPMessageType, []byte{byte(dhcp4.Release)})
packet.AddOption(dhcp4.OptionServerIdentifier, acknowledgementOptions[dhcp4.OptionServerIdentifier])
//packet.PadToMinSize()
return packet
}
/*
* Lets do a Full DHCP Request.
*/
func (c *Client) Request() (bool, dhcp4.Packet, error) {
discoveryPacket, err := c.SendDiscoverPacket()
if err != nil {
return false, discoveryPacket, err
}
offerPacket, err := c.GetOffer(&discoveryPacket)
if err != nil {
return false, offerPacket, err
}
requestPacket, err := c.SendRequest(&offerPacket)
if err != nil {
return false, requestPacket, err
}
acknowledgement, err := c.GetAcknowledgement(&requestPacket)
if err != nil {
return false, acknowledgement, err
}
acknowledgementOptions := acknowledgement.ParseOptions()
if dhcp4.MessageType(acknowledgementOptions[dhcp4.OptionDHCPMessageType][0]) != dhcp4.ACK {
return false, acknowledgement, nil
}
return true, acknowledgement, nil
}
/*
* Renew a lease backed on the Acknowledgement Packet.
* Returns Sucessfull, The AcknoledgementPacket, Any Errors
*/
func (c *Client) Renew(acknowledgement dhcp4.Packet) (bool, dhcp4.Packet, error) {
renewRequest := c.RenewalRequestPacket(&acknowledgement)
renewRequest.PadToMinSize()
err := c.SendPacket(renewRequest)
if err != nil {
return false, renewRequest, err
}
newAcknowledgement, err := c.GetAcknowledgement(&renewRequest)
if err != nil {
return false, newAcknowledgement, err
}
newAcknowledgementOptions := newAcknowledgement.ParseOptions()
if dhcp4.MessageType(newAcknowledgementOptions[dhcp4.OptionDHCPMessageType][0]) != dhcp4.ACK {
return false, newAcknowledgement, nil
}
return true, newAcknowledgement, nil
}
/*
* Release a lease backed on the Acknowledgement Packet.
* Returns Any Errors
*/
func (c *Client) Release(acknowledgement dhcp4.Packet) error {
release := c.ReleasePacket(&acknowledgement)
release.PadToMinSize()
return c.SendPacket(release)
}

View File

@ -1,69 +0,0 @@
package dhcp4client
import (
"log"
"net"
"testing"
)
/*
* Example Client
*/
func Test_ExampleClient(test *testing.T) {
var err error
m, err := net.ParseMAC("08-00-27-00-A8-E8")
if err != nil {
log.Printf("MAC Error:%v\n", err)
}
//Create a connection to use
//We need to set the connection ports to 1068 and 1067 so we don't need root access
c, err := NewInetSock(SetLocalAddr(net.UDPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 1068}), SetRemoteAddr(net.UDPAddr{IP: net.IPv4bcast, Port: 1067}))
if err != nil {
test.Error("Client Conection Generation:" + err.Error())
}
exampleClient, err := New(HardwareAddr(m), Connection(c))
if err != nil {
test.Fatalf("Error:%v\n", err)
}
success, acknowledgementpacket, err := exampleClient.Request()
test.Logf("Success:%v\n", success)
test.Logf("Packet:%v\n", acknowledgementpacket)
if err != nil {
networkError, ok := err.(*net.OpError)
if ok && networkError.Timeout() {
test.Log("Test Skipping as it didn't find a DHCP Server")
test.SkipNow()
}
test.Fatalf("Error:%v\n", err)
}
if !success {
test.Error("We didn't sucessfully get a DHCP Lease?")
} else {
log.Printf("IP Received:%v\n", acknowledgementpacket.YIAddr().String())
}
test.Log("Start Renewing Lease")
success, acknowledgementpacket, err = exampleClient.Renew(acknowledgementpacket)
if err != nil {
networkError, ok := err.(*net.OpError)
if ok && networkError.Timeout() {
test.Log("Renewal Failed! Because it didn't find the DHCP server very Strange")
test.Errorf("Error" + err.Error())
}
test.Fatalf("Error:%v\n", err)
}
if !success {
test.Error("We didn't sucessfully Renew a DHCP Lease?")
} else {
log.Printf("IP Received:%v\n", acknowledgementpacket.YIAddr().String())
}
}

View File

@ -1,75 +0,0 @@
package dhcp4client
import (
"net"
"time"
)
type inetSock struct {
*net.UDPConn
laddr net.UDPAddr
raddr net.UDPAddr
}
func NewInetSock(options ...func(*inetSock) error) (*inetSock, error) {
c := &inetSock{
laddr: net.UDPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 68},
raddr: net.UDPAddr{IP: net.IPv4bcast, Port: 67},
}
err := c.setOption(options...)
if err != nil {
return nil, err
}
conn, err := net.ListenUDP("udp4", &c.laddr)
if err != nil {
return nil, err
}
c.UDPConn = conn
return c, err
}
func (c *inetSock) setOption(options ...func(*inetSock) error) error {
for _, opt := range options {
if err := opt(c); err != nil {
return err
}
}
return nil
}
func SetLocalAddr(l net.UDPAddr) func(*inetSock) error {
return func(c *inetSock) error {
c.laddr = l
return nil
}
}
func SetRemoteAddr(r net.UDPAddr) func(*inetSock) error {
return func(c *inetSock) error {
c.raddr = r
return nil
}
}
func (c *inetSock) Write(packet []byte) error {
_, err := c.WriteToUDP(packet, &c.raddr)
return err
}
func (c *inetSock) ReadFrom() ([]byte, net.IP, error) {
readBuffer := make([]byte, MaxDHCPLen)
n, source, err := c.ReadFromUDP(readBuffer)
if source != nil {
return readBuffer[:n], source.IP, err
} else {
return readBuffer[:n], net.IP{}, err
}
}
func (c *inetSock) SetReadTimeout(t time.Duration) error {
return c.SetReadDeadline(time.Now().Add(t))
}

View File

@ -1,10 +0,0 @@
package dhcp4client
import (
"math/rand"
"time"
)
func init() {
rand.Seed(time.Now().Unix())
}

View File

@ -1,147 +0,0 @@
package dhcp4client
import (
"crypto/rand"
"encoding/binary"
"net"
"time"
"golang.org/x/sys/unix"
)
const (
minIPHdrLen = 20
maxIPHdrLen = 60
udpHdrLen = 8
ip4Ver = 0x40
ttl = 16
srcPort = 68
dstPort = 67
)
var (
bcastMAC = []byte{255, 255, 255, 255, 255, 255}
)
// abstracts AF_PACKET
type packetSock struct {
fd int
ifindex int
}
func NewPacketSock(ifindex int) (*packetSock, error) {
fd, err := unix.Socket(unix.AF_PACKET, unix.SOCK_DGRAM, int(swap16(unix.ETH_P_IP)))
if err != nil {
return nil, err
}
addr := unix.SockaddrLinklayer{
Ifindex: ifindex,
Protocol: swap16(unix.ETH_P_IP),
}
if err = unix.Bind(fd, &addr); err != nil {
return nil, err
}
return &packetSock{
fd: fd,
ifindex: ifindex,
}, nil
}
func (pc *packetSock) Close() error {
return unix.Close(pc.fd)
}
func (pc *packetSock) Write(packet []byte) error {
lladdr := unix.SockaddrLinklayer{
Ifindex: pc.ifindex,
Protocol: swap16(unix.ETH_P_IP),
Halen: uint8(len(bcastMAC)),
}
copy(lladdr.Addr[:], bcastMAC)
pkt := make([]byte, minIPHdrLen+udpHdrLen+len(packet))
fillIPHdr(pkt[0:minIPHdrLen], udpHdrLen+uint16(len(packet)))
fillUDPHdr(pkt[minIPHdrLen:minIPHdrLen+udpHdrLen], uint16(len(packet)))
// payload
copy(pkt[minIPHdrLen+udpHdrLen:len(pkt)], packet)
return unix.Sendto(pc.fd, pkt, 0, &lladdr)
}
func (pc *packetSock) ReadFrom() ([]byte, net.IP, error) {
pkt := make([]byte, maxIPHdrLen+udpHdrLen+MaxDHCPLen)
n, _, err := unix.Recvfrom(pc.fd, pkt, 0)
if err != nil {
return nil, nil, err
}
// IP hdr len
ihl := int(pkt[0]&0x0F) * 4
// Source IP address
src := net.IP(pkt[12:16])
return pkt[ihl+udpHdrLen : n], src, nil
}
func (pc *packetSock) SetReadTimeout(t time.Duration) error {
tv := unix.NsecToTimeval(t.Nanoseconds())
return unix.SetsockoptTimeval(pc.fd, unix.SOL_SOCKET, unix.SO_RCVTIMEO, &tv)
}
// compute's 1's complement checksum
func chksum(p []byte, csum []byte) {
cklen := len(p)
s := uint32(0)
for i := 0; i < (cklen - 1); i += 2 {
s += uint32(p[i+1])<<8 | uint32(p[i])
}
if cklen&1 == 1 {
s += uint32(p[cklen-1])
}
s = (s >> 16) + (s & 0xffff)
s = s + (s >> 16)
s = ^s
csum[0] = uint8(s & 0xff)
csum[1] = uint8(s >> 8)
}
func fillIPHdr(hdr []byte, payloadLen uint16) {
// version + IHL
hdr[0] = ip4Ver | (minIPHdrLen / 4)
// total length
binary.BigEndian.PutUint16(hdr[2:4], uint16(len(hdr))+payloadLen)
// identification
if _, err := rand.Read(hdr[4:5]); err != nil {
panic(err)
}
// TTL
hdr[8] = 16
// Protocol
hdr[9] = unix.IPPROTO_UDP
// dst IP
copy(hdr[16:20], net.IPv4bcast.To4())
// compute IP hdr checksum
chksum(hdr[0:len(hdr)], hdr[10:12])
}
func fillUDPHdr(hdr []byte, payloadLen uint16) {
// src port
binary.BigEndian.PutUint16(hdr[0:2], srcPort)
// dest port
binary.BigEndian.PutUint16(hdr[2:4], dstPort)
// length
binary.BigEndian.PutUint16(hdr[4:6], udpHdrLen+payloadLen)
}
func swap16(x uint16) uint16 {
var b [2]byte
binary.BigEndian.PutUint16(b[:], x)
return binary.LittleEndian.Uint16(b[:])
}

View File

@ -1,3 +0,0 @@
language: go
install:
- go get github.com/vishvananda/netns

View File

@ -1,192 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
Copyright 2014 Vishvananda Ishaya.
Copyright 2014 Docker, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,29 +0,0 @@
DIRS := \
. \
nl
DEPS = \
github.com/vishvananda/netns
uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
testdirs = $(call uniq,$(foreach d,$(1),$(dir $(wildcard $(d)/*_test.go))))
goroot = $(addprefix ../../../,$(1))
unroot = $(subst ../../../,,$(1))
fmt = $(addprefix fmt-,$(1))
all: fmt
$(call goroot,$(DEPS)):
go get $(call unroot,$@)
.PHONY: $(call testdirs,$(DIRS))
$(call testdirs,$(DIRS)):
sudo -E go test -v github.com/vishvananda/netlink/$@
$(call fmt,$(call testdirs,$(DIRS))):
! gofmt -l $(subst fmt-,,$@)/*.go | grep ''
.PHONY: fmt
fmt: $(call fmt,$(call testdirs,$(DIRS)))
test: fmt $(call goroot,$(DEPS)) $(call testdirs,$(DIRS))

View File

@ -1,83 +0,0 @@
# netlink - netlink library for go #
[![Build Status](https://travis-ci.org/vishvananda/netlink.png?branch=master)](https://travis-ci.org/vishvananda/netlink) [![GoDoc](https://godoc.org/github.com/vishvananda/netlink?status.svg)](https://godoc.org/github.com/vishvananda/netlink)
The netlink package provides a simple netlink library for go. Netlink
is the interface a user-space program in linux uses to communicate with
the kernel. It can be used to add and remove interfaces, set ip addresses
and routes, and configure ipsec. Netlink communication requires elevated
privileges, so in most cases this code needs to be run as root. Since
low-level netlink messages are inscrutable at best, the library attempts
to provide an api that is loosely modeled on the CLI provied by iproute2.
Actions like `ip link add` will be accomplished via a similarly named
function like AddLink(). This library began its life as a fork of the
netlink functionality in
[docker/libcontainer](https://github.com/docker/libcontainer) but was
heavily rewritten to improve testability, performance, and to add new
functionality like ipsec xfrm handling.
## Local Build and Test ##
You can use go get command:
go get github.com/vishvananda/netlink
Testing dependencies:
go get github.com/vishvananda/netns
Testing (requires root):
sudo -E go test github.com/vishvananda/netlink
## Examples ##
Add a new bridge and add eth1 into it:
```go
package main
import (
"net"
"github.com/vishvananda/netlink"
)
func main() {
mybridge := &netlink.Bridge{netlink.LinkAttrs{Name: "foo"}}
_ := netlink.LinkAdd(mybridge)
eth1, _ := netlink.LinkByName("eth1")
netlink.LinkSetMaster(eth1, mybridge)
}
```
Add a new ip address to loopback:
```go
package main
import (
"net"
"github.com/vishvananda/netlink"
)
func main() {
lo, _ := netlink.LinkByName("lo")
addr, _ := netlink.ParseAddr("169.254.169.254/32")
netlink.AddrAdd(lo, addr)
}
```
## Future Work ##
Many pieces of netlink are not yet fully supported in the high-level
interface. Aspects of virtually all of the high-level objects don't exist.
Many of the underlying primitives are there, so its a matter of putting
the right fields into the high-level objects and making sure that they
are serialized and deserialized correctly in the Add and List methods.
There are also a few pieces of low level netlink functionality that still
need to be implemented. Routing rules are not in place and some of the
more advanced link types. Hopefully there is decent structure and testing
in place to make these fairly straightforward to add.

View File

@ -1,43 +0,0 @@
package netlink
import (
"fmt"
"net"
"strings"
)
// Addr represents an IP address from netlink. Netlink ip addresses
// include a mask, so it stores the address as a net.IPNet.
type Addr struct {
*net.IPNet
Label string
}
// String returns $ip/$netmask $label
func (addr Addr) String() string {
return fmt.Sprintf("%s %s", addr.IPNet, addr.Label)
}
// ParseAddr parses the string representation of an address in the
// form $ip/$netmask $label. The label portion is optional
func ParseAddr(s string) (*Addr, error) {
label := ""
parts := strings.Split(s, " ")
if len(parts) > 1 {
s = parts[0]
label = parts[1]
}
m, err := ParseIPNet(s)
if err != nil {
return nil, err
}
return &Addr{IPNet: m, Label: label}, nil
}
// Equal returns true if both Addrs have the same net.IPNet value.
func (a Addr) Equal(x Addr) bool {
sizea, _ := a.Mask.Size()
sizeb, _ := x.Mask.Size()
// ignore label for comparison
return a.IP.Equal(x.IP) && sizea == sizeb
}

View File

@ -1,114 +0,0 @@
package netlink
import (
"fmt"
"net"
"strings"
"syscall"
"github.com/vishvananda/netlink/nl"
)
// AddrAdd will add an IP address to a link device.
// Equivalent to: `ip addr add $addr dev $link`
func AddrAdd(link Link, addr *Addr) error {
req := nl.NewNetlinkRequest(syscall.RTM_NEWADDR, syscall.NLM_F_CREATE|syscall.NLM_F_EXCL|syscall.NLM_F_ACK)
return addrHandle(link, addr, req)
}
// AddrDel will delete an IP address from a link device.
// Equivalent to: `ip addr del $addr dev $link`
func AddrDel(link Link, addr *Addr) error {
req := nl.NewNetlinkRequest(syscall.RTM_DELADDR, syscall.NLM_F_ACK)
return addrHandle(link, addr, req)
}
func addrHandle(link Link, addr *Addr, req *nl.NetlinkRequest) error {
base := link.Attrs()
if addr.Label != "" && !strings.HasPrefix(addr.Label, base.Name) {
return fmt.Errorf("label must begin with interface name")
}
ensureIndex(base)
family := nl.GetIPFamily(addr.IP)
msg := nl.NewIfAddrmsg(family)
msg.Index = uint32(base.Index)
prefixlen, _ := addr.Mask.Size()
msg.Prefixlen = uint8(prefixlen)
req.AddData(msg)
var addrData []byte
if family == FAMILY_V4 {
addrData = addr.IP.To4()
} else {
addrData = addr.IP.To16()
}
localData := nl.NewRtAttr(syscall.IFA_LOCAL, addrData)
req.AddData(localData)
addressData := nl.NewRtAttr(syscall.IFA_ADDRESS, addrData)
req.AddData(addressData)
if addr.Label != "" {
labelData := nl.NewRtAttr(syscall.IFA_LABEL, nl.ZeroTerminated(addr.Label))
req.AddData(labelData)
}
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
}
// AddrList gets a list of IP addresses in the system.
// Equivalent to: `ip addr show`.
// The list can be filtered by link and ip family.
func AddrList(link Link, family int) ([]Addr, error) {
req := nl.NewNetlinkRequest(syscall.RTM_GETADDR, syscall.NLM_F_DUMP)
msg := nl.NewIfInfomsg(family)
req.AddData(msg)
msgs, err := req.Execute(syscall.NETLINK_ROUTE, syscall.RTM_NEWADDR)
if err != nil {
return nil, err
}
index := 0
if link != nil {
base := link.Attrs()
ensureIndex(base)
index = base.Index
}
res := make([]Addr, 0)
for _, m := range msgs {
msg := nl.DeserializeIfAddrmsg(m)
if link != nil && msg.Index != uint32(index) {
// Ignore messages from other interfaces
continue
}
attrs, err := nl.ParseRouteAttr(m[msg.Len():])
if err != nil {
return nil, err
}
var addr Addr
for _, attr := range attrs {
switch attr.Attr.Type {
case syscall.IFA_ADDRESS:
addr.IPNet = &net.IPNet{
IP: attr.Value,
Mask: net.CIDRMask(int(msg.Prefixlen), 8*len(attr.Value)),
}
case syscall.IFA_LABEL:
addr.Label = string(attr.Value[:len(attr.Value)-1])
}
}
res = append(res, addr)
}
return res, nil
}

View File

@ -1,45 +0,0 @@
package netlink
import (
"testing"
)
func TestAddrAddDel(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
link, err := LinkByName("lo")
if err != nil {
t.Fatal(err)
}
addr, err := ParseAddr("127.1.1.1/24 local")
if err != nil {
t.Fatal(err)
}
if err = AddrAdd(link, addr); err != nil {
t.Fatal(err)
}
addrs, err := AddrList(link, FAMILY_ALL)
if err != nil {
t.Fatal(err)
}
if len(addrs) != 1 || !addr.Equal(addrs[0]) || addrs[0].Label != addr.Label {
t.Fatal("Address not added properly")
}
if err = AddrDel(link, addr); err != nil {
t.Fatal(err)
}
addrs, err = AddrList(link, FAMILY_ALL)
if err != nil {
t.Fatal(err)
}
if len(addrs) != 0 {
t.Fatal("Address not removed properly")
}
}

View File

@ -1,193 +0,0 @@
package netlink
import "net"
// Link represents a link device from netlink. Shared link attributes
// like name may be retrieved using the Attrs() method. Unique data
// can be retrieved by casting the object to the proper type.
type Link interface {
Attrs() *LinkAttrs
Type() string
}
type (
NsPid int
NsFd int
)
// LinkAttrs represents data shared by most link types
type LinkAttrs struct {
Index int
MTU int
TxQLen uint32 // Transmit Queue Length
Name string
HardwareAddr net.HardwareAddr
Flags net.Flags
ParentIndex int // index of the parent link device
MasterIndex int // must be the index of a bridge
Namespace interface{} // nil | NsPid | NsFd
}
// Device links cannot be created via netlink. These links
// are links created by udev like 'lo' and 'etho0'
type Device struct {
LinkAttrs
}
func (device *Device) Attrs() *LinkAttrs {
return &device.LinkAttrs
}
func (device *Device) Type() string {
return "device"
}
// Dummy links are dummy ethernet devices
type Dummy struct {
LinkAttrs
}
func (dummy *Dummy) Attrs() *LinkAttrs {
return &dummy.LinkAttrs
}
func (dummy *Dummy) Type() string {
return "dummy"
}
// Bridge links are simple linux bridges
type Bridge struct {
LinkAttrs
}
func (bridge *Bridge) Attrs() *LinkAttrs {
return &bridge.LinkAttrs
}
func (bridge *Bridge) Type() string {
return "bridge"
}
// Vlan links have ParentIndex set in their Attrs()
type Vlan struct {
LinkAttrs
VlanId int
}
func (vlan *Vlan) Attrs() *LinkAttrs {
return &vlan.LinkAttrs
}
func (vlan *Vlan) Type() string {
return "vlan"
}
type MacvlanMode uint16
const (
MACVLAN_MODE_DEFAULT MacvlanMode = iota
MACVLAN_MODE_PRIVATE
MACVLAN_MODE_VEPA
MACVLAN_MODE_BRIDGE
MACVLAN_MODE_PASSTHRU
MACVLAN_MODE_SOURCE
)
// Macvlan links have ParentIndex set in their Attrs()
type Macvlan struct {
LinkAttrs
Mode MacvlanMode
}
func (macvlan *Macvlan) Attrs() *LinkAttrs {
return &macvlan.LinkAttrs
}
func (macvlan *Macvlan) Type() string {
return "macvlan"
}
// Veth devices must specify PeerName on create
type Veth struct {
LinkAttrs
PeerName string // veth on create only
}
func (veth *Veth) Attrs() *LinkAttrs {
return &veth.LinkAttrs
}
func (veth *Veth) Type() string {
return "veth"
}
// Generic links represent types that are not currently understood
// by this netlink library.
type Generic struct {
LinkAttrs
LinkType string
}
func (generic *Generic) Attrs() *LinkAttrs {
return &generic.LinkAttrs
}
func (generic *Generic) Type() string {
return generic.LinkType
}
type Vxlan struct {
LinkAttrs
VxlanId int
VtepDevIndex int
SrcAddr net.IP
Group net.IP
TTL int
TOS int
Learning bool
Proxy bool
RSC bool
L2miss bool
L3miss bool
NoAge bool
Age int
Limit int
Port int
PortLow int
PortHigh int
}
func (vxlan *Vxlan) Attrs() *LinkAttrs {
return &vxlan.LinkAttrs
}
func (vxlan *Vxlan) Type() string {
return "vxlan"
}
type IPVlanMode uint16
const (
IPVLAN_MODE_L2 IPVlanMode = iota
IPVLAN_MODE_L3
IPVLAN_MODE_MAX
)
type IPVlan struct {
LinkAttrs
Mode IPVlanMode
}
func (ipvlan *IPVlan) Attrs() *LinkAttrs {
return &ipvlan.LinkAttrs
}
func (ipvlan *IPVlan) Type() string {
return "ipvlan"
}
// iproute2 supported devices;
// vlan | veth | vcan | dummy | ifb | macvlan | macvtap |
// bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan |
// gre | gretap | ip6gre | ip6gretap | vti | nlmon |
// bond_slave | ipvlan

View File

@ -1,749 +0,0 @@
package netlink
import (
"bytes"
"encoding/binary"
"fmt"
"net"
"syscall"
"github.com/vishvananda/netlink/nl"
)
var native = nl.NativeEndian()
var lookupByDump = false
var macvlanModes = [...]uint32{
0,
nl.MACVLAN_MODE_PRIVATE,
nl.MACVLAN_MODE_VEPA,
nl.MACVLAN_MODE_BRIDGE,
nl.MACVLAN_MODE_PASSTHRU,
nl.MACVLAN_MODE_SOURCE,
}
func ensureIndex(link *LinkAttrs) {
if link != nil && link.Index == 0 {
newlink, _ := LinkByName(link.Name)
if newlink != nil {
link.Index = newlink.Attrs().Index
}
}
}
// LinkSetUp enables the link device.
// Equivalent to: `ip link set $link up`
func LinkSetUp(link Link) error {
base := link.Attrs()
ensureIndex(base)
req := nl.NewNetlinkRequest(syscall.RTM_NEWLINK, syscall.NLM_F_ACK)
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
msg.Change = syscall.IFF_UP
msg.Flags = syscall.IFF_UP
msg.Index = int32(base.Index)
req.AddData(msg)
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
}
// LinkSetUp disables link device.
// Equivalent to: `ip link set $link down`
func LinkSetDown(link Link) error {
base := link.Attrs()
ensureIndex(base)
req := nl.NewNetlinkRequest(syscall.RTM_NEWLINK, syscall.NLM_F_ACK)
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
msg.Change = syscall.IFF_UP
msg.Flags = 0 & ^syscall.IFF_UP
msg.Index = int32(base.Index)
req.AddData(msg)
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
}
// LinkSetMTU sets the mtu of the link device.
// Equivalent to: `ip link set $link mtu $mtu`
func LinkSetMTU(link Link, mtu int) error {
base := link.Attrs()
ensureIndex(base)
req := nl.NewNetlinkRequest(syscall.RTM_SETLINK, syscall.NLM_F_ACK)
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
msg.Type = syscall.RTM_SETLINK
msg.Flags = syscall.NLM_F_REQUEST
msg.Index = int32(base.Index)
msg.Change = nl.DEFAULT_CHANGE
req.AddData(msg)
b := make([]byte, 4)
native.PutUint32(b, uint32(mtu))
data := nl.NewRtAttr(syscall.IFLA_MTU, b)
req.AddData(data)
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
}
// LinkSetName sets the name of the link device.
// Equivalent to: `ip link set $link name $name`
func LinkSetName(link Link, name string) error {
base := link.Attrs()
ensureIndex(base)
req := nl.NewNetlinkRequest(syscall.RTM_SETLINK, syscall.NLM_F_ACK)
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
msg.Type = syscall.RTM_SETLINK
msg.Flags = syscall.NLM_F_REQUEST
msg.Index = int32(base.Index)
msg.Change = nl.DEFAULT_CHANGE
req.AddData(msg)
data := nl.NewRtAttr(syscall.IFLA_IFNAME, []byte(name))
req.AddData(data)
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
}
// LinkSetHardwareAddr sets the hardware address of the link device.
// Equivalent to: `ip link set $link address $hwaddr`
func LinkSetHardwareAddr(link Link, hwaddr net.HardwareAddr) error {
base := link.Attrs()
ensureIndex(base)
req := nl.NewNetlinkRequest(syscall.RTM_SETLINK, syscall.NLM_F_ACK)
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
msg.Type = syscall.RTM_SETLINK
msg.Flags = syscall.NLM_F_REQUEST
msg.Index = int32(base.Index)
msg.Change = nl.DEFAULT_CHANGE
req.AddData(msg)
data := nl.NewRtAttr(syscall.IFLA_ADDRESS, []byte(hwaddr))
req.AddData(data)
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
}
// LinkSetMaster sets the master of the link device.
// Equivalent to: `ip link set $link master $master`
func LinkSetMaster(link Link, master *Bridge) error {
index := 0
if master != nil {
masterBase := master.Attrs()
ensureIndex(masterBase)
index = masterBase.Index
}
return LinkSetMasterByIndex(link, index)
}
// LinkSetMasterByIndex sets the master of the link device.
// Equivalent to: `ip link set $link master $master`
func LinkSetMasterByIndex(link Link, masterIndex int) error {
base := link.Attrs()
ensureIndex(base)
req := nl.NewNetlinkRequest(syscall.RTM_SETLINK, syscall.NLM_F_ACK)
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
msg.Type = syscall.RTM_SETLINK
msg.Flags = syscall.NLM_F_REQUEST
msg.Index = int32(base.Index)
msg.Change = nl.DEFAULT_CHANGE
req.AddData(msg)
b := make([]byte, 4)
native.PutUint32(b, uint32(masterIndex))
data := nl.NewRtAttr(syscall.IFLA_MASTER, b)
req.AddData(data)
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
}
// LinkSetNsPid puts the device into a new network namespace. The
// pid must be a pid of a running process.
// Equivalent to: `ip link set $link netns $pid`
func LinkSetNsPid(link Link, nspid int) error {
base := link.Attrs()
ensureIndex(base)
req := nl.NewNetlinkRequest(syscall.RTM_SETLINK, syscall.NLM_F_ACK)
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
msg.Type = syscall.RTM_SETLINK
msg.Flags = syscall.NLM_F_REQUEST
msg.Index = int32(base.Index)
msg.Change = nl.DEFAULT_CHANGE
req.AddData(msg)
b := make([]byte, 4)
native.PutUint32(b, uint32(nspid))
data := nl.NewRtAttr(syscall.IFLA_NET_NS_PID, b)
req.AddData(data)
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
}
// LinkSetNsPid puts the device into a new network namespace. The
// fd must be an open file descriptor to a network namespace.
// Similar to: `ip link set $link netns $ns`
func LinkSetNsFd(link Link, fd int) error {
base := link.Attrs()
ensureIndex(base)
req := nl.NewNetlinkRequest(syscall.RTM_SETLINK, syscall.NLM_F_ACK)
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
msg.Type = syscall.RTM_SETLINK
msg.Flags = syscall.NLM_F_REQUEST
msg.Index = int32(base.Index)
msg.Change = nl.DEFAULT_CHANGE
req.AddData(msg)
b := make([]byte, 4)
native.PutUint32(b, uint32(fd))
data := nl.NewRtAttr(nl.IFLA_NET_NS_FD, b)
req.AddData(data)
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
}
func boolAttr(val bool) []byte {
var v uint8
if val {
v = 1
}
return nl.Uint8Attr(v)
}
type vxlanPortRange struct {
Lo, Hi uint16
}
func addVxlanAttrs(vxlan *Vxlan, linkInfo *nl.RtAttr) {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil)
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_ID, nl.Uint32Attr(uint32(vxlan.VxlanId)))
if vxlan.VtepDevIndex != 0 {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_LINK, nl.Uint32Attr(uint32(vxlan.VtepDevIndex)))
}
if vxlan.SrcAddr != nil {
ip := vxlan.SrcAddr.To4()
if ip != nil {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_LOCAL, []byte(ip))
} else {
ip = vxlan.SrcAddr.To16()
if ip != nil {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_LOCAL6, []byte(ip))
}
}
}
if vxlan.Group != nil {
group := vxlan.Group.To4()
if group != nil {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_GROUP, []byte(group))
} else {
group = vxlan.Group.To16()
if group != nil {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_GROUP6, []byte(group))
}
}
}
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_TTL, nl.Uint8Attr(uint8(vxlan.TTL)))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_TOS, nl.Uint8Attr(uint8(vxlan.TOS)))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_LEARNING, boolAttr(vxlan.Learning))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_PROXY, boolAttr(vxlan.Proxy))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_RSC, boolAttr(vxlan.RSC))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_L2MISS, boolAttr(vxlan.L2miss))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_L3MISS, boolAttr(vxlan.L3miss))
if vxlan.NoAge {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_AGEING, nl.Uint32Attr(0))
} else if vxlan.Age > 0 {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_AGEING, nl.Uint32Attr(uint32(vxlan.Age)))
}
if vxlan.Limit > 0 {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_LIMIT, nl.Uint32Attr(uint32(vxlan.Limit)))
}
if vxlan.Port > 0 {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_PORT, nl.Uint16Attr(uint16(vxlan.Port)))
}
if vxlan.PortLow > 0 || vxlan.PortHigh > 0 {
pr := vxlanPortRange{uint16(vxlan.PortLow), uint16(vxlan.PortHigh)}
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, &pr)
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_PORT_RANGE, buf.Bytes())
}
}
// LinkAdd adds a new link device. The type and features of the device
// are taken fromt the parameters in the link object.
// Equivalent to: `ip link add $link`
func LinkAdd(link Link) error {
// TODO: set mtu and hardware address
// TODO: support extra data for macvlan
base := link.Attrs()
if base.Name == "" {
return fmt.Errorf("LinkAttrs.Name cannot be empty!")
}
req := nl.NewNetlinkRequest(syscall.RTM_NEWLINK, syscall.NLM_F_CREATE|syscall.NLM_F_EXCL|syscall.NLM_F_ACK)
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
req.AddData(msg)
if base.ParentIndex != 0 {
b := make([]byte, 4)
native.PutUint32(b, uint32(base.ParentIndex))
data := nl.NewRtAttr(syscall.IFLA_LINK, b)
req.AddData(data)
} else if link.Type() == "ipvlan" {
return fmt.Errorf("Can't create ipvlan link without ParentIndex")
}
nameData := nl.NewRtAttr(syscall.IFLA_IFNAME, nl.ZeroTerminated(base.Name))
req.AddData(nameData)
if base.MTU > 0 {
mtu := nl.NewRtAttr(syscall.IFLA_MTU, nl.Uint32Attr(uint32(base.MTU)))
req.AddData(mtu)
}
if base.Namespace != nil {
var attr *nl.RtAttr
switch base.Namespace.(type) {
case NsPid:
val := nl.Uint32Attr(uint32(base.Namespace.(NsPid)))
attr = nl.NewRtAttr(syscall.IFLA_NET_NS_PID, val)
case NsFd:
val := nl.Uint32Attr(uint32(base.Namespace.(NsFd)))
attr = nl.NewRtAttr(nl.IFLA_NET_NS_FD, val)
}
req.AddData(attr)
}
linkInfo := nl.NewRtAttr(syscall.IFLA_LINKINFO, nil)
nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_KIND, nl.NonZeroTerminated(link.Type()))
nl.NewRtAttrChild(linkInfo, syscall.IFLA_TXQLEN, nl.Uint32Attr(base.TxQLen))
if vlan, ok := link.(*Vlan); ok {
b := make([]byte, 2)
native.PutUint16(b, uint16(vlan.VlanId))
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil)
nl.NewRtAttrChild(data, nl.IFLA_VLAN_ID, b)
} else if veth, ok := link.(*Veth); ok {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil)
peer := nl.NewRtAttrChild(data, nl.VETH_INFO_PEER, nil)
nl.NewIfInfomsgChild(peer, syscall.AF_UNSPEC)
nl.NewRtAttrChild(peer, syscall.IFLA_IFNAME, nl.ZeroTerminated(veth.PeerName))
nl.NewRtAttrChild(peer, syscall.IFLA_TXQLEN, nl.Uint32Attr(base.TxQLen))
if base.MTU > 0 {
nl.NewRtAttrChild(peer, syscall.IFLA_MTU, nl.Uint32Attr(uint32(base.MTU)))
}
} else if vxlan, ok := link.(*Vxlan); ok {
addVxlanAttrs(vxlan, linkInfo)
} else if ipv, ok := link.(*IPVlan); ok {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil)
nl.NewRtAttrChild(data, nl.IFLA_IPVLAN_MODE, nl.Uint16Attr(uint16(ipv.Mode)))
} else if macv, ok := link.(*Macvlan); ok {
if macv.Mode != MACVLAN_MODE_DEFAULT {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil)
nl.NewRtAttrChild(data, nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[macv.Mode]))
}
}
req.AddData(linkInfo)
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
if err != nil {
return err
}
ensureIndex(base)
// can't set master during create, so set it afterwards
if base.MasterIndex != 0 {
// TODO: verify MasterIndex is actually a bridge?
return LinkSetMasterByIndex(link, base.MasterIndex)
}
return nil
}
// LinkDel deletes link device. Either Index or Name must be set in
// the link object for it to be deleted. The other values are ignored.
// Equivalent to: `ip link del $link`
func LinkDel(link Link) error {
base := link.Attrs()
ensureIndex(base)
req := nl.NewNetlinkRequest(syscall.RTM_DELLINK, syscall.NLM_F_ACK)
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
msg.Index = int32(base.Index)
req.AddData(msg)
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
}
func linkByNameDump(name string) (Link, error) {
links, err := LinkList()
if err != nil {
return nil, err
}
for _, link := range links {
if link.Attrs().Name == name {
return link, nil
}
}
return nil, fmt.Errorf("Link %s not found", name)
}
// LinkByName finds a link by name and returns a pointer to the object.
func LinkByName(name string) (Link, error) {
if lookupByDump {
return linkByNameDump(name)
}
req := nl.NewNetlinkRequest(syscall.RTM_GETLINK, syscall.NLM_F_ACK)
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
req.AddData(msg)
nameData := nl.NewRtAttr(syscall.IFLA_IFNAME, nl.ZeroTerminated(name))
req.AddData(nameData)
link, err := execGetLink(req)
if err == syscall.EINVAL {
// older kernels don't support looking up via IFLA_IFNAME
// so fall back to dumping all links
lookupByDump = true
return linkByNameDump(name)
}
return link, err
}
// LinkByIndex finds a link by index and returns a pointer to the object.
func LinkByIndex(index int) (Link, error) {
req := nl.NewNetlinkRequest(syscall.RTM_GETLINK, syscall.NLM_F_ACK)
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
msg.Index = int32(index)
req.AddData(msg)
return execGetLink(req)
}
func execGetLink(req *nl.NetlinkRequest) (Link, error) {
msgs, err := req.Execute(syscall.NETLINK_ROUTE, 0)
if err != nil {
if errno, ok := err.(syscall.Errno); ok {
if errno == syscall.ENODEV {
return nil, fmt.Errorf("Link not found")
}
}
return nil, err
}
switch {
case len(msgs) == 0:
return nil, fmt.Errorf("Link not found")
case len(msgs) == 1:
return linkDeserialize(msgs[0])
default:
return nil, fmt.Errorf("More than one link found")
}
}
// linkDeserialize deserializes a raw message received from netlink into
// a link object.
func linkDeserialize(m []byte) (Link, error) {
msg := nl.DeserializeIfInfomsg(m)
attrs, err := nl.ParseRouteAttr(m[msg.Len():])
if err != nil {
return nil, err
}
base := LinkAttrs{Index: int(msg.Index), Flags: linkFlags(msg.Flags)}
var link Link
linkType := ""
for _, attr := range attrs {
switch attr.Attr.Type {
case syscall.IFLA_LINKINFO:
infos, err := nl.ParseRouteAttr(attr.Value)
if err != nil {
return nil, err
}
for _, info := range infos {
switch info.Attr.Type {
case nl.IFLA_INFO_KIND:
linkType = string(info.Value[:len(info.Value)-1])
switch linkType {
case "dummy":
link = &Dummy{}
case "bridge":
link = &Bridge{}
case "vlan":
link = &Vlan{}
case "veth":
link = &Veth{}
case "vxlan":
link = &Vxlan{}
case "ipvlan":
link = &IPVlan{}
case "macvlan":
link = &Macvlan{}
default:
link = &Generic{LinkType: linkType}
}
case nl.IFLA_INFO_DATA:
data, err := nl.ParseRouteAttr(info.Value)
if err != nil {
return nil, err
}
switch linkType {
case "vlan":
parseVlanData(link, data)
case "vxlan":
parseVxlanData(link, data)
case "ipvlan":
parseIPVlanData(link, data)
case "macvlan":
parseMacvlanData(link, data)
}
}
}
case syscall.IFLA_ADDRESS:
var nonzero bool
for _, b := range attr.Value {
if b != 0 {
nonzero = true
}
}
if nonzero {
base.HardwareAddr = attr.Value[:]
}
case syscall.IFLA_IFNAME:
base.Name = string(attr.Value[:len(attr.Value)-1])
case syscall.IFLA_MTU:
base.MTU = int(native.Uint32(attr.Value[0:4]))
case syscall.IFLA_LINK:
base.ParentIndex = int(native.Uint32(attr.Value[0:4]))
case syscall.IFLA_MASTER:
base.MasterIndex = int(native.Uint32(attr.Value[0:4]))
case syscall.IFLA_TXQLEN:
base.TxQLen = native.Uint32(attr.Value[0:4])
}
}
// Links that don't have IFLA_INFO_KIND are hardware devices
if link == nil {
link = &Device{}
}
*link.Attrs() = base
return link, nil
}
// LinkList gets a list of link devices.
// Equivalent to: `ip link show`
func LinkList() ([]Link, error) {
// NOTE(vish): This duplicates functionality in net/iface_linux.go, but we need
// to get the message ourselves to parse link type.
req := nl.NewNetlinkRequest(syscall.RTM_GETLINK, syscall.NLM_F_DUMP)
msg := nl.NewIfInfomsg(syscall.AF_UNSPEC)
req.AddData(msg)
msgs, err := req.Execute(syscall.NETLINK_ROUTE, syscall.RTM_NEWLINK)
if err != nil {
return nil, err
}
res := make([]Link, 0)
for _, m := range msgs {
link, err := linkDeserialize(m)
if err != nil {
return nil, err
}
res = append(res, link)
}
return res, nil
}
func LinkSetHairpin(link Link, mode bool) error {
return setProtinfoAttr(link, mode, nl.IFLA_BRPORT_MODE)
}
func LinkSetGuard(link Link, mode bool) error {
return setProtinfoAttr(link, mode, nl.IFLA_BRPORT_GUARD)
}
func LinkSetFastLeave(link Link, mode bool) error {
return setProtinfoAttr(link, mode, nl.IFLA_BRPORT_FAST_LEAVE)
}
func LinkSetLearning(link Link, mode bool) error {
return setProtinfoAttr(link, mode, nl.IFLA_BRPORT_LEARNING)
}
func LinkSetRootBlock(link Link, mode bool) error {
return setProtinfoAttr(link, mode, nl.IFLA_BRPORT_PROTECT)
}
func LinkSetFlood(link Link, mode bool) error {
return setProtinfoAttr(link, mode, nl.IFLA_BRPORT_UNICAST_FLOOD)
}
func setProtinfoAttr(link Link, mode bool, attr int) error {
base := link.Attrs()
ensureIndex(base)
req := nl.NewNetlinkRequest(syscall.RTM_SETLINK, syscall.NLM_F_ACK)
msg := nl.NewIfInfomsg(syscall.AF_BRIDGE)
msg.Type = syscall.RTM_SETLINK
msg.Flags = syscall.NLM_F_REQUEST
msg.Index = int32(base.Index)
msg.Change = nl.DEFAULT_CHANGE
req.AddData(msg)
br := nl.NewRtAttr(syscall.IFLA_PROTINFO|syscall.NLA_F_NESTED, nil)
nl.NewRtAttrChild(br, attr, boolToByte(mode))
req.AddData(br)
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
if err != nil {
return err
}
return nil
}
func parseVlanData(link Link, data []syscall.NetlinkRouteAttr) {
vlan := link.(*Vlan)
for _, datum := range data {
switch datum.Attr.Type {
case nl.IFLA_VLAN_ID:
vlan.VlanId = int(native.Uint16(datum.Value[0:2]))
}
}
}
func parseVxlanData(link Link, data []syscall.NetlinkRouteAttr) {
vxlan := link.(*Vxlan)
for _, datum := range data {
switch datum.Attr.Type {
case nl.IFLA_VXLAN_ID:
vxlan.VxlanId = int(native.Uint32(datum.Value[0:4]))
case nl.IFLA_VXLAN_LINK:
vxlan.VtepDevIndex = int(native.Uint32(datum.Value[0:4]))
case nl.IFLA_VXLAN_LOCAL:
vxlan.SrcAddr = net.IP(datum.Value[0:4])
case nl.IFLA_VXLAN_LOCAL6:
vxlan.SrcAddr = net.IP(datum.Value[0:16])
case nl.IFLA_VXLAN_GROUP:
vxlan.Group = net.IP(datum.Value[0:4])
case nl.IFLA_VXLAN_GROUP6:
vxlan.Group = net.IP(datum.Value[0:16])
case nl.IFLA_VXLAN_TTL:
vxlan.TTL = int(datum.Value[0])
case nl.IFLA_VXLAN_TOS:
vxlan.TOS = int(datum.Value[0])
case nl.IFLA_VXLAN_LEARNING:
vxlan.Learning = int8(datum.Value[0]) != 0
case nl.IFLA_VXLAN_PROXY:
vxlan.Proxy = int8(datum.Value[0]) != 0
case nl.IFLA_VXLAN_RSC:
vxlan.RSC = int8(datum.Value[0]) != 0
case nl.IFLA_VXLAN_L2MISS:
vxlan.L2miss = int8(datum.Value[0]) != 0
case nl.IFLA_VXLAN_L3MISS:
vxlan.L3miss = int8(datum.Value[0]) != 0
case nl.IFLA_VXLAN_AGEING:
vxlan.Age = int(native.Uint32(datum.Value[0:4]))
vxlan.NoAge = vxlan.Age == 0
case nl.IFLA_VXLAN_LIMIT:
vxlan.Limit = int(native.Uint32(datum.Value[0:4]))
case nl.IFLA_VXLAN_PORT:
vxlan.Port = int(native.Uint16(datum.Value[0:2]))
case nl.IFLA_VXLAN_PORT_RANGE:
buf := bytes.NewBuffer(datum.Value[0:4])
var pr vxlanPortRange
if binary.Read(buf, binary.BigEndian, &pr) != nil {
vxlan.PortLow = int(pr.Lo)
vxlan.PortHigh = int(pr.Hi)
}
}
}
}
func parseIPVlanData(link Link, data []syscall.NetlinkRouteAttr) {
ipv := link.(*IPVlan)
for _, datum := range data {
if datum.Attr.Type == nl.IFLA_IPVLAN_MODE {
ipv.Mode = IPVlanMode(native.Uint32(datum.Value[0:4]))
return
}
}
}
func parseMacvlanData(link Link, data []syscall.NetlinkRouteAttr) {
macv := link.(*Macvlan)
for _, datum := range data {
if datum.Attr.Type == nl.IFLA_MACVLAN_MODE {
switch native.Uint32(datum.Value[0:4]) {
case nl.MACVLAN_MODE_PRIVATE:
macv.Mode = MACVLAN_MODE_PRIVATE
case nl.MACVLAN_MODE_VEPA:
macv.Mode = MACVLAN_MODE_VEPA
case nl.MACVLAN_MODE_BRIDGE:
macv.Mode = MACVLAN_MODE_BRIDGE
case nl.MACVLAN_MODE_PASSTHRU:
macv.Mode = MACVLAN_MODE_PASSTHRU
case nl.MACVLAN_MODE_SOURCE:
macv.Mode = MACVLAN_MODE_SOURCE
}
return
}
}
}
// copied from pkg/net_linux.go
func linkFlags(rawFlags uint32) net.Flags {
var f net.Flags
if rawFlags&syscall.IFF_UP != 0 {
f |= net.FlagUp
}
if rawFlags&syscall.IFF_BROADCAST != 0 {
f |= net.FlagBroadcast
}
if rawFlags&syscall.IFF_LOOPBACK != 0 {
f |= net.FlagLoopback
}
if rawFlags&syscall.IFF_POINTOPOINT != 0 {
f |= net.FlagPointToPoint
}
if rawFlags&syscall.IFF_MULTICAST != 0 {
f |= net.FlagMulticast
}
return f
}

View File

@ -1,544 +0,0 @@
package netlink
import (
"bytes"
"net"
"testing"
"github.com/vishvananda/netns"
)
const testTxQLen uint32 = 100
func testLinkAddDel(t *testing.T, link Link) {
links, err := LinkList()
if err != nil {
t.Fatal(err)
}
num := len(links)
if err := LinkAdd(link); err != nil {
t.Fatal(err)
}
base := link.Attrs()
result, err := LinkByName(base.Name)
if err != nil {
t.Fatal(err)
}
rBase := result.Attrs()
if vlan, ok := link.(*Vlan); ok {
other, ok := result.(*Vlan)
if !ok {
t.Fatal("Result of create is not a vlan")
}
if vlan.VlanId != other.VlanId {
t.Fatal("Link.VlanId id doesn't match")
}
}
if rBase.ParentIndex == 0 && base.ParentIndex != 0 {
t.Fatal("Created link doesn't have a Parent but it should")
} else if rBase.ParentIndex != 0 && base.ParentIndex == 0 {
t.Fatal("Created link has a Parent but it shouldn't")
} else if rBase.ParentIndex != 0 && base.ParentIndex != 0 {
if rBase.ParentIndex != base.ParentIndex {
t.Fatal("Link.ParentIndex doesn't match")
}
}
if veth, ok := link.(*Veth); ok {
if veth.TxQLen != testTxQLen {
t.Fatalf("TxQLen is %d, should be %d", veth.TxQLen, testTxQLen)
}
if rBase.MTU != base.MTU {
t.Fatalf("MTU is %d, should be %d", rBase.MTU, base.MTU)
}
if veth.PeerName != "" {
var peer *Veth
other, err := LinkByName(veth.PeerName)
if err != nil {
t.Fatalf("Peer %s not created", veth.PeerName)
}
if peer, ok = other.(*Veth); !ok {
t.Fatalf("Peer %s is incorrect type", veth.PeerName)
}
if peer.TxQLen != testTxQLen {
t.Fatalf("TxQLen of peer is %d, should be %d", peer.TxQLen, testTxQLen)
}
}
}
if vxlan, ok := link.(*Vxlan); ok {
other, ok := result.(*Vxlan)
if !ok {
t.Fatal("Result of create is not a vxlan")
}
compareVxlan(t, vxlan, other)
}
if ipv, ok := link.(*IPVlan); ok {
other, ok := result.(*IPVlan)
if !ok {
t.Fatal("Result of create is not a ipvlan")
}
if ipv.Mode != other.Mode {
t.Fatalf("Got unexpected mode: %d, expected: %d", other.Mode, ipv.Mode)
}
}
if macv, ok := link.(*Macvlan); ok {
other, ok := result.(*Macvlan)
if !ok {
t.Fatal("Result of create is not a macvlan")
}
if macv.Mode != other.Mode {
t.Fatalf("Got unexpected mode: %d, expected: %d", other.Mode, macv.Mode)
}
}
if err = LinkDel(link); err != nil {
t.Fatal(err)
}
links, err = LinkList()
if err != nil {
t.Fatal(err)
}
if len(links) != num {
t.Fatal("Link not removed properly")
}
}
func compareVxlan(t *testing.T, expected, actual *Vxlan) {
if actual.VxlanId != expected.VxlanId {
t.Fatal("Vxlan.VxlanId doesn't match")
}
if expected.SrcAddr != nil && !actual.SrcAddr.Equal(expected.SrcAddr) {
t.Fatal("Vxlan.SrcAddr doesn't match")
}
if expected.Group != nil && !actual.Group.Equal(expected.Group) {
t.Fatal("Vxlan.Group doesn't match")
}
if expected.TTL != -1 && actual.TTL != expected.TTL {
t.Fatal("Vxlan.TTL doesn't match")
}
if expected.TOS != -1 && actual.TOS != expected.TOS {
t.Fatal("Vxlan.TOS doesn't match")
}
if actual.Learning != expected.Learning {
t.Fatal("Vxlan.Learning doesn't match")
}
if actual.Proxy != expected.Proxy {
t.Fatal("Vxlan.Proxy doesn't match")
}
if actual.RSC != expected.RSC {
t.Fatal("Vxlan.RSC doesn't match")
}
if actual.L2miss != expected.L2miss {
t.Fatal("Vxlan.L2miss doesn't match")
}
if actual.L3miss != expected.L3miss {
t.Fatal("Vxlan.L3miss doesn't match")
}
if expected.NoAge {
if !actual.NoAge {
t.Fatal("Vxlan.NoAge doesn't match")
}
} else if expected.Age > 0 && actual.Age != expected.Age {
t.Fatal("Vxlan.Age doesn't match")
}
if expected.Limit > 0 && actual.Limit != expected.Limit {
t.Fatal("Vxlan.Limit doesn't match")
}
if expected.Port > 0 && actual.Port != expected.Port {
t.Fatal("Vxlan.Port doesn't match")
}
if expected.PortLow > 0 || expected.PortHigh > 0 {
if actual.PortLow != expected.PortLow {
t.Fatal("Vxlan.PortLow doesn't match")
}
if actual.PortHigh != expected.PortHigh {
t.Fatal("Vxlan.PortHigh doesn't match")
}
}
}
func TestLinkAddDelDummy(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
testLinkAddDel(t, &Dummy{LinkAttrs{Name: "foo"}})
}
func TestLinkAddDelBridge(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
testLinkAddDel(t, &Bridge{LinkAttrs{Name: "foo", MTU: 1400}})
}
func TestLinkAddDelVlan(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
parent := &Dummy{LinkAttrs{Name: "foo"}}
if err := LinkAdd(parent); err != nil {
t.Fatal(err)
}
testLinkAddDel(t, &Vlan{LinkAttrs{Name: "bar", ParentIndex: parent.Attrs().Index}, 900})
if err := LinkDel(parent); err != nil {
t.Fatal(err)
}
}
func TestLinkAddDelMacvlan(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
parent := &Dummy{LinkAttrs{Name: "foo"}}
if err := LinkAdd(parent); err != nil {
t.Fatal(err)
}
testLinkAddDel(t, &Macvlan{
LinkAttrs: LinkAttrs{Name: "bar", ParentIndex: parent.Attrs().Index},
Mode: MACVLAN_MODE_PRIVATE,
})
if err := LinkDel(parent); err != nil {
t.Fatal(err)
}
}
func TestLinkAddDelVeth(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
testLinkAddDel(t, &Veth{LinkAttrs{Name: "foo", TxQLen: testTxQLen, MTU: 1400}, "bar"})
}
func TestLinkAddDelBridgeMaster(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
master := &Bridge{LinkAttrs{Name: "foo"}}
if err := LinkAdd(master); err != nil {
t.Fatal(err)
}
testLinkAddDel(t, &Dummy{LinkAttrs{Name: "bar", MasterIndex: master.Attrs().Index}})
if err := LinkDel(master); err != nil {
t.Fatal(err)
}
}
func TestLinkSetUnsetResetMaster(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
master := &Bridge{LinkAttrs{Name: "foo"}}
if err := LinkAdd(master); err != nil {
t.Fatal(err)
}
newmaster := &Bridge{LinkAttrs{Name: "bar"}}
if err := LinkAdd(newmaster); err != nil {
t.Fatal(err)
}
slave := &Dummy{LinkAttrs{Name: "baz"}}
if err := LinkAdd(slave); err != nil {
t.Fatal(err)
}
if err := LinkSetMaster(slave, master); err != nil {
t.Fatal(err)
}
link, err := LinkByName("baz")
if err != nil {
t.Fatal(err)
}
if link.Attrs().MasterIndex != master.Attrs().Index {
t.Fatal("Master not set properly")
}
if err := LinkSetMaster(slave, newmaster); err != nil {
t.Fatal(err)
}
link, err = LinkByName("baz")
if err != nil {
t.Fatal(err)
}
if link.Attrs().MasterIndex != newmaster.Attrs().Index {
t.Fatal("Master not reset properly")
}
if err := LinkSetMaster(slave, nil); err != nil {
t.Fatal(err)
}
link, err = LinkByName("baz")
if err != nil {
t.Fatal(err)
}
if link.Attrs().MasterIndex != 0 {
t.Fatal("Master not unset properly")
}
if err := LinkDel(slave); err != nil {
t.Fatal(err)
}
if err := LinkDel(newmaster); err != nil {
t.Fatal(err)
}
if err := LinkDel(master); err != nil {
t.Fatal(err)
}
}
func TestLinkSetNs(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
basens, err := netns.Get()
if err != nil {
t.Fatal("Failed to get basens")
}
defer basens.Close()
newns, err := netns.New()
if err != nil {
t.Fatal("Failed to create newns")
}
defer newns.Close()
link := &Veth{LinkAttrs{Name: "foo"}, "bar"}
if err := LinkAdd(link); err != nil {
t.Fatal(err)
}
peer, err := LinkByName("bar")
if err != nil {
t.Fatal(err)
}
LinkSetNsFd(peer, int(basens))
if err != nil {
t.Fatal("Failed to set newns for link")
}
_, err = LinkByName("bar")
if err == nil {
t.Fatal("Link bar is still in newns")
}
err = netns.Set(basens)
if err != nil {
t.Fatal("Failed to set basens")
}
peer, err = LinkByName("bar")
if err != nil {
t.Fatal("Link is not in basens")
}
if err := LinkDel(peer); err != nil {
t.Fatal(err)
}
err = netns.Set(newns)
if err != nil {
t.Fatal("Failed to set newns")
}
_, err = LinkByName("foo")
if err == nil {
t.Fatal("Other half of veth pair not deleted")
}
}
func TestLinkAddDelVxlan(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
parent := &Dummy{
LinkAttrs{Name: "foo"},
}
if err := LinkAdd(parent); err != nil {
t.Fatal(err)
}
vxlan := Vxlan{
LinkAttrs: LinkAttrs{
Name: "bar",
},
VxlanId: 10,
VtepDevIndex: parent.Index,
Learning: true,
L2miss: true,
L3miss: true,
}
testLinkAddDel(t, &vxlan)
if err := LinkDel(parent); err != nil {
t.Fatal(err)
}
}
func TestLinkAddDelIPVlanL2(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
parent := &Dummy{LinkAttrs{Name: "foo"}}
if err := LinkAdd(parent); err != nil {
t.Fatal(err)
}
ipv := IPVlan{
LinkAttrs: LinkAttrs{
Name: "bar",
ParentIndex: parent.Index,
},
Mode: IPVLAN_MODE_L2,
}
testLinkAddDel(t, &ipv)
}
func TestLinkAddDelIPVlanL3(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
parent := &Dummy{LinkAttrs{Name: "foo"}}
if err := LinkAdd(parent); err != nil {
t.Fatal(err)
}
ipv := IPVlan{
LinkAttrs: LinkAttrs{
Name: "bar",
ParentIndex: parent.Index,
},
Mode: IPVLAN_MODE_L3,
}
testLinkAddDel(t, &ipv)
}
func TestLinkAddDelIPVlanNoParent(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
ipv := IPVlan{
LinkAttrs: LinkAttrs{
Name: "bar",
},
Mode: IPVLAN_MODE_L3,
}
err := LinkAdd(&ipv)
if err == nil {
t.Fatal("Add should fail if ipvlan creating without ParentIndex")
}
if err.Error() != "Can't create ipvlan link without ParentIndex" {
t.Fatalf("Error should be about missing ParentIndex, got %q", err)
}
}
func TestLinkByIndex(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
dummy := &Dummy{LinkAttrs{Name: "dummy"}}
if err := LinkAdd(dummy); err != nil {
t.Fatal(err)
}
found, err := LinkByIndex(dummy.Index)
if err != nil {
t.Fatal(err)
}
if found.Attrs().Index != dummy.Attrs().Index {
t.Fatalf("Indices don't match: %v != %v", found.Attrs().Index, dummy.Attrs().Index)
}
LinkDel(dummy)
// test not found
_, err = LinkByIndex(dummy.Attrs().Index)
if err == nil {
t.Fatalf("LinkByIndex(%v) found deleted link", err)
}
}
func TestLinkSet(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
iface := &Dummy{LinkAttrs{Name: "foo"}}
if err := LinkAdd(iface); err != nil {
t.Fatal(err)
}
link, err := LinkByName("foo")
if err != nil {
t.Fatal(err)
}
err = LinkSetName(link, "bar")
if err != nil {
t.Fatalf("Could not change interface name: %v", err)
}
link, err = LinkByName("bar")
if err != nil {
t.Fatalf("Interface name not changed: %v", err)
}
err = LinkSetMTU(link, 1400)
if err != nil {
t.Fatalf("Could not set MTU: %v", err)
}
link, err = LinkByName("bar")
if err != nil {
t.Fatal(err)
}
if link.Attrs().MTU != 1400 {
t.Fatal("MTU not changed!")
}
addr, err := net.ParseMAC("00:12:34:56:78:AB")
if err != nil {
t.Fatal(err)
}
err = LinkSetHardwareAddr(link, addr)
if err != nil {
t.Fatal(err)
}
link, err = LinkByName("bar")
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(link.Attrs().HardwareAddr, addr) {
t.Fatalf("hardware address not changed!")
}
}

View File

@ -1,22 +0,0 @@
package netlink
import (
"fmt"
"net"
)
// Neigh represents a link layer neighbor from netlink.
type Neigh struct {
LinkIndex int
Family int
State int
Type int
Flags int
IP net.IP
HardwareAddr net.HardwareAddr
}
// String returns $ip/$hwaddr $label
func (neigh *Neigh) String() string {
return fmt.Sprintf("%s %s", neigh.IP, neigh.HardwareAddr)
}

View File

@ -1,189 +0,0 @@
package netlink
import (
"net"
"syscall"
"unsafe"
"github.com/vishvananda/netlink/nl"
)
const (
NDA_UNSPEC = iota
NDA_DST
NDA_LLADDR
NDA_CACHEINFO
NDA_PROBES
NDA_VLAN
NDA_PORT
NDA_VNI
NDA_IFINDEX
NDA_MAX = NDA_IFINDEX
)
// Neighbor Cache Entry States.
const (
NUD_NONE = 0x00
NUD_INCOMPLETE = 0x01
NUD_REACHABLE = 0x02
NUD_STALE = 0x04
NUD_DELAY = 0x08
NUD_PROBE = 0x10
NUD_FAILED = 0x20
NUD_NOARP = 0x40
NUD_PERMANENT = 0x80
)
// Neighbor Flags
const (
NTF_USE = 0x01
NTF_SELF = 0x02
NTF_MASTER = 0x04
NTF_PROXY = 0x08
NTF_ROUTER = 0x80
)
type Ndmsg struct {
Family uint8
Index uint32
State uint16
Flags uint8
Type uint8
}
func deserializeNdmsg(b []byte) *Ndmsg {
var dummy Ndmsg
return (*Ndmsg)(unsafe.Pointer(&b[0:unsafe.Sizeof(dummy)][0]))
}
func (msg *Ndmsg) Serialize() []byte {
return (*(*[unsafe.Sizeof(*msg)]byte)(unsafe.Pointer(msg)))[:]
}
func (msg *Ndmsg) Len() int {
return int(unsafe.Sizeof(*msg))
}
// NeighAdd will add an IP to MAC mapping to the ARP table
// Equivalent to: `ip neigh add ....`
func NeighAdd(neigh *Neigh) error {
return neighAdd(neigh, syscall.NLM_F_CREATE|syscall.NLM_F_EXCL)
}
// NeighAdd will add or replace an IP to MAC mapping to the ARP table
// Equivalent to: `ip neigh replace....`
func NeighSet(neigh *Neigh) error {
return neighAdd(neigh, syscall.NLM_F_CREATE)
}
// NeighAppend will append an entry to FDB
// Equivalent to: `bridge fdb append...`
func NeighAppend(neigh *Neigh) error {
return neighAdd(neigh, syscall.NLM_F_CREATE|syscall.NLM_F_APPEND)
}
func neighAdd(neigh *Neigh, mode int) error {
req := nl.NewNetlinkRequest(syscall.RTM_NEWNEIGH, mode|syscall.NLM_F_ACK)
return neighHandle(neigh, req)
}
// NeighDel will delete an IP address from a link device.
// Equivalent to: `ip addr del $addr dev $link`
func NeighDel(neigh *Neigh) error {
req := nl.NewNetlinkRequest(syscall.RTM_DELNEIGH, syscall.NLM_F_ACK)
return neighHandle(neigh, req)
}
func neighHandle(neigh *Neigh, req *nl.NetlinkRequest) error {
var family int
if neigh.Family > 0 {
family = neigh.Family
} else {
family = nl.GetIPFamily(neigh.IP)
}
msg := Ndmsg{
Family: uint8(family),
Index: uint32(neigh.LinkIndex),
State: uint16(neigh.State),
Type: uint8(neigh.Type),
Flags: uint8(neigh.Flags),
}
req.AddData(&msg)
ipData := neigh.IP.To4()
if ipData == nil {
ipData = neigh.IP.To16()
}
dstData := nl.NewRtAttr(NDA_DST, ipData)
req.AddData(dstData)
hwData := nl.NewRtAttr(NDA_LLADDR, []byte(neigh.HardwareAddr))
req.AddData(hwData)
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
}
// NeighList gets a list of IP-MAC mappings in the system (ARP table).
// Equivalent to: `ip neighbor show`.
// The list can be filtered by link and ip family.
func NeighList(linkIndex, family int) ([]Neigh, error) {
req := nl.NewNetlinkRequest(syscall.RTM_GETNEIGH, syscall.NLM_F_DUMP)
msg := Ndmsg{
Family: uint8(family),
}
req.AddData(&msg)
msgs, err := req.Execute(syscall.NETLINK_ROUTE, syscall.RTM_NEWNEIGH)
if err != nil {
return nil, err
}
res := make([]Neigh, 0)
for _, m := range msgs {
ndm := deserializeNdmsg(m)
if linkIndex != 0 && int(ndm.Index) != linkIndex {
// Ignore messages from other interfaces
continue
}
neigh, err := NeighDeserialize(m)
if err != nil {
continue
}
res = append(res, *neigh)
}
return res, nil
}
func NeighDeserialize(m []byte) (*Neigh, error) {
msg := deserializeNdmsg(m)
neigh := Neigh{
LinkIndex: int(msg.Index),
Family: int(msg.Family),
State: int(msg.State),
Type: int(msg.Type),
Flags: int(msg.Flags),
}
attrs, err := nl.ParseRouteAttr(m[msg.Len():])
if err != nil {
return nil, err
}
for _, attr := range attrs {
switch attr.Attr.Type {
case NDA_DST:
neigh.IP = net.IP(attr.Value)
case NDA_LLADDR:
neigh.HardwareAddr = net.HardwareAddr(attr.Value)
}
}
return &neigh, nil
}

View File

@ -1,104 +0,0 @@
package netlink
import (
"net"
"testing"
)
type arpEntry struct {
ip net.IP
mac net.HardwareAddr
}
func parseMAC(s string) net.HardwareAddr {
m, err := net.ParseMAC(s)
if err != nil {
panic(err)
}
return m
}
func dumpContains(dump []Neigh, e arpEntry) bool {
for _, n := range dump {
if n.IP.Equal(e.ip) && (n.State&NUD_INCOMPLETE) == 0 {
return true
}
}
return false
}
func TestNeighAddDel(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
dummy := Dummy{LinkAttrs{Name: "neigh0"}}
if err := LinkAdd(&dummy); err != nil {
t.Fatal(err)
}
ensureIndex(dummy.Attrs())
arpTable := []arpEntry{
{net.ParseIP("10.99.0.1"), parseMAC("aa:bb:cc:dd:00:01")},
{net.ParseIP("10.99.0.2"), parseMAC("aa:bb:cc:dd:00:02")},
{net.ParseIP("10.99.0.3"), parseMAC("aa:bb:cc:dd:00:03")},
{net.ParseIP("10.99.0.4"), parseMAC("aa:bb:cc:dd:00:04")},
{net.ParseIP("10.99.0.5"), parseMAC("aa:bb:cc:dd:00:05")},
}
// Add the arpTable
for _, entry := range arpTable {
err := NeighAdd(&Neigh{
LinkIndex: dummy.Index,
State: NUD_REACHABLE,
IP: entry.ip,
HardwareAddr: entry.mac,
})
if err != nil {
t.Errorf("Failed to NeighAdd: %v", err)
}
}
// Dump and see that all added entries are there
dump, err := NeighList(dummy.Index, 0)
if err != nil {
t.Errorf("Failed to NeighList: %v", err)
}
for _, entry := range arpTable {
if !dumpContains(dump, entry) {
t.Errorf("Dump does not contain: %v", entry)
}
}
// Delete the arpTable
for _, entry := range arpTable {
err := NeighDel(&Neigh{
LinkIndex: dummy.Index,
IP: entry.ip,
HardwareAddr: entry.mac,
})
if err != nil {
t.Errorf("Failed to NeighDel: %v", err)
}
}
// TODO: seems not working because of cache
//// Dump and see that none of deleted entries are there
//dump, err = NeighList(dummy.Index, 0)
//if err != nil {
//t.Errorf("Failed to NeighList: %v", err)
//}
//for _, entry := range arpTable {
//if dumpContains(dump, entry) {
//t.Errorf("Dump contains: %v", entry)
//}
//}
if err := LinkDel(&dummy); err != nil {
t.Fatal(err)
}
}

View File

@ -1,39 +0,0 @@
// Package netlink provides a simple library for netlink. Netlink is
// the interface a user-space program in linux uses to communicate with
// the kernel. It can be used to add and remove interfaces, set up ip
// addresses and routes, and confiugre ipsec. Netlink communication
// requires elevated privileges, so in most cases this code needs to
// be run as root. The low level primitives for netlink are contained
// in the nl subpackage. This package attempts to provide a high-level
// interface that is loosly modeled on the iproute2 cli.
package netlink
import (
"net"
"github.com/vishvananda/netlink/nl"
)
const (
// Family type definitions
FAMILY_ALL = nl.FAMILY_ALL
FAMILY_V4 = nl.FAMILY_V4
FAMILY_V6 = nl.FAMILY_V6
)
// ParseIPNet parses a string in ip/net format and returns a net.IPNet.
// This is valuable because addresses in netlink are often IPNets and
// ParseCIDR returns an IPNet with the IP part set to the base IP of the
// range.
func ParseIPNet(s string) (*net.IPNet, error) {
ip, ipNet, err := net.ParseCIDR(s)
if err != nil {
return nil, err
}
return &net.IPNet{IP: ip, Mask: ipNet.Mask}, nil
}
// NewIPNet generates an IPNet from an ip address using a netmask of 32.
func NewIPNet(ip net.IP) *net.IPNet {
return &net.IPNet{IP: ip, Mask: net.CIDRMask(32, 32)}
}

View File

@ -1,34 +0,0 @@
package netlink
import (
"log"
"os"
"runtime"
"testing"
"github.com/vishvananda/netns"
)
type tearDownNetlinkTest func()
func setUpNetlinkTest(t *testing.T) tearDownNetlinkTest {
if os.Getuid() != 0 {
msg := "Skipped test because it requires root privileges."
log.Printf(msg)
t.Skip(msg)
}
// new temporary namespace so we don't pollute the host
// lock thread since the namespace is thread local
runtime.LockOSThread()
var err error
ns, err := netns.New()
if err != nil {
t.Fatal("Failed to create newns", ns)
}
return func() {
ns.Close()
runtime.UnlockOSThread()
}
}

View File

@ -1,143 +0,0 @@
// +build !linux
package netlink
import (
"errors"
)
var (
ErrNotImplemented = errors.New("not implemented")
)
func LinkSetUp(link *Link) error {
return ErrNotImplemented
}
func LinkSetDown(link *Link) error {
return ErrNotImplemented
}
func LinkSetMTU(link *Link, mtu int) error {
return ErrNotImplemented
}
func LinkSetMaster(link *Link, master *Link) error {
return ErrNotImplemented
}
func LinkSetNsPid(link *Link, nspid int) error {
return ErrNotImplemented
}
func LinkSetNsFd(link *Link, fd int) error {
return ErrNotImplemented
}
func LinkAdd(link *Link) error {
return ErrNotImplemented
}
func LinkDel(link *Link) error {
return ErrNotImplemented
}
func SetHairpin(link Link, mode bool) error {
return ErrNotImplemented
}
func SetGuard(link Link, mode bool) error {
return ErrNotImplemented
}
func SetFastLeave(link Link, mode bool) error {
return ErrNotImplemented
}
func SetLearning(link Link, mode bool) error {
return ErrNotImplemented
}
func SetRootBlock(link Link, mode bool) error {
return ErrNotImplemented
}
func SetFlood(link Link, mode bool) error {
return ErrNotImplemented
}
func LinkList() ([]Link, error) {
return nil, ErrNotImplemented
}
func AddrAdd(link *Link, addr *Addr) error {
return ErrNotImplemented
}
func AddrDel(link *Link, addr *Addr) error {
return ErrNotImplemented
}
func AddrList(link *Link, family int) ([]Addr, error) {
return nil, ErrNotImplemented
}
func RouteAdd(route *Route) error {
return ErrNotImplemented
}
func RouteDel(route *Route) error {
return ErrNotImplemented
}
func RouteList(link *Link, family int) ([]Route, error) {
return nil, ErrNotImplemented
}
func XfrmPolicyAdd(policy *XfrmPolicy) error {
return ErrNotImplemented
}
func XfrmPolicyDel(policy *XfrmPolicy) error {
return ErrNotImplemented
}
func XfrmPolicyList(family int) ([]XfrmPolicy, error) {
return nil, ErrNotImplemented
}
func XfrmStateAdd(policy *XfrmState) error {
return ErrNotImplemented
}
func XfrmStateDel(policy *XfrmState) error {
return ErrNotImplemented
}
func XfrmStateList(family int) ([]XfrmState, error) {
return nil, ErrNotImplemented
}
func NeighAdd(neigh *Neigh) error {
return ErrNotImplemented
}
func NeighSet(neigh *Neigh) error {
return ErrNotImplemented
}
func NeighAppend(neigh *Neigh) error {
return ErrNotImplemented
}
func NeighDel(neigh *Neigh) error {
return ErrNotImplemented
}
func NeighList(linkIndex, family int) ([]Neigh, error) {
return nil, ErrNotImplemented
}
func NeighDeserialize(m []byte) (*Ndmsg, *Neigh, error) {
return nil, nil, ErrNotImplemented
}

View File

@ -1,47 +0,0 @@
package nl
import (
"syscall"
"unsafe"
)
type IfAddrmsg struct {
syscall.IfAddrmsg
}
func NewIfAddrmsg(family int) *IfAddrmsg {
return &IfAddrmsg{
IfAddrmsg: syscall.IfAddrmsg{
Family: uint8(family),
},
}
}
// struct ifaddrmsg {
// __u8 ifa_family;
// __u8 ifa_prefixlen; /* The prefix length */
// __u8 ifa_flags; /* Flags */
// __u8 ifa_scope; /* Address scope */
// __u32 ifa_index; /* Link index */
// };
// type IfAddrmsg struct {
// Family uint8
// Prefixlen uint8
// Flags uint8
// Scope uint8
// Index uint32
// }
// SizeofIfAddrmsg = 0x8
func DeserializeIfAddrmsg(b []byte) *IfAddrmsg {
return (*IfAddrmsg)(unsafe.Pointer(&b[0:syscall.SizeofIfAddrmsg][0]))
}
func (msg *IfAddrmsg) Serialize() []byte {
return (*(*[syscall.SizeofIfAddrmsg]byte)(unsafe.Pointer(msg)))[:]
}
func (msg *IfAddrmsg) Len() int {
return syscall.SizeofIfAddrmsg
}

View File

@ -1,39 +0,0 @@
package nl
import (
"bytes"
"crypto/rand"
"encoding/binary"
"syscall"
"testing"
)
func (msg *IfAddrmsg) write(b []byte) {
native := NativeEndian()
b[0] = msg.Family
b[1] = msg.Prefixlen
b[2] = msg.Flags
b[3] = msg.Scope
native.PutUint32(b[4:8], msg.Index)
}
func (msg *IfAddrmsg) serializeSafe() []byte {
len := syscall.SizeofIfAddrmsg
b := make([]byte, len)
msg.write(b)
return b
}
func deserializeIfAddrmsgSafe(b []byte) *IfAddrmsg {
var msg = IfAddrmsg{}
binary.Read(bytes.NewReader(b[0:syscall.SizeofIfAddrmsg]), NativeEndian(), &msg)
return &msg
}
func TestIfAddrmsgDeserializeSerialize(t *testing.T) {
var orig = make([]byte, syscall.SizeofIfAddrmsg)
rand.Read(orig)
safemsg := deserializeIfAddrmsgSafe(orig)
msg := DeserializeIfAddrmsg(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}

View File

@ -1,96 +0,0 @@
package nl
const (
DEFAULT_CHANGE = 0xFFFFFFFF
)
const (
IFLA_INFO_UNSPEC = iota
IFLA_INFO_KIND
IFLA_INFO_DATA
IFLA_INFO_XSTATS
IFLA_INFO_MAX = IFLA_INFO_XSTATS
)
const (
IFLA_VLAN_UNSPEC = iota
IFLA_VLAN_ID
IFLA_VLAN_FLAGS
IFLA_VLAN_EGRESS_QOS
IFLA_VLAN_INGRESS_QOS
IFLA_VLAN_PROTOCOL
IFLA_VLAN_MAX = IFLA_VLAN_PROTOCOL
)
const (
VETH_INFO_UNSPEC = iota
VETH_INFO_PEER
VETH_INFO_MAX = VETH_INFO_PEER
)
const (
IFLA_VXLAN_UNSPEC = iota
IFLA_VXLAN_ID
IFLA_VXLAN_GROUP
IFLA_VXLAN_LINK
IFLA_VXLAN_LOCAL
IFLA_VXLAN_TTL
IFLA_VXLAN_TOS
IFLA_VXLAN_LEARNING
IFLA_VXLAN_AGEING
IFLA_VXLAN_LIMIT
IFLA_VXLAN_PORT_RANGE
IFLA_VXLAN_PROXY
IFLA_VXLAN_RSC
IFLA_VXLAN_L2MISS
IFLA_VXLAN_L3MISS
IFLA_VXLAN_PORT
IFLA_VXLAN_GROUP6
IFLA_VXLAN_LOCAL6
IFLA_VXLAN_MAX = IFLA_VXLAN_LOCAL6
)
const (
BRIDGE_MODE_UNSPEC = iota
BRIDGE_MODE_HAIRPIN
)
const (
IFLA_BRPORT_UNSPEC = iota
IFLA_BRPORT_STATE
IFLA_BRPORT_PRIORITY
IFLA_BRPORT_COST
IFLA_BRPORT_MODE
IFLA_BRPORT_GUARD
IFLA_BRPORT_PROTECT
IFLA_BRPORT_FAST_LEAVE
IFLA_BRPORT_LEARNING
IFLA_BRPORT_UNICAST_FLOOD
IFLA_BRPORT_MAX = IFLA_BRPORT_UNICAST_FLOOD
)
const (
IFLA_IPVLAN_UNSPEC = iota
IFLA_IPVLAN_MODE
IFLA_IPVLAN_MAX = IFLA_IPVLAN_MODE
)
const (
// not defined in syscall
IFLA_NET_NS_FD = 28
)
const (
IFLA_MACVLAN_UNSPEC = iota
IFLA_MACVLAN_MODE
IFLA_MACVLAN_FLAGS
IFLA_MACVLAN_MAX = IFLA_MACVLAN_FLAGS
)
const (
MACVLAN_MODE_PRIVATE = 1
MACVLAN_MODE_VEPA = 2
MACVLAN_MODE_BRIDGE = 4
MACVLAN_MODE_PASSTHRU = 8
MACVLAN_MODE_SOURCE = 16
)

View File

@ -1,417 +0,0 @@
// Package nl has low level primitives for making Netlink calls.
package nl
import (
"bytes"
"encoding/binary"
"fmt"
"net"
"sync/atomic"
"syscall"
"unsafe"
)
const (
// Family type definitions
FAMILY_ALL = syscall.AF_UNSPEC
FAMILY_V4 = syscall.AF_INET
FAMILY_V6 = syscall.AF_INET6
)
var nextSeqNr uint32
// GetIPFamily returns the family type of a net.IP.
func GetIPFamily(ip net.IP) int {
if len(ip) <= net.IPv4len {
return FAMILY_V4
}
if ip.To4() != nil {
return FAMILY_V4
}
return FAMILY_V6
}
var nativeEndian binary.ByteOrder
// Get native endianness for the system
func NativeEndian() binary.ByteOrder {
if nativeEndian == nil {
var x uint32 = 0x01020304
if *(*byte)(unsafe.Pointer(&x)) == 0x01 {
nativeEndian = binary.BigEndian
}
nativeEndian = binary.LittleEndian
}
return nativeEndian
}
// Byte swap a 16 bit value if we aren't big endian
func Swap16(i uint16) uint16 {
if NativeEndian() == binary.BigEndian {
return i
}
return (i&0xff00)>>8 | (i&0xff)<<8
}
// Byte swap a 32 bit value if aren't big endian
func Swap32(i uint32) uint32 {
if NativeEndian() == binary.BigEndian {
return i
}
return (i&0xff000000)>>24 | (i&0xff0000)>>8 | (i&0xff00)<<8 | (i&0xff)<<24
}
type NetlinkRequestData interface {
Len() int
Serialize() []byte
}
// IfInfomsg is related to links, but it is used for list requests as well
type IfInfomsg struct {
syscall.IfInfomsg
}
// Create an IfInfomsg with family specified
func NewIfInfomsg(family int) *IfInfomsg {
return &IfInfomsg{
IfInfomsg: syscall.IfInfomsg{
Family: uint8(family),
},
}
}
func DeserializeIfInfomsg(b []byte) *IfInfomsg {
return (*IfInfomsg)(unsafe.Pointer(&b[0:syscall.SizeofIfInfomsg][0]))
}
func (msg *IfInfomsg) Serialize() []byte {
return (*(*[syscall.SizeofIfInfomsg]byte)(unsafe.Pointer(msg)))[:]
}
func (msg *IfInfomsg) Len() int {
return syscall.SizeofIfInfomsg
}
func rtaAlignOf(attrlen int) int {
return (attrlen + syscall.RTA_ALIGNTO - 1) & ^(syscall.RTA_ALIGNTO - 1)
}
func NewIfInfomsgChild(parent *RtAttr, family int) *IfInfomsg {
msg := NewIfInfomsg(family)
parent.children = append(parent.children, msg)
return msg
}
// Extend RtAttr to handle data and children
type RtAttr struct {
syscall.RtAttr
Data []byte
children []NetlinkRequestData
}
// Create a new Extended RtAttr object
func NewRtAttr(attrType int, data []byte) *RtAttr {
return &RtAttr{
RtAttr: syscall.RtAttr{
Type: uint16(attrType),
},
children: []NetlinkRequestData{},
Data: data,
}
}
// Create a new RtAttr obj anc add it as a child of an existing object
func NewRtAttrChild(parent *RtAttr, attrType int, data []byte) *RtAttr {
attr := NewRtAttr(attrType, data)
parent.children = append(parent.children, attr)
return attr
}
func (a *RtAttr) Len() int {
if len(a.children) == 0 {
return (syscall.SizeofRtAttr + len(a.Data))
}
l := 0
for _, child := range a.children {
l += rtaAlignOf(child.Len())
}
l += syscall.SizeofRtAttr
return rtaAlignOf(l + len(a.Data))
}
// Serialize the RtAttr into a byte array
// This can't ust unsafe.cast because it must iterate through children.
func (a *RtAttr) Serialize() []byte {
native := NativeEndian()
length := a.Len()
buf := make([]byte, rtaAlignOf(length))
if a.Data != nil {
copy(buf[4:], a.Data)
} else {
next := 4
for _, child := range a.children {
childBuf := child.Serialize()
copy(buf[next:], childBuf)
next += rtaAlignOf(len(childBuf))
}
}
if l := uint16(length); l != 0 {
native.PutUint16(buf[0:2], l)
}
native.PutUint16(buf[2:4], a.Type)
return buf
}
type NetlinkRequest struct {
syscall.NlMsghdr
Data []NetlinkRequestData
}
// Serialize the Netlink Request into a byte array
func (msg *NetlinkRequest) Serialize() []byte {
length := syscall.SizeofNlMsghdr
dataBytes := make([][]byte, len(msg.Data))
for i, data := range msg.Data {
dataBytes[i] = data.Serialize()
length = length + len(dataBytes[i])
}
msg.Len = uint32(length)
b := make([]byte, length)
hdr := (*(*[syscall.SizeofNlMsghdr]byte)(unsafe.Pointer(msg)))[:]
next := syscall.SizeofNlMsghdr
copy(b[0:next], hdr)
for _, data := range dataBytes {
for _, dataByte := range data {
b[next] = dataByte
next = next + 1
}
}
return b
}
func (msg *NetlinkRequest) AddData(data NetlinkRequestData) {
if data != nil {
msg.Data = append(msg.Data, data)
}
}
// Execute the request against a the given sockType.
// Returns a list of netlink messages in seriaized format, optionally filtered
// by resType.
func (req *NetlinkRequest) Execute(sockType int, resType uint16) ([][]byte, error) {
s, err := getNetlinkSocket(sockType)
if err != nil {
return nil, err
}
defer s.Close()
if err := s.Send(req); err != nil {
return nil, err
}
pid, err := s.GetPid()
if err != nil {
return nil, err
}
res := make([][]byte, 0)
done:
for {
msgs, err := s.Recieve()
if err != nil {
return nil, err
}
for _, m := range msgs {
if m.Header.Seq != req.Seq {
return nil, fmt.Errorf("Wrong Seq nr %d, expected 1", m.Header.Seq)
}
if m.Header.Pid != pid {
return nil, fmt.Errorf("Wrong pid %d, expected %d", m.Header.Pid, pid)
}
if m.Header.Type == syscall.NLMSG_DONE {
break done
}
if m.Header.Type == syscall.NLMSG_ERROR {
native := NativeEndian()
error := int32(native.Uint32(m.Data[0:4]))
if error == 0 {
break done
}
return nil, syscall.Errno(-error)
}
if resType != 0 && m.Header.Type != resType {
continue
}
res = append(res, m.Data)
if m.Header.Flags&syscall.NLM_F_MULTI == 0 {
break done
}
}
}
return res, nil
}
// Create a new netlink request from proto and flags
// Note the Len value will be inaccurate once data is added until
// the message is serialized
func NewNetlinkRequest(proto, flags int) *NetlinkRequest {
return &NetlinkRequest{
NlMsghdr: syscall.NlMsghdr{
Len: uint32(syscall.SizeofNlMsghdr),
Type: uint16(proto),
Flags: syscall.NLM_F_REQUEST | uint16(flags),
Seq: atomic.AddUint32(&nextSeqNr, 1),
},
}
}
type NetlinkSocket struct {
fd int
lsa syscall.SockaddrNetlink
}
func getNetlinkSocket(protocol int) (*NetlinkSocket, error) {
fd, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW, protocol)
if err != nil {
return nil, err
}
s := &NetlinkSocket{
fd: fd,
}
s.lsa.Family = syscall.AF_NETLINK
if err := syscall.Bind(fd, &s.lsa); err != nil {
syscall.Close(fd)
return nil, err
}
return s, nil
}
// Create a netlink socket with a given protocol (e.g. NETLINK_ROUTE)
// and subscribe it to multicast groups passed in variable argument list.
// Returns the netlink socket on whic hReceive() method can be called
// to retrieve the messages from the kernel.
func Subscribe(protocol int, groups ...uint) (*NetlinkSocket, error) {
fd, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW, protocol)
if err != nil {
return nil, err
}
s := &NetlinkSocket{
fd: fd,
}
s.lsa.Family = syscall.AF_NETLINK
for _, g := range groups {
s.lsa.Groups |= (1 << (g - 1))
}
if err := syscall.Bind(fd, &s.lsa); err != nil {
syscall.Close(fd)
return nil, err
}
return s, nil
}
func (s *NetlinkSocket) Close() {
syscall.Close(s.fd)
}
func (s *NetlinkSocket) Send(request *NetlinkRequest) error {
if err := syscall.Sendto(s.fd, request.Serialize(), 0, &s.lsa); err != nil {
return err
}
return nil
}
func (s *NetlinkSocket) Recieve() ([]syscall.NetlinkMessage, error) {
rb := make([]byte, syscall.Getpagesize())
nr, _, err := syscall.Recvfrom(s.fd, rb, 0)
if err != nil {
return nil, err
}
if nr < syscall.NLMSG_HDRLEN {
return nil, fmt.Errorf("Got short response from netlink")
}
rb = rb[:nr]
return syscall.ParseNetlinkMessage(rb)
}
func (s *NetlinkSocket) GetPid() (uint32, error) {
lsa, err := syscall.Getsockname(s.fd)
if err != nil {
return 0, err
}
switch v := lsa.(type) {
case *syscall.SockaddrNetlink:
return v.Pid, nil
}
return 0, fmt.Errorf("Wrong socket type")
}
func ZeroTerminated(s string) []byte {
bytes := make([]byte, len(s)+1)
for i := 0; i < len(s); i++ {
bytes[i] = s[i]
}
bytes[len(s)] = 0
return bytes
}
func NonZeroTerminated(s string) []byte {
bytes := make([]byte, len(s))
for i := 0; i < len(s); i++ {
bytes[i] = s[i]
}
return bytes
}
func BytesToString(b []byte) string {
n := bytes.Index(b, []byte{0})
return string(b[:n])
}
func Uint8Attr(v uint8) []byte {
return []byte{byte(v)}
}
func Uint16Attr(v uint16) []byte {
native := NativeEndian()
bytes := make([]byte, 2)
native.PutUint16(bytes, v)
return bytes
}
func Uint32Attr(v uint32) []byte {
native := NativeEndian()
bytes := make([]byte, 4)
native.PutUint32(bytes, v)
return bytes
}
func ParseRouteAttr(b []byte) ([]syscall.NetlinkRouteAttr, error) {
var attrs []syscall.NetlinkRouteAttr
for len(b) >= syscall.SizeofRtAttr {
a, vbuf, alen, err := netlinkRouteAttrAndValue(b)
if err != nil {
return nil, err
}
ra := syscall.NetlinkRouteAttr{Attr: *a, Value: vbuf[:int(a.Len)-syscall.SizeofRtAttr]}
attrs = append(attrs, ra)
b = b[alen:]
}
return attrs, nil
}
func netlinkRouteAttrAndValue(b []byte) (*syscall.RtAttr, []byte, int, error) {
a := (*syscall.RtAttr)(unsafe.Pointer(&b[0]))
if int(a.Len) < syscall.SizeofRtAttr || int(a.Len) > len(b) {
return nil, nil, 0, syscall.EINVAL
}
return a, b[syscall.SizeofRtAttr:], rtaAlignOf(int(a.Len)), nil
}

View File

@ -1,60 +0,0 @@
package nl
import (
"bytes"
"crypto/rand"
"encoding/binary"
"reflect"
"syscall"
"testing"
)
type testSerializer interface {
serializeSafe() []byte
Serialize() []byte
}
func testDeserializeSerialize(t *testing.T, orig []byte, safemsg testSerializer, msg testSerializer) {
if !reflect.DeepEqual(safemsg, msg) {
t.Fatal("Deserialization failed.\n", safemsg, "\n", msg)
}
safe := msg.serializeSafe()
if !bytes.Equal(safe, orig) {
t.Fatal("Safe serialization failed.\n", safe, "\n", orig)
}
b := msg.Serialize()
if !bytes.Equal(b, safe) {
t.Fatal("Serialization failed.\n", b, "\n", safe)
}
}
func (msg *IfInfomsg) write(b []byte) {
native := NativeEndian()
b[0] = msg.Family
b[1] = msg.X__ifi_pad
native.PutUint16(b[2:4], msg.Type)
native.PutUint32(b[4:8], uint32(msg.Index))
native.PutUint32(b[8:12], msg.Flags)
native.PutUint32(b[12:16], msg.Change)
}
func (msg *IfInfomsg) serializeSafe() []byte {
length := syscall.SizeofIfInfomsg
b := make([]byte, length)
msg.write(b)
return b
}
func deserializeIfInfomsgSafe(b []byte) *IfInfomsg {
var msg = IfInfomsg{}
binary.Read(bytes.NewReader(b[0:syscall.SizeofIfInfomsg]), NativeEndian(), &msg)
return &msg
}
func TestIfInfomsgDeserializeSerialize(t *testing.T) {
var orig = make([]byte, syscall.SizeofIfInfomsg)
rand.Read(orig)
safemsg := deserializeIfInfomsgSafe(orig)
msg := DeserializeIfInfomsg(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}

View File

@ -1,33 +0,0 @@
package nl
import (
"syscall"
"unsafe"
)
type RtMsg struct {
syscall.RtMsg
}
func NewRtMsg() *RtMsg {
return &RtMsg{
RtMsg: syscall.RtMsg{
Table: syscall.RT_TABLE_MAIN,
Scope: syscall.RT_SCOPE_UNIVERSE,
Protocol: syscall.RTPROT_BOOT,
Type: syscall.RTN_UNICAST,
},
}
}
func (msg *RtMsg) Len() int {
return syscall.SizeofRtMsg
}
func DeserializeRtMsg(b []byte) *RtMsg {
return (*RtMsg)(unsafe.Pointer(&b[0:syscall.SizeofRtMsg][0]))
}
func (msg *RtMsg) Serialize() []byte {
return (*(*[syscall.SizeofRtMsg]byte)(unsafe.Pointer(msg)))[:]
}

View File

@ -1,43 +0,0 @@
package nl
import (
"bytes"
"crypto/rand"
"encoding/binary"
"syscall"
"testing"
)
func (msg *RtMsg) write(b []byte) {
native := NativeEndian()
b[0] = msg.Family
b[1] = msg.Dst_len
b[2] = msg.Src_len
b[3] = msg.Tos
b[4] = msg.Table
b[5] = msg.Protocol
b[6] = msg.Scope
b[7] = msg.Type
native.PutUint32(b[8:12], msg.Flags)
}
func (msg *RtMsg) serializeSafe() []byte {
len := syscall.SizeofRtMsg
b := make([]byte, len)
msg.write(b)
return b
}
func deserializeRtMsgSafe(b []byte) *RtMsg {
var msg = RtMsg{}
binary.Read(bytes.NewReader(b[0:syscall.SizeofRtMsg]), NativeEndian(), &msg)
return &msg
}
func TestRtMsgDeserializeSerialize(t *testing.T) {
var orig = make([]byte, syscall.SizeofRtMsg)
rand.Read(orig)
safemsg := deserializeRtMsgSafe(orig)
msg := DeserializeRtMsg(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}

View File

@ -1,259 +0,0 @@
package nl
import (
"bytes"
"net"
"unsafe"
)
// Infinity for packet and byte counts
const (
XFRM_INF = ^uint64(0)
)
// Message Types
const (
XFRM_MSG_BASE = 0x10
XFRM_MSG_NEWSA = 0x10
XFRM_MSG_DELSA = 0x11
XFRM_MSG_GETSA = 0x12
XFRM_MSG_NEWPOLICY = 0x13
XFRM_MSG_DELPOLICY = 0x14
XFRM_MSG_GETPOLICY = 0x15
XFRM_MSG_ALLOCSPI = 0x16
XFRM_MSG_ACQUIRE = 0x17
XFRM_MSG_EXPIRE = 0x18
XFRM_MSG_UPDPOLICY = 0x19
XFRM_MSG_UPDSA = 0x1a
XFRM_MSG_POLEXPIRE = 0x1b
XFRM_MSG_FLUSHSA = 0x1c
XFRM_MSG_FLUSHPOLICY = 0x1d
XFRM_MSG_NEWAE = 0x1e
XFRM_MSG_GETAE = 0x1f
XFRM_MSG_REPORT = 0x20
XFRM_MSG_MIGRATE = 0x21
XFRM_MSG_NEWSADINFO = 0x22
XFRM_MSG_GETSADINFO = 0x23
XFRM_MSG_NEWSPDINFO = 0x24
XFRM_MSG_GETSPDINFO = 0x25
XFRM_MSG_MAPPING = 0x26
XFRM_MSG_MAX = 0x26
XFRM_NR_MSGTYPES = 0x17
)
// Attribute types
const (
/* Netlink message attributes. */
XFRMA_UNSPEC = 0x00
XFRMA_ALG_AUTH = 0x01 /* struct xfrm_algo */
XFRMA_ALG_CRYPT = 0x02 /* struct xfrm_algo */
XFRMA_ALG_COMP = 0x03 /* struct xfrm_algo */
XFRMA_ENCAP = 0x04 /* struct xfrm_algo + struct xfrm_encap_tmpl */
XFRMA_TMPL = 0x05 /* 1 or more struct xfrm_user_tmpl */
XFRMA_SA = 0x06 /* struct xfrm_usersa_info */
XFRMA_POLICY = 0x07 /* struct xfrm_userpolicy_info */
XFRMA_SEC_CTX = 0x08 /* struct xfrm_sec_ctx */
XFRMA_LTIME_VAL = 0x09
XFRMA_REPLAY_VAL = 0x0a
XFRMA_REPLAY_THRESH = 0x0b
XFRMA_ETIMER_THRESH = 0x0c
XFRMA_SRCADDR = 0x0d /* xfrm_address_t */
XFRMA_COADDR = 0x0e /* xfrm_address_t */
XFRMA_LASTUSED = 0x0f /* unsigned long */
XFRMA_POLICY_TYPE = 0x10 /* struct xfrm_userpolicy_type */
XFRMA_MIGRATE = 0x11
XFRMA_ALG_AEAD = 0x12 /* struct xfrm_algo_aead */
XFRMA_KMADDRESS = 0x13 /* struct xfrm_user_kmaddress */
XFRMA_ALG_AUTH_TRUNC = 0x14 /* struct xfrm_algo_auth */
XFRMA_MARK = 0x15 /* struct xfrm_mark */
XFRMA_TFCPAD = 0x16 /* __u32 */
XFRMA_REPLAY_ESN_VAL = 0x17 /* struct xfrm_replay_esn */
XFRMA_SA_EXTRA_FLAGS = 0x18 /* __u32 */
XFRMA_MAX = 0x18
)
const (
SizeofXfrmAddress = 0x10
SizeofXfrmSelector = 0x38
SizeofXfrmLifetimeCfg = 0x40
SizeofXfrmLifetimeCur = 0x20
SizeofXfrmId = 0x18
)
// typedef union {
// __be32 a4;
// __be32 a6[4];
// } xfrm_address_t;
type XfrmAddress [SizeofXfrmAddress]byte
func (x *XfrmAddress) ToIP() net.IP {
var empty = [12]byte{}
ip := make(net.IP, net.IPv6len)
if bytes.Equal(x[4:16], empty[:]) {
ip[10] = 0xff
ip[11] = 0xff
copy(ip[12:16], x[0:4])
} else {
copy(ip[:], x[:])
}
return ip
}
func (x *XfrmAddress) ToIPNet(prefixlen uint8) *net.IPNet {
ip := x.ToIP()
if GetIPFamily(ip) == FAMILY_V4 {
return &net.IPNet{IP: ip, Mask: net.CIDRMask(int(prefixlen), 32)}
} else {
return &net.IPNet{IP: ip, Mask: net.CIDRMask(int(prefixlen), 128)}
}
}
func (x *XfrmAddress) FromIP(ip net.IP) {
var empty = [16]byte{}
if len(ip) < net.IPv4len {
copy(x[4:16], empty[:])
} else if GetIPFamily(ip) == FAMILY_V4 {
copy(x[0:4], ip.To4()[0:4])
copy(x[4:16], empty[:12])
} else {
copy(x[0:16], ip.To16()[0:16])
}
}
func DeserializeXfrmAddress(b []byte) *XfrmAddress {
return (*XfrmAddress)(unsafe.Pointer(&b[0:SizeofXfrmAddress][0]))
}
func (msg *XfrmAddress) Serialize() []byte {
return (*(*[SizeofXfrmAddress]byte)(unsafe.Pointer(msg)))[:]
}
// struct xfrm_selector {
// xfrm_address_t daddr;
// xfrm_address_t saddr;
// __be16 dport;
// __be16 dport_mask;
// __be16 sport;
// __be16 sport_mask;
// __u16 family;
// __u8 prefixlen_d;
// __u8 prefixlen_s;
// __u8 proto;
// int ifindex;
// __kernel_uid32_t user;
// };
type XfrmSelector struct {
Daddr XfrmAddress
Saddr XfrmAddress
Dport uint16 // big endian
DportMask uint16 // big endian
Sport uint16 // big endian
SportMask uint16 // big endian
Family uint16
PrefixlenD uint8
PrefixlenS uint8
Proto uint8
Pad [3]byte
Ifindex int32
User uint32
}
func (msg *XfrmSelector) Len() int {
return SizeofXfrmSelector
}
func DeserializeXfrmSelector(b []byte) *XfrmSelector {
return (*XfrmSelector)(unsafe.Pointer(&b[0:SizeofXfrmSelector][0]))
}
func (msg *XfrmSelector) Serialize() []byte {
return (*(*[SizeofXfrmSelector]byte)(unsafe.Pointer(msg)))[:]
}
// struct xfrm_lifetime_cfg {
// __u64 soft_byte_limit;
// __u64 hard_byte_limit;
// __u64 soft_packet_limit;
// __u64 hard_packet_limit;
// __u64 soft_add_expires_seconds;
// __u64 hard_add_expires_seconds;
// __u64 soft_use_expires_seconds;
// __u64 hard_use_expires_seconds;
// };
//
type XfrmLifetimeCfg struct {
SoftByteLimit uint64
HardByteLimit uint64
SoftPacketLimit uint64
HardPacketLimit uint64
SoftAddExpiresSeconds uint64
HardAddExpiresSeconds uint64
SoftUseExpiresSeconds uint64
HardUseExpiresSeconds uint64
}
func (msg *XfrmLifetimeCfg) Len() int {
return SizeofXfrmLifetimeCfg
}
func DeserializeXfrmLifetimeCfg(b []byte) *XfrmLifetimeCfg {
return (*XfrmLifetimeCfg)(unsafe.Pointer(&b[0:SizeofXfrmLifetimeCfg][0]))
}
func (msg *XfrmLifetimeCfg) Serialize() []byte {
return (*(*[SizeofXfrmLifetimeCfg]byte)(unsafe.Pointer(msg)))[:]
}
// struct xfrm_lifetime_cur {
// __u64 bytes;
// __u64 packets;
// __u64 add_time;
// __u64 use_time;
// };
type XfrmLifetimeCur struct {
Bytes uint64
Packets uint64
AddTime uint64
UseTime uint64
}
func (msg *XfrmLifetimeCur) Len() int {
return SizeofXfrmLifetimeCur
}
func DeserializeXfrmLifetimeCur(b []byte) *XfrmLifetimeCur {
return (*XfrmLifetimeCur)(unsafe.Pointer(&b[0:SizeofXfrmLifetimeCur][0]))
}
func (msg *XfrmLifetimeCur) Serialize() []byte {
return (*(*[SizeofXfrmLifetimeCur]byte)(unsafe.Pointer(msg)))[:]
}
// struct xfrm_id {
// xfrm_address_t daddr;
// __be32 spi;
// __u8 proto;
// };
type XfrmId struct {
Daddr XfrmAddress
Spi uint32 // big endian
Proto uint8
Pad [3]byte
}
func (msg *XfrmId) Len() int {
return SizeofXfrmId
}
func DeserializeXfrmId(b []byte) *XfrmId {
return (*XfrmId)(unsafe.Pointer(&b[0:SizeofXfrmId][0]))
}
func (msg *XfrmId) Serialize() []byte {
return (*(*[SizeofXfrmId]byte)(unsafe.Pointer(msg)))[:]
}

View File

@ -1,161 +0,0 @@
package nl
import (
"bytes"
"crypto/rand"
"encoding/binary"
"testing"
)
func (msg *XfrmAddress) write(b []byte) {
copy(b[0:SizeofXfrmAddress], msg[:])
}
func (msg *XfrmAddress) serializeSafe() []byte {
b := make([]byte, SizeofXfrmAddress)
msg.write(b)
return b
}
func deserializeXfrmAddressSafe(b []byte) *XfrmAddress {
var msg = XfrmAddress{}
binary.Read(bytes.NewReader(b[0:SizeofXfrmAddress]), NativeEndian(), &msg)
return &msg
}
func TestXfrmAddressDeserializeSerialize(t *testing.T) {
var orig = make([]byte, SizeofXfrmAddress)
rand.Read(orig)
safemsg := deserializeXfrmAddressSafe(orig)
msg := DeserializeXfrmAddress(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}
func (msg *XfrmSelector) write(b []byte) {
const AddrEnd = SizeofXfrmAddress * 2
native := NativeEndian()
msg.Daddr.write(b[0:SizeofXfrmAddress])
msg.Saddr.write(b[SizeofXfrmAddress:AddrEnd])
native.PutUint16(b[AddrEnd:AddrEnd+2], msg.Dport)
native.PutUint16(b[AddrEnd+2:AddrEnd+4], msg.DportMask)
native.PutUint16(b[AddrEnd+4:AddrEnd+6], msg.Sport)
native.PutUint16(b[AddrEnd+6:AddrEnd+8], msg.SportMask)
native.PutUint16(b[AddrEnd+8:AddrEnd+10], msg.Family)
b[AddrEnd+10] = msg.PrefixlenD
b[AddrEnd+11] = msg.PrefixlenS
b[AddrEnd+12] = msg.Proto
copy(b[AddrEnd+13:AddrEnd+16], msg.Pad[:])
native.PutUint32(b[AddrEnd+16:AddrEnd+20], uint32(msg.Ifindex))
native.PutUint32(b[AddrEnd+20:AddrEnd+24], msg.User)
}
func (msg *XfrmSelector) serializeSafe() []byte {
length := SizeofXfrmSelector
b := make([]byte, length)
msg.write(b)
return b
}
func deserializeXfrmSelectorSafe(b []byte) *XfrmSelector {
var msg = XfrmSelector{}
binary.Read(bytes.NewReader(b[0:SizeofXfrmSelector]), NativeEndian(), &msg)
return &msg
}
func TestXfrmSelectorDeserializeSerialize(t *testing.T) {
var orig = make([]byte, SizeofXfrmSelector)
rand.Read(orig)
safemsg := deserializeXfrmSelectorSafe(orig)
msg := DeserializeXfrmSelector(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}
func (msg *XfrmLifetimeCfg) write(b []byte) {
native := NativeEndian()
native.PutUint64(b[0:8], msg.SoftByteLimit)
native.PutUint64(b[8:16], msg.HardByteLimit)
native.PutUint64(b[16:24], msg.SoftPacketLimit)
native.PutUint64(b[24:32], msg.HardPacketLimit)
native.PutUint64(b[32:40], msg.SoftAddExpiresSeconds)
native.PutUint64(b[40:48], msg.HardAddExpiresSeconds)
native.PutUint64(b[48:56], msg.SoftUseExpiresSeconds)
native.PutUint64(b[56:64], msg.HardUseExpiresSeconds)
}
func (msg *XfrmLifetimeCfg) serializeSafe() []byte {
length := SizeofXfrmLifetimeCfg
b := make([]byte, length)
msg.write(b)
return b
}
func deserializeXfrmLifetimeCfgSafe(b []byte) *XfrmLifetimeCfg {
var msg = XfrmLifetimeCfg{}
binary.Read(bytes.NewReader(b[0:SizeofXfrmLifetimeCfg]), NativeEndian(), &msg)
return &msg
}
func TestXfrmLifetimeCfgDeserializeSerialize(t *testing.T) {
var orig = make([]byte, SizeofXfrmLifetimeCfg)
rand.Read(orig)
safemsg := deserializeXfrmLifetimeCfgSafe(orig)
msg := DeserializeXfrmLifetimeCfg(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}
func (msg *XfrmLifetimeCur) write(b []byte) {
native := NativeEndian()
native.PutUint64(b[0:8], msg.Bytes)
native.PutUint64(b[8:16], msg.Packets)
native.PutUint64(b[16:24], msg.AddTime)
native.PutUint64(b[24:32], msg.UseTime)
}
func (msg *XfrmLifetimeCur) serializeSafe() []byte {
length := SizeofXfrmLifetimeCur
b := make([]byte, length)
msg.write(b)
return b
}
func deserializeXfrmLifetimeCurSafe(b []byte) *XfrmLifetimeCur {
var msg = XfrmLifetimeCur{}
binary.Read(bytes.NewReader(b[0:SizeofXfrmLifetimeCur]), NativeEndian(), &msg)
return &msg
}
func TestXfrmLifetimeCurDeserializeSerialize(t *testing.T) {
var orig = make([]byte, SizeofXfrmLifetimeCur)
rand.Read(orig)
safemsg := deserializeXfrmLifetimeCurSafe(orig)
msg := DeserializeXfrmLifetimeCur(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}
func (msg *XfrmId) write(b []byte) {
native := NativeEndian()
msg.Daddr.write(b[0:SizeofXfrmAddress])
native.PutUint32(b[SizeofXfrmAddress:SizeofXfrmAddress+4], msg.Spi)
b[SizeofXfrmAddress+4] = msg.Proto
copy(b[SizeofXfrmAddress+5:SizeofXfrmAddress+8], msg.Pad[:])
}
func (msg *XfrmId) serializeSafe() []byte {
b := make([]byte, SizeofXfrmId)
msg.write(b)
return b
}
func deserializeXfrmIdSafe(b []byte) *XfrmId {
var msg = XfrmId{}
binary.Read(bytes.NewReader(b[0:SizeofXfrmId]), NativeEndian(), &msg)
return &msg
}
func TestXfrmIdDeserializeSerialize(t *testing.T) {
var orig = make([]byte, SizeofXfrmId)
rand.Read(orig)
safemsg := deserializeXfrmIdSafe(orig)
msg := DeserializeXfrmId(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}

View File

@ -1,119 +0,0 @@
package nl
import (
"unsafe"
)
const (
SizeofXfrmUserpolicyId = 0x40
SizeofXfrmUserpolicyInfo = 0xa8
SizeofXfrmUserTmpl = 0x40
)
// struct xfrm_userpolicy_id {
// struct xfrm_selector sel;
// __u32 index;
// __u8 dir;
// };
//
type XfrmUserpolicyId struct {
Sel XfrmSelector
Index uint32
Dir uint8
Pad [3]byte
}
func (msg *XfrmUserpolicyId) Len() int {
return SizeofXfrmUserpolicyId
}
func DeserializeXfrmUserpolicyId(b []byte) *XfrmUserpolicyId {
return (*XfrmUserpolicyId)(unsafe.Pointer(&b[0:SizeofXfrmUserpolicyId][0]))
}
func (msg *XfrmUserpolicyId) Serialize() []byte {
return (*(*[SizeofXfrmUserpolicyId]byte)(unsafe.Pointer(msg)))[:]
}
// struct xfrm_userpolicy_info {
// struct xfrm_selector sel;
// struct xfrm_lifetime_cfg lft;
// struct xfrm_lifetime_cur curlft;
// __u32 priority;
// __u32 index;
// __u8 dir;
// __u8 action;
// #define XFRM_POLICY_ALLOW 0
// #define XFRM_POLICY_BLOCK 1
// __u8 flags;
// #define XFRM_POLICY_LOCALOK 1 /* Allow user to override global policy */
// /* Automatically expand selector to include matching ICMP payloads. */
// #define XFRM_POLICY_ICMP 2
// __u8 share;
// };
type XfrmUserpolicyInfo struct {
Sel XfrmSelector
Lft XfrmLifetimeCfg
Curlft XfrmLifetimeCur
Priority uint32
Index uint32
Dir uint8
Action uint8
Flags uint8
Share uint8
Pad [4]byte
}
func (msg *XfrmUserpolicyInfo) Len() int {
return SizeofXfrmUserpolicyInfo
}
func DeserializeXfrmUserpolicyInfo(b []byte) *XfrmUserpolicyInfo {
return (*XfrmUserpolicyInfo)(unsafe.Pointer(&b[0:SizeofXfrmUserpolicyInfo][0]))
}
func (msg *XfrmUserpolicyInfo) Serialize() []byte {
return (*(*[SizeofXfrmUserpolicyInfo]byte)(unsafe.Pointer(msg)))[:]
}
// struct xfrm_user_tmpl {
// struct xfrm_id id;
// __u16 family;
// xfrm_address_t saddr;
// __u32 reqid;
// __u8 mode;
// __u8 share;
// __u8 optional;
// __u32 aalgos;
// __u32 ealgos;
// __u32 calgos;
// }
type XfrmUserTmpl struct {
XfrmId XfrmId
Family uint16
Pad1 [2]byte
Saddr XfrmAddress
Reqid uint32
Mode uint8
Share uint8
Optional uint8
Pad2 byte
Aalgos uint32
Ealgos uint32
Calgos uint32
}
func (msg *XfrmUserTmpl) Len() int {
return SizeofXfrmUserTmpl
}
func DeserializeXfrmUserTmpl(b []byte) *XfrmUserTmpl {
return (*XfrmUserTmpl)(unsafe.Pointer(&b[0:SizeofXfrmUserTmpl][0]))
}
func (msg *XfrmUserTmpl) Serialize() []byte {
return (*(*[SizeofXfrmUserTmpl]byte)(unsafe.Pointer(msg)))[:]
}

View File

@ -1,109 +0,0 @@
package nl
import (
"bytes"
"crypto/rand"
"encoding/binary"
"testing"
)
func (msg *XfrmUserpolicyId) write(b []byte) {
native := NativeEndian()
msg.Sel.write(b[0:SizeofXfrmSelector])
native.PutUint32(b[SizeofXfrmSelector:SizeofXfrmSelector+4], msg.Index)
b[SizeofXfrmSelector+4] = msg.Dir
copy(b[SizeofXfrmSelector+5:SizeofXfrmSelector+8], msg.Pad[:])
}
func (msg *XfrmUserpolicyId) serializeSafe() []byte {
b := make([]byte, SizeofXfrmUserpolicyId)
msg.write(b)
return b
}
func deserializeXfrmUserpolicyIdSafe(b []byte) *XfrmUserpolicyId {
var msg = XfrmUserpolicyId{}
binary.Read(bytes.NewReader(b[0:SizeofXfrmUserpolicyId]), NativeEndian(), &msg)
return &msg
}
func TestXfrmUserpolicyIdDeserializeSerialize(t *testing.T) {
var orig = make([]byte, SizeofXfrmUserpolicyId)
rand.Read(orig)
safemsg := deserializeXfrmUserpolicyIdSafe(orig)
msg := DeserializeXfrmUserpolicyId(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}
func (msg *XfrmUserpolicyInfo) write(b []byte) {
const CfgEnd = SizeofXfrmSelector + SizeofXfrmLifetimeCfg
const CurEnd = CfgEnd + SizeofXfrmLifetimeCur
native := NativeEndian()
msg.Sel.write(b[0:SizeofXfrmSelector])
msg.Lft.write(b[SizeofXfrmSelector:CfgEnd])
msg.Curlft.write(b[CfgEnd:CurEnd])
native.PutUint32(b[CurEnd:CurEnd+4], msg.Priority)
native.PutUint32(b[CurEnd+4:CurEnd+8], msg.Index)
b[CurEnd+8] = msg.Dir
b[CurEnd+9] = msg.Action
b[CurEnd+10] = msg.Flags
b[CurEnd+11] = msg.Share
copy(b[CurEnd+12:CurEnd+16], msg.Pad[:])
}
func (msg *XfrmUserpolicyInfo) serializeSafe() []byte {
b := make([]byte, SizeofXfrmUserpolicyInfo)
msg.write(b)
return b
}
func deserializeXfrmUserpolicyInfoSafe(b []byte) *XfrmUserpolicyInfo {
var msg = XfrmUserpolicyInfo{}
binary.Read(bytes.NewReader(b[0:SizeofXfrmUserpolicyInfo]), NativeEndian(), &msg)
return &msg
}
func TestXfrmUserpolicyInfoDeserializeSerialize(t *testing.T) {
var orig = make([]byte, SizeofXfrmUserpolicyInfo)
rand.Read(orig)
safemsg := deserializeXfrmUserpolicyInfoSafe(orig)
msg := DeserializeXfrmUserpolicyInfo(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}
func (msg *XfrmUserTmpl) write(b []byte) {
const AddrEnd = SizeofXfrmId + 4 + SizeofXfrmAddress
native := NativeEndian()
msg.XfrmId.write(b[0:SizeofXfrmId])
native.PutUint16(b[SizeofXfrmId:SizeofXfrmId+2], msg.Family)
copy(b[SizeofXfrmId+2:SizeofXfrmId+4], msg.Pad1[:])
msg.Saddr.write(b[SizeofXfrmId+4 : AddrEnd])
native.PutUint32(b[AddrEnd:AddrEnd+4], msg.Reqid)
b[AddrEnd+4] = msg.Mode
b[AddrEnd+5] = msg.Share
b[AddrEnd+6] = msg.Optional
b[AddrEnd+7] = msg.Pad2
native.PutUint32(b[AddrEnd+8:AddrEnd+12], msg.Aalgos)
native.PutUint32(b[AddrEnd+12:AddrEnd+16], msg.Ealgos)
native.PutUint32(b[AddrEnd+16:AddrEnd+20], msg.Calgos)
}
func (msg *XfrmUserTmpl) serializeSafe() []byte {
b := make([]byte, SizeofXfrmUserTmpl)
msg.write(b)
return b
}
func deserializeXfrmUserTmplSafe(b []byte) *XfrmUserTmpl {
var msg = XfrmUserTmpl{}
binary.Read(bytes.NewReader(b[0:SizeofXfrmUserTmpl]), NativeEndian(), &msg)
return &msg
}
func TestXfrmUserTmplDeserializeSerialize(t *testing.T) {
var orig = make([]byte, SizeofXfrmUserTmpl)
rand.Read(orig)
safemsg := deserializeXfrmUserTmplSafe(orig)
msg := DeserializeXfrmUserTmpl(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}

View File

@ -1,221 +0,0 @@
package nl
import (
"unsafe"
)
const (
SizeofXfrmUsersaId = 0x18
SizeofXfrmStats = 0x0c
SizeofXfrmUsersaInfo = 0xe0
SizeofXfrmAlgo = 0x44
SizeofXfrmAlgoAuth = 0x48
SizeofXfrmEncapTmpl = 0x18
)
// struct xfrm_usersa_id {
// xfrm_address_t daddr;
// __be32 spi;
// __u16 family;
// __u8 proto;
// };
type XfrmUsersaId struct {
Daddr XfrmAddress
Spi uint32 // big endian
Family uint16
Proto uint8
Pad byte
}
func (msg *XfrmUsersaId) Len() int {
return SizeofXfrmUsersaId
}
func DeserializeXfrmUsersaId(b []byte) *XfrmUsersaId {
return (*XfrmUsersaId)(unsafe.Pointer(&b[0:SizeofXfrmUsersaId][0]))
}
func (msg *XfrmUsersaId) Serialize() []byte {
return (*(*[SizeofXfrmUsersaId]byte)(unsafe.Pointer(msg)))[:]
}
// struct xfrm_stats {
// __u32 replay_window;
// __u32 replay;
// __u32 integrity_failed;
// };
type XfrmStats struct {
ReplayWindow uint32
Replay uint32
IntegrityFailed uint32
}
func (msg *XfrmStats) Len() int {
return SizeofXfrmStats
}
func DeserializeXfrmStats(b []byte) *XfrmStats {
return (*XfrmStats)(unsafe.Pointer(&b[0:SizeofXfrmStats][0]))
}
func (msg *XfrmStats) Serialize() []byte {
return (*(*[SizeofXfrmStats]byte)(unsafe.Pointer(msg)))[:]
}
// struct xfrm_usersa_info {
// struct xfrm_selector sel;
// struct xfrm_id id;
// xfrm_address_t saddr;
// struct xfrm_lifetime_cfg lft;
// struct xfrm_lifetime_cur curlft;
// struct xfrm_stats stats;
// __u32 seq;
// __u32 reqid;
// __u16 family;
// __u8 mode; /* XFRM_MODE_xxx */
// __u8 replay_window;
// __u8 flags;
// #define XFRM_STATE_NOECN 1
// #define XFRM_STATE_DECAP_DSCP 2
// #define XFRM_STATE_NOPMTUDISC 4
// #define XFRM_STATE_WILDRECV 8
// #define XFRM_STATE_ICMP 16
// #define XFRM_STATE_AF_UNSPEC 32
// #define XFRM_STATE_ALIGN4 64
// #define XFRM_STATE_ESN 128
// };
//
// #define XFRM_SA_XFLAG_DONT_ENCAP_DSCP 1
//
type XfrmUsersaInfo struct {
Sel XfrmSelector
Id XfrmId
Saddr XfrmAddress
Lft XfrmLifetimeCfg
Curlft XfrmLifetimeCur
Stats XfrmStats
Seq uint32
Reqid uint32
Family uint16
Mode uint8
ReplayWindow uint8
Flags uint8
Pad [7]byte
}
func (msg *XfrmUsersaInfo) Len() int {
return SizeofXfrmUsersaInfo
}
func DeserializeXfrmUsersaInfo(b []byte) *XfrmUsersaInfo {
return (*XfrmUsersaInfo)(unsafe.Pointer(&b[0:SizeofXfrmUsersaInfo][0]))
}
func (msg *XfrmUsersaInfo) Serialize() []byte {
return (*(*[SizeofXfrmUsersaInfo]byte)(unsafe.Pointer(msg)))[:]
}
// struct xfrm_algo {
// char alg_name[64];
// unsigned int alg_key_len; /* in bits */
// char alg_key[0];
// };
type XfrmAlgo struct {
AlgName [64]byte
AlgKeyLen uint32
AlgKey []byte
}
func (msg *XfrmAlgo) Len() int {
return SizeofXfrmAlgo + int(msg.AlgKeyLen/8)
}
func DeserializeXfrmAlgo(b []byte) *XfrmAlgo {
ret := XfrmAlgo{}
copy(ret.AlgName[:], b[0:64])
ret.AlgKeyLen = *(*uint32)(unsafe.Pointer(&b[64]))
ret.AlgKey = b[68:ret.Len()]
return &ret
}
func (msg *XfrmAlgo) Serialize() []byte {
b := make([]byte, msg.Len())
copy(b[0:64], msg.AlgName[:])
copy(b[64:68], (*(*[4]byte)(unsafe.Pointer(&msg.AlgKeyLen)))[:])
copy(b[68:msg.Len()], msg.AlgKey[:])
return b
}
// struct xfrm_algo_auth {
// char alg_name[64];
// unsigned int alg_key_len; /* in bits */
// unsigned int alg_trunc_len; /* in bits */
// char alg_key[0];
// };
type XfrmAlgoAuth struct {
AlgName [64]byte
AlgKeyLen uint32
AlgTruncLen uint32
AlgKey []byte
}
func (msg *XfrmAlgoAuth) Len() int {
return SizeofXfrmAlgoAuth + int(msg.AlgKeyLen/8)
}
func DeserializeXfrmAlgoAuth(b []byte) *XfrmAlgoAuth {
ret := XfrmAlgoAuth{}
copy(ret.AlgName[:], b[0:64])
ret.AlgKeyLen = *(*uint32)(unsafe.Pointer(&b[64]))
ret.AlgTruncLen = *(*uint32)(unsafe.Pointer(&b[68]))
ret.AlgKey = b[72:ret.Len()]
return &ret
}
func (msg *XfrmAlgoAuth) Serialize() []byte {
b := make([]byte, msg.Len())
copy(b[0:64], msg.AlgName[:])
copy(b[64:68], (*(*[4]byte)(unsafe.Pointer(&msg.AlgKeyLen)))[:])
copy(b[68:72], (*(*[4]byte)(unsafe.Pointer(&msg.AlgTruncLen)))[:])
copy(b[72:msg.Len()], msg.AlgKey[:])
return b
}
// struct xfrm_algo_aead {
// char alg_name[64];
// unsigned int alg_key_len; /* in bits */
// unsigned int alg_icv_len; /* in bits */
// char alg_key[0];
// }
// struct xfrm_encap_tmpl {
// __u16 encap_type;
// __be16 encap_sport;
// __be16 encap_dport;
// xfrm_address_t encap_oa;
// };
type XfrmEncapTmpl struct {
EncapType uint16
EncapSport uint16 // big endian
EncapDport uint16 // big endian
Pad [2]byte
EncapOa XfrmAddress
}
func (msg *XfrmEncapTmpl) Len() int {
return SizeofXfrmEncapTmpl
}
func DeserializeXfrmEncapTmpl(b []byte) *XfrmEncapTmpl {
return (*XfrmEncapTmpl)(unsafe.Pointer(&b[0:SizeofXfrmEncapTmpl][0]))
}
func (msg *XfrmEncapTmpl) Serialize() []byte {
return (*(*[SizeofXfrmEncapTmpl]byte)(unsafe.Pointer(msg)))[:]
}

View File

@ -1,207 +0,0 @@
package nl
import (
"bytes"
"crypto/rand"
"encoding/binary"
"testing"
)
func (msg *XfrmUsersaId) write(b []byte) {
native := NativeEndian()
msg.Daddr.write(b[0:SizeofXfrmAddress])
native.PutUint32(b[SizeofXfrmAddress:SizeofXfrmAddress+4], msg.Spi)
native.PutUint16(b[SizeofXfrmAddress+4:SizeofXfrmAddress+6], msg.Family)
b[SizeofXfrmAddress+6] = msg.Proto
b[SizeofXfrmAddress+7] = msg.Pad
}
func (msg *XfrmUsersaId) serializeSafe() []byte {
b := make([]byte, SizeofXfrmUsersaId)
msg.write(b)
return b
}
func deserializeXfrmUsersaIdSafe(b []byte) *XfrmUsersaId {
var msg = XfrmUsersaId{}
binary.Read(bytes.NewReader(b[0:SizeofXfrmUsersaId]), NativeEndian(), &msg)
return &msg
}
func TestXfrmUsersaIdDeserializeSerialize(t *testing.T) {
var orig = make([]byte, SizeofXfrmUsersaId)
rand.Read(orig)
safemsg := deserializeXfrmUsersaIdSafe(orig)
msg := DeserializeXfrmUsersaId(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}
func (msg *XfrmStats) write(b []byte) {
native := NativeEndian()
native.PutUint32(b[0:4], msg.ReplayWindow)
native.PutUint32(b[4:8], msg.Replay)
native.PutUint32(b[8:12], msg.IntegrityFailed)
}
func (msg *XfrmStats) serializeSafe() []byte {
b := make([]byte, SizeofXfrmStats)
msg.write(b)
return b
}
func deserializeXfrmStatsSafe(b []byte) *XfrmStats {
var msg = XfrmStats{}
binary.Read(bytes.NewReader(b[0:SizeofXfrmStats]), NativeEndian(), &msg)
return &msg
}
func TestXfrmStatsDeserializeSerialize(t *testing.T) {
var orig = make([]byte, SizeofXfrmStats)
rand.Read(orig)
safemsg := deserializeXfrmStatsSafe(orig)
msg := DeserializeXfrmStats(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}
func (msg *XfrmUsersaInfo) write(b []byte) {
const IdEnd = SizeofXfrmSelector + SizeofXfrmId
const AddressEnd = IdEnd + SizeofXfrmAddress
const CfgEnd = AddressEnd + SizeofXfrmLifetimeCfg
const CurEnd = CfgEnd + SizeofXfrmLifetimeCur
const StatsEnd = CurEnd + SizeofXfrmStats
native := NativeEndian()
msg.Sel.write(b[0:SizeofXfrmSelector])
msg.Id.write(b[SizeofXfrmSelector:IdEnd])
msg.Saddr.write(b[IdEnd:AddressEnd])
msg.Lft.write(b[AddressEnd:CfgEnd])
msg.Curlft.write(b[CfgEnd:CurEnd])
msg.Stats.write(b[CurEnd:StatsEnd])
native.PutUint32(b[StatsEnd:StatsEnd+4], msg.Seq)
native.PutUint32(b[StatsEnd+4:StatsEnd+8], msg.Reqid)
native.PutUint16(b[StatsEnd+8:StatsEnd+10], msg.Family)
b[StatsEnd+10] = msg.Mode
b[StatsEnd+11] = msg.ReplayWindow
b[StatsEnd+12] = msg.Flags
copy(b[StatsEnd+13:StatsEnd+20], msg.Pad[:])
}
func (msg *XfrmUsersaInfo) serializeSafe() []byte {
b := make([]byte, SizeofXfrmUsersaInfo)
msg.write(b)
return b
}
func deserializeXfrmUsersaInfoSafe(b []byte) *XfrmUsersaInfo {
var msg = XfrmUsersaInfo{}
binary.Read(bytes.NewReader(b[0:SizeofXfrmUsersaInfo]), NativeEndian(), &msg)
return &msg
}
func TestXfrmUsersaInfoDeserializeSerialize(t *testing.T) {
var orig = make([]byte, SizeofXfrmUsersaInfo)
rand.Read(orig)
safemsg := deserializeXfrmUsersaInfoSafe(orig)
msg := DeserializeXfrmUsersaInfo(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}
func (msg *XfrmAlgo) write(b []byte) {
native := NativeEndian()
copy(b[0:64], msg.AlgName[:])
native.PutUint32(b[64:68], msg.AlgKeyLen)
copy(b[68:msg.Len()], msg.AlgKey[:])
}
func (msg *XfrmAlgo) serializeSafe() []byte {
b := make([]byte, msg.Len())
msg.write(b)
return b
}
func deserializeXfrmAlgoSafe(b []byte) *XfrmAlgo {
var msg = XfrmAlgo{}
copy(msg.AlgName[:], b[0:64])
binary.Read(bytes.NewReader(b[64:68]), NativeEndian(), &msg.AlgKeyLen)
msg.AlgKey = b[68:msg.Len()]
return &msg
}
func TestXfrmAlgoDeserializeSerialize(t *testing.T) {
// use a 32 byte key len
var orig = make([]byte, SizeofXfrmAlgo+32)
rand.Read(orig)
// set the key len to 256 bits
orig[64] = 0
orig[65] = 1
orig[66] = 0
orig[67] = 0
safemsg := deserializeXfrmAlgoSafe(orig)
msg := DeserializeXfrmAlgo(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}
func (msg *XfrmAlgoAuth) write(b []byte) {
native := NativeEndian()
copy(b[0:64], msg.AlgName[:])
native.PutUint32(b[64:68], msg.AlgKeyLen)
native.PutUint32(b[68:72], msg.AlgTruncLen)
copy(b[72:msg.Len()], msg.AlgKey[:])
}
func (msg *XfrmAlgoAuth) serializeSafe() []byte {
b := make([]byte, msg.Len())
msg.write(b)
return b
}
func deserializeXfrmAlgoAuthSafe(b []byte) *XfrmAlgoAuth {
var msg = XfrmAlgoAuth{}
copy(msg.AlgName[:], b[0:64])
binary.Read(bytes.NewReader(b[64:68]), NativeEndian(), &msg.AlgKeyLen)
binary.Read(bytes.NewReader(b[68:72]), NativeEndian(), &msg.AlgTruncLen)
msg.AlgKey = b[72:msg.Len()]
return &msg
}
func TestXfrmAlgoAuthDeserializeSerialize(t *testing.T) {
// use a 32 byte key len
var orig = make([]byte, SizeofXfrmAlgoAuth+32)
rand.Read(orig)
// set the key len to 256 bits
orig[64] = 0
orig[65] = 1
orig[66] = 0
orig[67] = 0
safemsg := deserializeXfrmAlgoAuthSafe(orig)
msg := DeserializeXfrmAlgoAuth(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}
func (msg *XfrmEncapTmpl) write(b []byte) {
native := NativeEndian()
native.PutUint16(b[0:2], msg.EncapType)
native.PutUint16(b[2:4], msg.EncapSport)
native.PutUint16(b[4:6], msg.EncapDport)
copy(b[6:8], msg.Pad[:])
msg.EncapOa.write(b[8:SizeofXfrmAddress])
}
func (msg *XfrmEncapTmpl) serializeSafe() []byte {
b := make([]byte, SizeofXfrmEncapTmpl)
msg.write(b)
return b
}
func deserializeXfrmEncapTmplSafe(b []byte) *XfrmEncapTmpl {
var msg = XfrmEncapTmpl{}
binary.Read(bytes.NewReader(b[0:SizeofXfrmEncapTmpl]), NativeEndian(), &msg)
return &msg
}
func TestXfrmEncapTmplDeserializeSerialize(t *testing.T) {
var orig = make([]byte, SizeofXfrmEncapTmpl)
rand.Read(orig)
safemsg := deserializeXfrmEncapTmplSafe(orig)
msg := DeserializeXfrmEncapTmpl(orig)
testDeserializeSerialize(t, orig, safemsg, msg)
}

View File

@ -1,53 +0,0 @@
package netlink
import (
"strings"
)
// Protinfo represents bridge flags from netlink.
type Protinfo struct {
Hairpin bool
Guard bool
FastLeave bool
RootBlock bool
Learning bool
Flood bool
}
// String returns a list of enabled flags
func (prot *Protinfo) String() string {
boolStrings := make([]string, 0)
if prot.Hairpin {
boolStrings = append(boolStrings, "Hairpin")
}
if prot.Guard {
boolStrings = append(boolStrings, "Guard")
}
if prot.FastLeave {
boolStrings = append(boolStrings, "FastLeave")
}
if prot.RootBlock {
boolStrings = append(boolStrings, "RootBlock")
}
if prot.Learning {
boolStrings = append(boolStrings, "Learning")
}
if prot.Flood {
boolStrings = append(boolStrings, "Flood")
}
return strings.Join(boolStrings, " ")
}
func boolToByte(x bool) []byte {
if x {
return []byte{1}
}
return []byte{0}
}
func byteToBool(x byte) bool {
if uint8(x) != 0 {
return true
}
return false
}

View File

@ -1,60 +0,0 @@
package netlink
import (
"fmt"
"syscall"
"github.com/vishvananda/netlink/nl"
)
func LinkGetProtinfo(link Link) (Protinfo, error) {
base := link.Attrs()
ensureIndex(base)
var pi Protinfo
req := nl.NewNetlinkRequest(syscall.RTM_GETLINK, syscall.NLM_F_DUMP)
msg := nl.NewIfInfomsg(syscall.AF_BRIDGE)
req.AddData(msg)
msgs, err := req.Execute(syscall.NETLINK_ROUTE, 0)
if err != nil {
return pi, err
}
for _, m := range msgs {
ans := nl.DeserializeIfInfomsg(m)
if int(ans.Index) != base.Index {
continue
}
attrs, err := nl.ParseRouteAttr(m[ans.Len():])
if err != nil {
return pi, err
}
for _, attr := range attrs {
if attr.Attr.Type != syscall.IFLA_PROTINFO|syscall.NLA_F_NESTED {
continue
}
infos, err := nl.ParseRouteAttr(attr.Value)
if err != nil {
return pi, err
}
var pi Protinfo
for _, info := range infos {
switch info.Attr.Type {
case nl.IFLA_BRPORT_MODE:
pi.Hairpin = byteToBool(info.Value[0])
case nl.IFLA_BRPORT_GUARD:
pi.Guard = byteToBool(info.Value[0])
case nl.IFLA_BRPORT_FAST_LEAVE:
pi.FastLeave = byteToBool(info.Value[0])
case nl.IFLA_BRPORT_PROTECT:
pi.RootBlock = byteToBool(info.Value[0])
case nl.IFLA_BRPORT_LEARNING:
pi.Learning = byteToBool(info.Value[0])
case nl.IFLA_BRPORT_UNICAST_FLOOD:
pi.Flood = byteToBool(info.Value[0])
}
}
return pi, nil
}
}
return pi, fmt.Errorf("Device with index %d not found", base.Index)
}

View File

@ -1,98 +0,0 @@
package netlink
import "testing"
func TestProtinfo(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
master := &Bridge{LinkAttrs{Name: "foo"}}
if err := LinkAdd(master); err != nil {
t.Fatal(err)
}
iface1 := &Dummy{LinkAttrs{Name: "bar1", MasterIndex: master.Index}}
iface2 := &Dummy{LinkAttrs{Name: "bar2", MasterIndex: master.Index}}
iface3 := &Dummy{LinkAttrs{Name: "bar3"}}
if err := LinkAdd(iface1); err != nil {
t.Fatal(err)
}
if err := LinkAdd(iface2); err != nil {
t.Fatal(err)
}
if err := LinkAdd(iface3); err != nil {
t.Fatal(err)
}
oldpi1, err := LinkGetProtinfo(iface1)
if err != nil {
t.Fatal(err)
}
oldpi2, err := LinkGetProtinfo(iface2)
if err != nil {
t.Fatal(err)
}
if err := LinkSetHairpin(iface1, true); err != nil {
t.Fatal(err)
}
if err := LinkSetRootBlock(iface1, true); err != nil {
t.Fatal(err)
}
pi1, err := LinkGetProtinfo(iface1)
if err != nil {
t.Fatal(err)
}
if !pi1.Hairpin {
t.Fatalf("Hairpin mode is not enabled for %s, but should", iface1.Name)
}
if !pi1.RootBlock {
t.Fatalf("RootBlock is not enabled for %s, but should", iface1.Name)
}
if pi1.Guard != oldpi1.Guard {
t.Fatalf("Guard field was changed for %s but shouldn't", iface1.Name)
}
if pi1.FastLeave != oldpi1.FastLeave {
t.Fatalf("FastLeave field was changed for %s but shouldn't", iface1.Name)
}
if pi1.Learning != oldpi1.Learning {
t.Fatalf("Learning field was changed for %s but shouldn't", iface1.Name)
}
if pi1.Flood != oldpi1.Flood {
t.Fatalf("Flood field was changed for %s but shouldn't", iface1.Name)
}
if err := LinkSetGuard(iface2, true); err != nil {
t.Fatal(err)
}
if err := LinkSetLearning(iface2, false); err != nil {
t.Fatal(err)
}
pi2, err := LinkGetProtinfo(iface2)
if err != nil {
t.Fatal(err)
}
if pi2.Hairpin {
t.Fatalf("Hairpin mode is enabled for %s, but shouldn't", iface2.Name)
}
if !pi2.Guard {
t.Fatalf("Guard is not enabled for %s, but should", iface2.Name)
}
if pi2.Learning {
t.Fatalf("Learning is enabled for %s, but shouldn't", iface2.Name)
}
if pi2.RootBlock != oldpi2.RootBlock {
t.Fatalf("RootBlock field was changed for %s but shouldn't", iface2.Name)
}
if pi2.FastLeave != oldpi2.FastLeave {
t.Fatalf("FastLeave field was changed for %s but shouldn't", iface2.Name)
}
if pi2.Flood != oldpi2.Flood {
t.Fatalf("Flood field was changed for %s but shouldn't", iface2.Name)
}
if err := LinkSetHairpin(iface3, true); err == nil || err.Error() != "operation not supported" {
t.Fatalf("Set protinfo attrs for link without master is not supported, but err: %s", err)
}
}

View File

@ -1,35 +0,0 @@
package netlink
import (
"fmt"
"net"
"syscall"
)
// Scope is an enum representing a route scope.
type Scope uint8
const (
SCOPE_UNIVERSE Scope = syscall.RT_SCOPE_UNIVERSE
SCOPE_SITE Scope = syscall.RT_SCOPE_SITE
SCOPE_LINK Scope = syscall.RT_SCOPE_LINK
SCOPE_HOST Scope = syscall.RT_SCOPE_HOST
SCOPE_NOWHERE Scope = syscall.RT_SCOPE_NOWHERE
)
// Route represents a netlink route. A route is associated with a link,
// has a destination network, an optional source ip, and optional
// gateway. Advanced route parameters and non-main routing tables are
// currently not supported.
type Route struct {
LinkIndex int
Scope Scope
Dst *net.IPNet
Src net.IP
Gw net.IP
}
func (r Route) String() string {
return fmt.Sprintf("{Ifindex: %d Dst: %s Src: %s Gw: %s}", r.LinkIndex, r.Dst,
r.Src, r.Gw)
}

View File

@ -1,225 +0,0 @@
package netlink
import (
"fmt"
"net"
"syscall"
"github.com/vishvananda/netlink/nl"
)
// RtAttr is shared so it is in netlink_linux.go
// RouteAdd will add a route to the system.
// Equivalent to: `ip route add $route`
func RouteAdd(route *Route) error {
req := nl.NewNetlinkRequest(syscall.RTM_NEWROUTE, syscall.NLM_F_CREATE|syscall.NLM_F_EXCL|syscall.NLM_F_ACK)
return routeHandle(route, req)
}
// RouteAdd will delete a route from the system.
// Equivalent to: `ip route del $route`
func RouteDel(route *Route) error {
req := nl.NewNetlinkRequest(syscall.RTM_DELROUTE, syscall.NLM_F_ACK)
return routeHandle(route, req)
}
func routeHandle(route *Route, req *nl.NetlinkRequest) error {
if (route.Dst == nil || route.Dst.IP == nil) && route.Src == nil && route.Gw == nil {
return fmt.Errorf("one of Dst.IP, Src, or Gw must not be nil")
}
msg := nl.NewRtMsg()
msg.Scope = uint8(route.Scope)
family := -1
var rtAttrs []*nl.RtAttr
if route.Dst != nil && route.Dst.IP != nil {
dstLen, _ := route.Dst.Mask.Size()
msg.Dst_len = uint8(dstLen)
dstFamily := nl.GetIPFamily(route.Dst.IP)
family = dstFamily
var dstData []byte
if dstFamily == FAMILY_V4 {
dstData = route.Dst.IP.To4()
} else {
dstData = route.Dst.IP.To16()
}
rtAttrs = append(rtAttrs, nl.NewRtAttr(syscall.RTA_DST, dstData))
}
if route.Src != nil {
srcFamily := nl.GetIPFamily(route.Src)
if family != -1 && family != srcFamily {
return fmt.Errorf("source and destination ip are not the same IP family")
}
family = srcFamily
var srcData []byte
if srcFamily == FAMILY_V4 {
srcData = route.Src.To4()
} else {
srcData = route.Src.To16()
}
// The commonly used src ip for routes is actually PREFSRC
rtAttrs = append(rtAttrs, nl.NewRtAttr(syscall.RTA_PREFSRC, srcData))
}
if route.Gw != nil {
gwFamily := nl.GetIPFamily(route.Gw)
if family != -1 && family != gwFamily {
return fmt.Errorf("gateway, source, and destination ip are not the same IP family")
}
family = gwFamily
var gwData []byte
if gwFamily == FAMILY_V4 {
gwData = route.Gw.To4()
} else {
gwData = route.Gw.To16()
}
rtAttrs = append(rtAttrs, nl.NewRtAttr(syscall.RTA_GATEWAY, gwData))
}
msg.Family = uint8(family)
req.AddData(msg)
for _, attr := range rtAttrs {
req.AddData(attr)
}
var (
b = make([]byte, 4)
native = nl.NativeEndian()
)
native.PutUint32(b, uint32(route.LinkIndex))
req.AddData(nl.NewRtAttr(syscall.RTA_OIF, b))
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
}
// RouteList gets a list of routes in the system.
// Equivalent to: `ip route show`.
// The list can be filtered by link and ip family.
func RouteList(link Link, family int) ([]Route, error) {
req := nl.NewNetlinkRequest(syscall.RTM_GETROUTE, syscall.NLM_F_DUMP)
msg := nl.NewIfInfomsg(family)
req.AddData(msg)
msgs, err := req.Execute(syscall.NETLINK_ROUTE, syscall.RTM_NEWROUTE)
if err != nil {
return nil, err
}
index := 0
if link != nil {
base := link.Attrs()
ensureIndex(base)
index = base.Index
}
native := nl.NativeEndian()
res := make([]Route, 0)
for _, m := range msgs {
msg := nl.DeserializeRtMsg(m)
if msg.Flags&syscall.RTM_F_CLONED != 0 {
// Ignore cloned routes
continue
}
if msg.Table != syscall.RT_TABLE_MAIN {
// Ignore non-main tables
continue
}
attrs, err := nl.ParseRouteAttr(m[msg.Len():])
if err != nil {
return nil, err
}
route := Route{Scope: Scope(msg.Scope)}
for _, attr := range attrs {
switch attr.Attr.Type {
case syscall.RTA_GATEWAY:
route.Gw = net.IP(attr.Value)
case syscall.RTA_PREFSRC:
route.Src = net.IP(attr.Value)
case syscall.RTA_DST:
route.Dst = &net.IPNet{
IP: attr.Value,
Mask: net.CIDRMask(int(msg.Dst_len), 8*len(attr.Value)),
}
case syscall.RTA_OIF:
routeIndex := int(native.Uint32(attr.Value[0:4]))
if link != nil && routeIndex != index {
// Ignore routes from other interfaces
continue
}
route.LinkIndex = routeIndex
}
}
res = append(res, route)
}
return res, nil
}
// RouteGet gets a route to a specific destination from the host system.
// Equivalent to: 'ip route get'.
func RouteGet(destination net.IP) ([]Route, error) {
req := nl.NewNetlinkRequest(syscall.RTM_GETROUTE, syscall.NLM_F_REQUEST)
family := nl.GetIPFamily(destination)
var destinationData []byte
var bitlen uint8
if family == FAMILY_V4 {
destinationData = destination.To4()
bitlen = 32
} else {
destinationData = destination.To16()
bitlen = 128
}
msg := &nl.RtMsg{}
msg.Family = uint8(family)
msg.Dst_len = bitlen
req.AddData(msg)
rtaDst := nl.NewRtAttr(syscall.RTA_DST, destinationData)
req.AddData(rtaDst)
msgs, err := req.Execute(syscall.NETLINK_ROUTE, syscall.RTM_NEWROUTE)
if err != nil {
return nil, err
}
native := nl.NativeEndian()
res := make([]Route, 0)
for _, m := range msgs {
msg := nl.DeserializeRtMsg(m)
attrs, err := nl.ParseRouteAttr(m[msg.Len():])
if err != nil {
return nil, err
}
route := Route{}
for _, attr := range attrs {
switch attr.Attr.Type {
case syscall.RTA_GATEWAY:
route.Gw = net.IP(attr.Value)
case syscall.RTA_PREFSRC:
route.Src = net.IP(attr.Value)
case syscall.RTA_DST:
route.Dst = &net.IPNet{
IP: attr.Value,
Mask: net.CIDRMask(int(msg.Dst_len), 8*len(attr.Value)),
}
case syscall.RTA_OIF:
routeIndex := int(native.Uint32(attr.Value[0:4]))
route.LinkIndex = routeIndex
}
}
res = append(res, route)
}
return res, nil
}

View File

@ -1,84 +0,0 @@
package netlink
import (
"net"
"testing"
)
func TestRouteAddDel(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
// get loopback interface
link, err := LinkByName("lo")
if err != nil {
t.Fatal(err)
}
// bring the interface up
if err = LinkSetUp(link); err != nil {
t.Fatal(err)
}
// add a gateway route
_, dst, err := net.ParseCIDR("192.168.0.0/24")
ip := net.ParseIP("127.1.1.1")
route := Route{LinkIndex: link.Attrs().Index, Dst: dst, Src: ip}
err = RouteAdd(&route)
if err != nil {
t.Fatal(err)
}
routes, err := RouteList(link, FAMILY_V4)
if err != nil {
t.Fatal(err)
}
if len(routes) != 1 {
t.Fatal("Link not added properly")
}
dstIP := net.ParseIP("192.168.0.42")
routeToDstIP, err := RouteGet(dstIP)
if err != nil {
t.Fatal(err)
}
if len(routeToDstIP) == 0 {
t.Fatal("Default route not present")
}
err = RouteDel(&route)
if err != nil {
t.Fatal(err)
}
routes, err = RouteList(link, FAMILY_V4)
if err != nil {
t.Fatal(err)
}
if len(routes) != 0 {
t.Fatal("Route not removed properly")
}
}
func TestRouteAddIncomplete(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
// get loopback interface
link, err := LinkByName("lo")
if err != nil {
t.Fatal(err)
}
// bring the interface up
if err = LinkSetUp(link); err != nil {
t.Fatal(err)
}
route := Route{LinkIndex: link.Attrs().Index}
if err := RouteAdd(&route); err == nil {
t.Fatal("Adding incomplete route should fail")
}
}

View File

@ -1,64 +0,0 @@
package netlink
import (
"fmt"
"syscall"
)
// Proto is an enum representing an ipsec protocol.
type Proto uint8
const (
XFRM_PROTO_ROUTE2 Proto = syscall.IPPROTO_ROUTING
XFRM_PROTO_ESP Proto = syscall.IPPROTO_ESP
XFRM_PROTO_AH Proto = syscall.IPPROTO_AH
XFRM_PROTO_HAO Proto = syscall.IPPROTO_DSTOPTS
XFRM_PROTO_COMP Proto = syscall.IPPROTO_COMP
XFRM_PROTO_IPSEC_ANY Proto = syscall.IPPROTO_RAW
)
func (p Proto) String() string {
switch p {
case XFRM_PROTO_ROUTE2:
return "route2"
case XFRM_PROTO_ESP:
return "esp"
case XFRM_PROTO_AH:
return "ah"
case XFRM_PROTO_HAO:
return "hao"
case XFRM_PROTO_COMP:
return "comp"
case XFRM_PROTO_IPSEC_ANY:
return "ipsec-any"
}
return fmt.Sprintf("%d", p)
}
// Mode is an enum representing an ipsec transport.
type Mode uint8
const (
XFRM_MODE_TRANSPORT Mode = iota
XFRM_MODE_TUNNEL
XFRM_MODE_ROUTEOPTIMIZATION
XFRM_MODE_IN_TRIGGER
XFRM_MODE_BEET
XFRM_MODE_MAX
)
func (m Mode) String() string {
switch m {
case XFRM_MODE_TRANSPORT:
return "transport"
case XFRM_MODE_TUNNEL:
return "tunnel"
case XFRM_MODE_ROUTEOPTIMIZATION:
return "ro"
case XFRM_MODE_IN_TRIGGER:
return "in_trigger"
case XFRM_MODE_BEET:
return "beet"
}
return fmt.Sprintf("%d", m)
}

View File

@ -1,59 +0,0 @@
package netlink
import (
"fmt"
"net"
)
// Dir is an enum representing an ipsec template direction.
type Dir uint8
const (
XFRM_DIR_IN Dir = iota
XFRM_DIR_OUT
XFRM_DIR_FWD
XFRM_SOCKET_IN
XFRM_SOCKET_OUT
XFRM_SOCKET_FWD
)
func (d Dir) String() string {
switch d {
case XFRM_DIR_IN:
return "dir in"
case XFRM_DIR_OUT:
return "dir out"
case XFRM_DIR_FWD:
return "dir fwd"
case XFRM_SOCKET_IN:
return "socket in"
case XFRM_SOCKET_OUT:
return "socket out"
case XFRM_SOCKET_FWD:
return "socket fwd"
}
return fmt.Sprintf("socket %d", d-XFRM_SOCKET_IN)
}
// XfrmPolicyTmpl encapsulates a rule for the base addresses of an ipsec
// policy. These rules are matched with XfrmState to determine encryption
// and authentication algorithms.
type XfrmPolicyTmpl struct {
Dst net.IP
Src net.IP
Proto Proto
Mode Mode
Reqid int
}
// XfrmPolicy represents an ipsec policy. It represents the overlay network
// and has a list of XfrmPolicyTmpls representing the base addresses of
// the policy.
type XfrmPolicy struct {
Dst *net.IPNet
Src *net.IPNet
Dir Dir
Priority int
Index int
Tmpls []XfrmPolicyTmpl
}

View File

@ -1,127 +0,0 @@
package netlink
import (
"syscall"
"github.com/vishvananda/netlink/nl"
)
func selFromPolicy(sel *nl.XfrmSelector, policy *XfrmPolicy) {
sel.Family = uint16(nl.GetIPFamily(policy.Dst.IP))
sel.Daddr.FromIP(policy.Dst.IP)
sel.Saddr.FromIP(policy.Src.IP)
prefixlenD, _ := policy.Dst.Mask.Size()
sel.PrefixlenD = uint8(prefixlenD)
prefixlenS, _ := policy.Src.Mask.Size()
sel.PrefixlenS = uint8(prefixlenS)
}
// XfrmPolicyAdd will add an xfrm policy to the system.
// Equivalent to: `ip xfrm policy add $policy`
func XfrmPolicyAdd(policy *XfrmPolicy) error {
req := nl.NewNetlinkRequest(nl.XFRM_MSG_NEWPOLICY, syscall.NLM_F_CREATE|syscall.NLM_F_EXCL|syscall.NLM_F_ACK)
msg := &nl.XfrmUserpolicyInfo{}
selFromPolicy(&msg.Sel, policy)
msg.Priority = uint32(policy.Priority)
msg.Index = uint32(policy.Index)
msg.Dir = uint8(policy.Dir)
msg.Lft.SoftByteLimit = nl.XFRM_INF
msg.Lft.HardByteLimit = nl.XFRM_INF
msg.Lft.SoftPacketLimit = nl.XFRM_INF
msg.Lft.HardPacketLimit = nl.XFRM_INF
req.AddData(msg)
tmplData := make([]byte, nl.SizeofXfrmUserTmpl*len(policy.Tmpls))
for i, tmpl := range policy.Tmpls {
start := i * nl.SizeofXfrmUserTmpl
userTmpl := nl.DeserializeXfrmUserTmpl(tmplData[start : start+nl.SizeofXfrmUserTmpl])
userTmpl.XfrmId.Daddr.FromIP(tmpl.Dst)
userTmpl.Saddr.FromIP(tmpl.Src)
userTmpl.XfrmId.Proto = uint8(tmpl.Proto)
userTmpl.Mode = uint8(tmpl.Mode)
userTmpl.Reqid = uint32(tmpl.Reqid)
userTmpl.Aalgos = ^uint32(0)
userTmpl.Ealgos = ^uint32(0)
userTmpl.Calgos = ^uint32(0)
}
if len(tmplData) > 0 {
tmpls := nl.NewRtAttr(nl.XFRMA_TMPL, tmplData)
req.AddData(tmpls)
}
_, err := req.Execute(syscall.NETLINK_XFRM, 0)
return err
}
// XfrmPolicyDel will delete an xfrm policy from the system. Note that
// the Tmpls are ignored when matching the policy to delete.
// Equivalent to: `ip xfrm policy del $policy`
func XfrmPolicyDel(policy *XfrmPolicy) error {
req := nl.NewNetlinkRequest(nl.XFRM_MSG_DELPOLICY, syscall.NLM_F_ACK)
msg := &nl.XfrmUserpolicyId{}
selFromPolicy(&msg.Sel, policy)
msg.Index = uint32(policy.Index)
msg.Dir = uint8(policy.Dir)
req.AddData(msg)
_, err := req.Execute(syscall.NETLINK_XFRM, 0)
return err
}
// XfrmPolicyList gets a list of xfrm policies in the system.
// Equivalent to: `ip xfrm policy show`.
// The list can be filtered by ip family.
func XfrmPolicyList(family int) ([]XfrmPolicy, error) {
req := nl.NewNetlinkRequest(nl.XFRM_MSG_GETPOLICY, syscall.NLM_F_DUMP)
msg := nl.NewIfInfomsg(family)
req.AddData(msg)
msgs, err := req.Execute(syscall.NETLINK_XFRM, nl.XFRM_MSG_NEWPOLICY)
if err != nil {
return nil, err
}
res := make([]XfrmPolicy, 0)
for _, m := range msgs {
msg := nl.DeserializeXfrmUserpolicyInfo(m)
if family != FAMILY_ALL && family != int(msg.Sel.Family) {
continue
}
var policy XfrmPolicy
policy.Dst = msg.Sel.Daddr.ToIPNet(msg.Sel.PrefixlenD)
policy.Src = msg.Sel.Saddr.ToIPNet(msg.Sel.PrefixlenS)
policy.Priority = int(msg.Priority)
policy.Index = int(msg.Index)
policy.Dir = Dir(msg.Dir)
attrs, err := nl.ParseRouteAttr(m[msg.Len():])
if err != nil {
return nil, err
}
for _, attr := range attrs {
switch attr.Attr.Type {
case nl.XFRMA_TMPL:
max := len(attr.Value)
for i := 0; i < max; i += nl.SizeofXfrmUserTmpl {
var resTmpl XfrmPolicyTmpl
tmpl := nl.DeserializeXfrmUserTmpl(attr.Value[i : i+nl.SizeofXfrmUserTmpl])
resTmpl.Dst = tmpl.XfrmId.Daddr.ToIP()
resTmpl.Src = tmpl.Saddr.ToIP()
resTmpl.Proto = Proto(tmpl.XfrmId.Proto)
resTmpl.Mode = Mode(tmpl.Mode)
resTmpl.Reqid = int(tmpl.Reqid)
policy.Tmpls = append(policy.Tmpls, resTmpl)
}
}
}
res = append(res, policy)
}
return res, nil
}

View File

@ -1,49 +0,0 @@
package netlink
import (
"net"
"testing"
)
func TestXfrmPolicyAddDel(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
src, _ := ParseIPNet("127.1.1.1/32")
dst, _ := ParseIPNet("127.1.1.2/32")
policy := XfrmPolicy{
Src: src,
Dst: dst,
Dir: XFRM_DIR_OUT,
}
tmpl := XfrmPolicyTmpl{
Src: net.ParseIP("127.0.0.1"),
Dst: net.ParseIP("127.0.0.2"),
Proto: XFRM_PROTO_ESP,
Mode: XFRM_MODE_TUNNEL,
}
policy.Tmpls = append(policy.Tmpls, tmpl)
if err := XfrmPolicyAdd(&policy); err != nil {
t.Fatal(err)
}
policies, err := XfrmPolicyList(FAMILY_ALL)
if err != nil {
t.Fatal(err)
}
if len(policies) != 1 {
t.Fatal("Policy not added properly")
}
if err = XfrmPolicyDel(&policy); err != nil {
t.Fatal(err)
}
policies, err = XfrmPolicyList(FAMILY_ALL)
if err != nil {
t.Fatal(err)
}
if len(policies) != 0 {
t.Fatal("Policy not removed properly")
}
}

View File

@ -1,53 +0,0 @@
package netlink
import (
"net"
)
// XfrmStateAlgo represents the algorithm to use for the ipsec encryption.
type XfrmStateAlgo struct {
Name string
Key []byte
TruncateLen int // Auth only
}
// EncapType is an enum representing an ipsec template direction.
type EncapType uint8
const (
XFRM_ENCAP_ESPINUDP_NONIKE EncapType = iota + 1
XFRM_ENCAP_ESPINUDP
)
func (e EncapType) String() string {
switch e {
case XFRM_ENCAP_ESPINUDP_NONIKE:
return "espinudp-nonike"
case XFRM_ENCAP_ESPINUDP:
return "espinudp"
}
return "unknown"
}
// XfrmEncap represents the encapsulation to use for the ipsec encryption.
type XfrmStateEncap struct {
Type EncapType
SrcPort int
DstPort int
OriginalAddress net.IP
}
// XfrmState represents the state of an ipsec policy. It optionally
// contains an XfrmStateAlgo for encryption and one for authentication.
type XfrmState struct {
Dst net.IP
Src net.IP
Proto Proto
Mode Mode
Spi int
Reqid int
ReplayWindow int
Auth *XfrmStateAlgo
Crypt *XfrmStateAlgo
Encap *XfrmStateEncap
}

View File

@ -1,181 +0,0 @@
package netlink
import (
"fmt"
"syscall"
"github.com/vishvananda/netlink/nl"
)
func writeStateAlgo(a *XfrmStateAlgo) []byte {
algo := nl.XfrmAlgo{
AlgKeyLen: uint32(len(a.Key) * 8),
AlgKey: a.Key,
}
end := len(a.Name)
if end > 64 {
end = 64
}
copy(algo.AlgName[:end], a.Name)
return algo.Serialize()
}
func writeStateAlgoAuth(a *XfrmStateAlgo) []byte {
algo := nl.XfrmAlgoAuth{
AlgKeyLen: uint32(len(a.Key) * 8),
AlgTruncLen: uint32(a.TruncateLen),
AlgKey: a.Key,
}
end := len(a.Name)
if end > 64 {
end = 64
}
copy(algo.AlgName[:end], a.Name)
return algo.Serialize()
}
// XfrmStateAdd will add an xfrm state to the system.
// Equivalent to: `ip xfrm state add $state`
func XfrmStateAdd(state *XfrmState) error {
// A state with spi 0 can't be deleted so don't allow it to be set
if state.Spi == 0 {
return fmt.Errorf("Spi must be set when adding xfrm state.")
}
req := nl.NewNetlinkRequest(nl.XFRM_MSG_NEWSA, syscall.NLM_F_CREATE|syscall.NLM_F_EXCL|syscall.NLM_F_ACK)
msg := &nl.XfrmUsersaInfo{}
msg.Family = uint16(nl.GetIPFamily(state.Dst))
msg.Id.Daddr.FromIP(state.Dst)
msg.Saddr.FromIP(state.Src)
msg.Id.Proto = uint8(state.Proto)
msg.Mode = uint8(state.Mode)
msg.Id.Spi = nl.Swap32(uint32(state.Spi))
msg.Reqid = uint32(state.Reqid)
msg.ReplayWindow = uint8(state.ReplayWindow)
msg.Lft.SoftByteLimit = nl.XFRM_INF
msg.Lft.HardByteLimit = nl.XFRM_INF
msg.Lft.SoftPacketLimit = nl.XFRM_INF
msg.Lft.HardPacketLimit = nl.XFRM_INF
req.AddData(msg)
if state.Auth != nil {
out := nl.NewRtAttr(nl.XFRMA_ALG_AUTH_TRUNC, writeStateAlgoAuth(state.Auth))
req.AddData(out)
}
if state.Crypt != nil {
out := nl.NewRtAttr(nl.XFRMA_ALG_CRYPT, writeStateAlgo(state.Crypt))
req.AddData(out)
}
if state.Encap != nil {
encapData := make([]byte, nl.SizeofXfrmEncapTmpl)
encap := nl.DeserializeXfrmEncapTmpl(encapData)
encap.EncapType = uint16(state.Encap.Type)
encap.EncapSport = nl.Swap16(uint16(state.Encap.SrcPort))
encap.EncapDport = nl.Swap16(uint16(state.Encap.DstPort))
encap.EncapOa.FromIP(state.Encap.OriginalAddress)
out := nl.NewRtAttr(nl.XFRMA_ENCAP, encapData)
req.AddData(out)
}
_, err := req.Execute(syscall.NETLINK_XFRM, 0)
return err
}
// XfrmStateDel will delete an xfrm state from the system. Note that
// the Algos are ignored when matching the state to delete.
// Equivalent to: `ip xfrm state del $state`
func XfrmStateDel(state *XfrmState) error {
req := nl.NewNetlinkRequest(nl.XFRM_MSG_DELSA, syscall.NLM_F_ACK)
msg := &nl.XfrmUsersaId{}
msg.Daddr.FromIP(state.Dst)
msg.Family = uint16(nl.GetIPFamily(state.Dst))
msg.Proto = uint8(state.Proto)
msg.Spi = nl.Swap32(uint32(state.Spi))
req.AddData(msg)
saddr := nl.XfrmAddress{}
saddr.FromIP(state.Src)
srcdata := nl.NewRtAttr(nl.XFRMA_SRCADDR, saddr.Serialize())
req.AddData(srcdata)
_, err := req.Execute(syscall.NETLINK_XFRM, 0)
return err
}
// XfrmStateList gets a list of xfrm states in the system.
// Equivalent to: `ip xfrm state show`.
// The list can be filtered by ip family.
func XfrmStateList(family int) ([]XfrmState, error) {
req := nl.NewNetlinkRequest(nl.XFRM_MSG_GETSA, syscall.NLM_F_DUMP)
msg := nl.NewIfInfomsg(family)
req.AddData(msg)
msgs, err := req.Execute(syscall.NETLINK_XFRM, nl.XFRM_MSG_NEWSA)
if err != nil {
return nil, err
}
res := make([]XfrmState, 0)
for _, m := range msgs {
msg := nl.DeserializeXfrmUsersaInfo(m)
if family != FAMILY_ALL && family != int(msg.Family) {
continue
}
var state XfrmState
state.Dst = msg.Id.Daddr.ToIP()
state.Src = msg.Saddr.ToIP()
state.Proto = Proto(msg.Id.Proto)
state.Mode = Mode(msg.Mode)
state.Spi = int(nl.Swap32(msg.Id.Spi))
state.Reqid = int(msg.Reqid)
state.ReplayWindow = int(msg.ReplayWindow)
attrs, err := nl.ParseRouteAttr(m[msg.Len():])
if err != nil {
return nil, err
}
for _, attr := range attrs {
switch attr.Attr.Type {
case nl.XFRMA_ALG_AUTH, nl.XFRMA_ALG_CRYPT:
var resAlgo *XfrmStateAlgo
if attr.Attr.Type == nl.XFRMA_ALG_AUTH {
if state.Auth == nil {
state.Auth = new(XfrmStateAlgo)
}
resAlgo = state.Auth
} else {
state.Crypt = new(XfrmStateAlgo)
resAlgo = state.Crypt
}
algo := nl.DeserializeXfrmAlgo(attr.Value[:])
(*resAlgo).Name = nl.BytesToString(algo.AlgName[:])
(*resAlgo).Key = algo.AlgKey
case nl.XFRMA_ALG_AUTH_TRUNC:
if state.Auth == nil {
state.Auth = new(XfrmStateAlgo)
}
algo := nl.DeserializeXfrmAlgoAuth(attr.Value[:])
state.Auth.Name = nl.BytesToString(algo.AlgName[:])
state.Auth.Key = algo.AlgKey
state.Auth.TruncateLen = int(algo.AlgTruncLen)
case nl.XFRMA_ENCAP:
encap := nl.DeserializeXfrmEncapTmpl(attr.Value[:])
state.Encap = new(XfrmStateEncap)
state.Encap.Type = EncapType(encap.EncapType)
state.Encap.SrcPort = int(nl.Swap16(encap.EncapSport))
state.Encap.DstPort = int(nl.Swap16(encap.EncapDport))
state.Encap.OriginalAddress = encap.EncapOa.ToIP()
}
}
res = append(res, state)
}
return res, nil
}

View File

@ -1,50 +0,0 @@
package netlink
import (
"net"
"testing"
)
func TestXfrmStateAddDel(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
state := XfrmState{
Src: net.ParseIP("127.0.0.1"),
Dst: net.ParseIP("127.0.0.2"),
Proto: XFRM_PROTO_ESP,
Mode: XFRM_MODE_TUNNEL,
Spi: 1,
Auth: &XfrmStateAlgo{
Name: "hmac(sha256)",
Key: []byte("abcdefghijklmnopqrstuvwzyzABCDEF"),
},
Crypt: &XfrmStateAlgo{
Name: "cbc(aes)",
Key: []byte("abcdefghijklmnopqrstuvwzyzABCDEF"),
},
}
if err := XfrmStateAdd(&state); err != nil {
t.Fatal(err)
}
policies, err := XfrmStateList(FAMILY_ALL)
if err != nil {
t.Fatal(err)
}
if len(policies) != 1 {
t.Fatal("State not added properly")
}
if err = XfrmStateDel(&state); err != nil {
t.Fatal(err)
}
policies, err = XfrmStateList(FAMILY_ALL)
if err != nil {
t.Fatal(err)
}
if len(policies) != 0 {
t.Fatal("State not removed properly")
}
}

View File

@ -1,10 +0,0 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !gccgo
#include "textflag.h"
TEXT ·use(SB),NOSPLIT,$0
RET

View File

@ -1,29 +0,0 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !gccgo
#include "textflag.h"
//
// System call support for 386, Darwin
//
// Just jump to package syscall's implementation for all these functions.
// The runtime may know about them.
TEXT ·Syscall(SB),NOSPLIT,$0-28
JMP syscall·Syscall(SB)
TEXT ·Syscall6(SB),NOSPLIT,$0-40
JMP syscall·Syscall6(SB)
TEXT ·Syscall9(SB),NOSPLIT,$0-52
JMP syscall·Syscall9(SB)
TEXT ·RawSyscall(SB),NOSPLIT,$0-28
JMP syscall·RawSyscall(SB)
TEXT ·RawSyscall6(SB),NOSPLIT,$0-40
JMP syscall·RawSyscall6(SB)

View File

@ -1,29 +0,0 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !gccgo
#include "textflag.h"
//
// System call support for AMD64, Darwin
//
// Just jump to package syscall's implementation for all these functions.
// The runtime may know about them.
TEXT ·Syscall(SB),NOSPLIT,$0-56
JMP syscall·Syscall(SB)
TEXT ·Syscall6(SB),NOSPLIT,$0-80
JMP syscall·Syscall6(SB)
TEXT ·Syscall9(SB),NOSPLIT,$0-104
JMP syscall·Syscall9(SB)
TEXT ·RawSyscall(SB),NOSPLIT,$0-56
JMP syscall·RawSyscall(SB)
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
JMP syscall·RawSyscall6(SB)

View File

@ -1,29 +0,0 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !gccgo
#include "textflag.h"
//
// System call support for 386, FreeBSD
//
// Just jump to package syscall's implementation for all these functions.
// The runtime may know about them.
TEXT ·Syscall(SB),NOSPLIT,$0-32
JMP syscall·Syscall(SB)
TEXT ·Syscall6(SB),NOSPLIT,$0-44
JMP syscall·Syscall6(SB)
TEXT ·Syscall9(SB),NOSPLIT,$0-56
JMP syscall·Syscall9(SB)
TEXT ·RawSyscall(SB),NOSPLIT,$0-32
JMP syscall·RawSyscall(SB)
TEXT ·RawSyscall6(SB),NOSPLIT,$0-44
JMP syscall·RawSyscall6(SB)

View File

@ -1,29 +0,0 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !gccgo
#include "textflag.h"
//
// System call support for AMD64, DragonFly
//
// Just jump to package syscall's implementation for all these functions.
// The runtime may know about them.
TEXT ·Syscall(SB),NOSPLIT,$0-64
JMP syscall·Syscall(SB)
TEXT ·Syscall6(SB),NOSPLIT,$0-88
JMP syscall·Syscall6(SB)
TEXT ·Syscall9(SB),NOSPLIT,$0-112
JMP syscall·Syscall9(SB)
TEXT ·RawSyscall(SB),NOSPLIT,$0-64
JMP syscall·RawSyscall(SB)
TEXT ·RawSyscall6(SB),NOSPLIT,$0-88
JMP syscall·RawSyscall6(SB)

View File

@ -1,29 +0,0 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !gccgo
#include "textflag.h"
//
// System call support for 386, FreeBSD
//
// Just jump to package syscall's implementation for all these functions.
// The runtime may know about them.
TEXT ·Syscall(SB),NOSPLIT,$0-28
JMP syscall·Syscall(SB)
TEXT ·Syscall6(SB),NOSPLIT,$0-40
JMP syscall·Syscall6(SB)
TEXT ·Syscall9(SB),NOSPLIT,$0-52
JMP syscall·Syscall9(SB)
TEXT ·RawSyscall(SB),NOSPLIT,$0-28
JMP syscall·RawSyscall(SB)
TEXT ·RawSyscall6(SB),NOSPLIT,$0-40
JMP syscall·RawSyscall6(SB)

View File

@ -1,29 +0,0 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !gccgo
#include "textflag.h"
//
// System call support for AMD64, FreeBSD
//
// Just jump to package syscall's implementation for all these functions.
// The runtime may know about them.
TEXT ·Syscall(SB),NOSPLIT,$0-56
JMP syscall·Syscall(SB)
TEXT ·Syscall6(SB),NOSPLIT,$0-80
JMP syscall·Syscall6(SB)
TEXT ·Syscall9(SB),NOSPLIT,$0-104
JMP syscall·Syscall9(SB)
TEXT ·RawSyscall(SB),NOSPLIT,$0-56
JMP syscall·RawSyscall(SB)
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
JMP syscall·RawSyscall6(SB)

View File

@ -1,29 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !gccgo
#include "textflag.h"
//
// System call support for ARM, FreeBSD
//
// Just jump to package syscall's implementation for all these functions.
// The runtime may know about them.
TEXT ·Syscall(SB),NOSPLIT,$0-28
B syscall·Syscall(SB)
TEXT ·Syscall6(SB),NOSPLIT,$0-40
B syscall·Syscall6(SB)
TEXT ·Syscall9(SB),NOSPLIT,$0-52
B syscall·Syscall9(SB)
TEXT ·RawSyscall(SB),NOSPLIT,$0-28
B syscall·RawSyscall(SB)
TEXT ·RawSyscall6(SB),NOSPLIT,$0-40
B syscall·RawSyscall6(SB)

View File

@ -1,35 +0,0 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !gccgo
#include "textflag.h"
//
// System calls for 386, Linux
//
// Just jump to package syscall's implementation for all these functions.
// The runtime may know about them.
TEXT ·Syscall(SB),NOSPLIT,$0-28
JMP syscall·Syscall(SB)
TEXT ·Syscall6(SB),NOSPLIT,$0-40
JMP syscall·Syscall6(SB)
TEXT ·RawSyscall(SB),NOSPLIT,$0-28
JMP syscall·RawSyscall(SB)
TEXT ·RawSyscall6(SB),NOSPLIT,$0-40
JMP syscall·RawSyscall6(SB)
TEXT ·socketcall(SB),NOSPLIT,$0-36
JMP syscall·socketcall(SB)
TEXT ·rawsocketcall(SB),NOSPLIT,$0-36
JMP syscall·rawsocketcall(SB)
TEXT ·seek(SB),NOSPLIT,$0-28
JMP syscall·seek(SB)

Some files were not shown because too many files have changed in this diff Show More