Update go-discover library
To pick up go.net change so we can cross compile to arm64
This commit is contained in:
parent
5298fee5d6
commit
8e78fb15bf
354
vendor/github.com/hashicorp/go-discover/LICENSE
generated
vendored
Normal file
354
vendor/github.com/hashicorp/go-discover/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,354 @@
|
||||||
|
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 Contributor’s 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 party’s
|
||||||
|
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
|
||||||
|
party’s 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 party’s 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.
|
||||||
|
|
2
vendor/github.com/hashicorp/go-discover/go.mod
generated
vendored
2
vendor/github.com/hashicorp/go-discover/go.mod
generated
vendored
|
@ -25,7 +25,7 @@ require (
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c // indirect
|
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c // indirect
|
||||||
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
|
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
|
||||||
github.com/hashicorp/go-multierror v1.0.0
|
github.com/hashicorp/go-multierror v1.0.0
|
||||||
github.com/hashicorp/mdns v1.0.0
|
github.com/hashicorp/mdns v1.0.1
|
||||||
github.com/hashicorp/vic v1.5.1-0.20190403131502-bbfe86ec9443
|
github.com/hashicorp/vic v1.5.1-0.20190403131502-bbfe86ec9443
|
||||||
github.com/hpcloud/tail v1.0.0 // indirect
|
github.com/hpcloud/tail v1.0.0 // indirect
|
||||||
github.com/imdario/mergo v0.3.6 // indirect
|
github.com/imdario/mergo v0.3.6 // indirect
|
||||||
|
|
4
vendor/github.com/hashicorp/go-discover/go.sum
generated
vendored
4
vendor/github.com/hashicorp/go-discover/go.sum
generated
vendored
|
@ -52,10 +52,10 @@ github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/U
|
||||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
|
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
|
||||||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
||||||
github.com/hashicorp/go.net v0.0.1 h1:sNCoNyDEvN1xa+X0baata4RdcpKwcMS6DH+xwfqPgjw=
|
|
||||||
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
|
|
||||||
github.com/hashicorp/mdns v1.0.0 h1:WhIgCr5a7AaVH6jPUwjtRuuE7/RDufnUvzIr48smyxs=
|
github.com/hashicorp/mdns v1.0.0 h1:WhIgCr5a7AaVH6jPUwjtRuuE7/RDufnUvzIr48smyxs=
|
||||||
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
||||||
|
github.com/hashicorp/mdns v1.0.1 h1:XFSOubp8KWB+Jd2PDyaX5xUd5bhSP/+pTDZVDMzZJM8=
|
||||||
|
github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY=
|
||||||
github.com/hashicorp/vic v1.5.1-0.20190403131502-bbfe86ec9443 h1:O/pT5C1Q3mVXMyuqg7yuAWUg/jMZR1/0QTzTRdNR6Uw=
|
github.com/hashicorp/vic v1.5.1-0.20190403131502-bbfe86ec9443 h1:O/pT5C1Q3mVXMyuqg7yuAWUg/jMZR1/0QTzTRdNR6Uw=
|
||||||
github.com/hashicorp/vic v1.5.1-0.20190403131502-bbfe86ec9443/go.mod h1:bEpDU35nTu0ey1EXjwNwPjI9xErAsoOCmcMb9GKvyxo=
|
github.com/hashicorp/vic v1.5.1-0.20190403131502-bbfe86ec9443/go.mod h1:bEpDU35nTu0ey1EXjwNwPjI9xErAsoOCmcMb9GKvyxo=
|
||||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||||
|
|
320
vendor/github.com/hashicorp/go-discover/provider/k8s/k8s_discover_test.go
generated
vendored
320
vendor/github.com/hashicorp/go-discover/provider/k8s/k8s_discover_test.go
generated
vendored
|
@ -1,320 +0,0 @@
|
||||||
package k8s_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
discover "github.com/hashicorp/go-discover"
|
|
||||||
"github.com/hashicorp/go-discover/provider/k8s"
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ discover.Provider = (*k8s.Provider)(nil)
|
|
||||||
|
|
||||||
// Acceptance test against a real cluster
|
|
||||||
func TestAcc(t *testing.T) {
|
|
||||||
path := "../../test/tf/k8s/kubeconfig.yaml"
|
|
||||||
path, err := filepath.Abs(path)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := os.Stat(path); err != nil {
|
|
||||||
t.Skipf("Skipping, can't find %q: %s", path, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
args := discover.Config{
|
|
||||||
"provider": "k8s",
|
|
||||||
"kubeconfig": path,
|
|
||||||
"label_selector": "app = valid",
|
|
||||||
}
|
|
||||||
|
|
||||||
l := log.New(os.Stderr, "", log.LstdFlags)
|
|
||||||
p := &k8s.Provider{}
|
|
||||||
addrs, err := p.Addrs(args, l)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
t.Logf("Addrs: %v", addrs)
|
|
||||||
if len(addrs) != 3 {
|
|
||||||
t.Fatalf("bad: %v", addrs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPodAddrs(t *testing.T) {
|
|
||||||
cases := []struct {
|
|
||||||
Name string
|
|
||||||
Args map[string]string
|
|
||||||
Pods []corev1.Pod
|
|
||||||
Expected []string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
"Simple pods (no ready, no annotations, etc.)",
|
|
||||||
nil,
|
|
||||||
[]corev1.Pod{
|
|
||||||
corev1.Pod{
|
|
||||||
Status: corev1.PodStatus{
|
|
||||||
Phase: corev1.PodRunning,
|
|
||||||
PodIP: "1.2.3.4",
|
|
||||||
HostIP: "2.3.4.5",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
[]string{"1.2.3.4"},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"Simple pods host network",
|
|
||||||
map[string]string{"host_network": "true"},
|
|
||||||
[]corev1.Pod{
|
|
||||||
corev1.Pod{
|
|
||||||
Status: corev1.PodStatus{
|
|
||||||
Phase: corev1.PodRunning,
|
|
||||||
PodIP: "1.2.3.4",
|
|
||||||
HostIP: "2.3.4.5",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
[]string{"2.3.4.5"},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"Only running pods",
|
|
||||||
nil,
|
|
||||||
[]corev1.Pod{
|
|
||||||
corev1.Pod{
|
|
||||||
Status: corev1.PodStatus{
|
|
||||||
Phase: corev1.PodPending,
|
|
||||||
PodIP: "2.3.4.5",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
corev1.Pod{
|
|
||||||
Status: corev1.PodStatus{
|
|
||||||
Phase: corev1.PodRunning,
|
|
||||||
PodIP: "1.2.3.4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
[]string{"1.2.3.4"},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"Only pods that are ready",
|
|
||||||
nil,
|
|
||||||
[]corev1.Pod{
|
|
||||||
corev1.Pod{
|
|
||||||
Status: corev1.PodStatus{
|
|
||||||
Phase: corev1.PodPending,
|
|
||||||
PodIP: "2.3.4.5",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
corev1.Pod{
|
|
||||||
Status: corev1.PodStatus{
|
|
||||||
Phase: corev1.PodRunning,
|
|
||||||
PodIP: "ready",
|
|
||||||
Conditions: []corev1.PodCondition{
|
|
||||||
corev1.PodCondition{
|
|
||||||
Type: corev1.PodReady,
|
|
||||||
Status: corev1.ConditionTrue,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
// Not true
|
|
||||||
corev1.Pod{
|
|
||||||
Status: corev1.PodStatus{
|
|
||||||
Phase: corev1.PodRunning,
|
|
||||||
PodIP: "not-ready",
|
|
||||||
Conditions: []corev1.PodCondition{
|
|
||||||
corev1.PodCondition{
|
|
||||||
Type: corev1.PodReady,
|
|
||||||
Status: corev1.ConditionUnknown,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
// Not ready type, ignored
|
|
||||||
corev1.Pod{
|
|
||||||
Status: corev1.PodStatus{
|
|
||||||
Phase: corev1.PodRunning,
|
|
||||||
PodIP: "scheduled",
|
|
||||||
Conditions: []corev1.PodCondition{
|
|
||||||
corev1.PodCondition{
|
|
||||||
Type: corev1.PodScheduled,
|
|
||||||
Status: corev1.ConditionUnknown,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
[]string{"ready", "scheduled"},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"Port annotation (named)",
|
|
||||||
nil,
|
|
||||||
[]corev1.Pod{
|
|
||||||
corev1.Pod{
|
|
||||||
Status: corev1.PodStatus{
|
|
||||||
Phase: corev1.PodRunning,
|
|
||||||
PodIP: "1.2.3.4",
|
|
||||||
},
|
|
||||||
|
|
||||||
Spec: corev1.PodSpec{
|
|
||||||
Containers: []corev1.Container{
|
|
||||||
corev1.Container{
|
|
||||||
Ports: []corev1.ContainerPort{
|
|
||||||
corev1.ContainerPort{
|
|
||||||
Name: "my-port",
|
|
||||||
HostPort: 1234,
|
|
||||||
ContainerPort: 8500,
|
|
||||||
},
|
|
||||||
|
|
||||||
corev1.ContainerPort{
|
|
||||||
Name: "http",
|
|
||||||
HostPort: 80,
|
|
||||||
ContainerPort: 8080,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Annotations: map[string]string{
|
|
||||||
k8s.AnnotationKeyPort: "my-port",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
[]string{"1.2.3.4:8500"},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"Port annotation (named with host network)",
|
|
||||||
map[string]string{"host_network": "true"},
|
|
||||||
[]corev1.Pod{
|
|
||||||
corev1.Pod{
|
|
||||||
Status: corev1.PodStatus{
|
|
||||||
Phase: corev1.PodRunning,
|
|
||||||
PodIP: "1.2.3.4",
|
|
||||||
HostIP: "2.3.4.5",
|
|
||||||
},
|
|
||||||
|
|
||||||
Spec: corev1.PodSpec{
|
|
||||||
Containers: []corev1.Container{
|
|
||||||
corev1.Container{
|
|
||||||
Ports: []corev1.ContainerPort{
|
|
||||||
corev1.ContainerPort{
|
|
||||||
Name: "http",
|
|
||||||
HostPort: 80,
|
|
||||||
ContainerPort: 8080,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Annotations: map[string]string{
|
|
||||||
k8s.AnnotationKeyPort: "http",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
[]string{"2.3.4.5:80"},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"Port annotation (direct)",
|
|
||||||
nil,
|
|
||||||
[]corev1.Pod{
|
|
||||||
corev1.Pod{
|
|
||||||
Status: corev1.PodStatus{
|
|
||||||
Phase: corev1.PodRunning,
|
|
||||||
PodIP: "1.2.3.4",
|
|
||||||
},
|
|
||||||
|
|
||||||
Spec: corev1.PodSpec{
|
|
||||||
Containers: []corev1.Container{
|
|
||||||
corev1.Container{
|
|
||||||
Ports: []corev1.ContainerPort{
|
|
||||||
corev1.ContainerPort{
|
|
||||||
Name: "http",
|
|
||||||
HostPort: 80,
|
|
||||||
ContainerPort: 8080,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Annotations: map[string]string{
|
|
||||||
k8s.AnnotationKeyPort: "4600",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
[]string{"1.2.3.4:4600"},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"Port annotation (direct with host network)",
|
|
||||||
map[string]string{"host_network": "true"},
|
|
||||||
[]corev1.Pod{
|
|
||||||
corev1.Pod{
|
|
||||||
Status: corev1.PodStatus{
|
|
||||||
Phase: corev1.PodRunning,
|
|
||||||
PodIP: "1.2.3.4",
|
|
||||||
HostIP: "2.3.4.5",
|
|
||||||
},
|
|
||||||
|
|
||||||
Spec: corev1.PodSpec{
|
|
||||||
Containers: []corev1.Container{
|
|
||||||
corev1.Container{
|
|
||||||
Ports: []corev1.ContainerPort{
|
|
||||||
corev1.ContainerPort{
|
|
||||||
Name: "http",
|
|
||||||
HostPort: 80,
|
|
||||||
ContainerPort: 8080,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Annotations: map[string]string{
|
|
||||||
k8s.AnnotationKeyPort: "4600",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
[]string{"2.3.4.5:4600"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range cases {
|
|
||||||
t.Run(tt.Name, func(t *testing.T) {
|
|
||||||
l := log.New(os.Stderr, "", log.LstdFlags)
|
|
||||||
addrs, err := k8s.PodAddrs(&corev1.PodList{Items: tt.Pods}, tt.Args, l)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(addrs, tt.Expected) {
|
|
||||||
t.Fatalf("bad: %#v", addrs)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,184 +0,0 @@
|
||||||
// go generate gen.go
|
|
||||||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
// Package iana provides protocol number resources managed by the Internet Assigned Numbers Authority (IANA).
|
|
||||||
package iana
|
|
||||||
|
|
||||||
// Differentiated Services Field Codepoints (DSCP), Updated: 2013-06-25
|
|
||||||
const (
|
|
||||||
DiffServCS0 = 0x0 // CS0
|
|
||||||
DiffServCS1 = 0x20 // CS1
|
|
||||||
DiffServCS2 = 0x40 // CS2
|
|
||||||
DiffServCS3 = 0x60 // CS3
|
|
||||||
DiffServCS4 = 0x80 // CS4
|
|
||||||
DiffServCS5 = 0xa0 // CS5
|
|
||||||
DiffServCS6 = 0xc0 // CS6
|
|
||||||
DiffServCS7 = 0xe0 // CS7
|
|
||||||
DiffServAF11 = 0x28 // AF11
|
|
||||||
DiffServAF12 = 0x30 // AF12
|
|
||||||
DiffServAF13 = 0x38 // AF13
|
|
||||||
DiffServAF21 = 0x48 // AF21
|
|
||||||
DiffServAF22 = 0x50 // AF22
|
|
||||||
DiffServAF23 = 0x58 // AF23
|
|
||||||
DiffServAF31 = 0x68 // AF31
|
|
||||||
DiffServAF32 = 0x70 // AF32
|
|
||||||
DiffServAF33 = 0x78 // AF33
|
|
||||||
DiffServAF41 = 0x88 // AF41
|
|
||||||
DiffServAF42 = 0x90 // AF42
|
|
||||||
DiffServAF43 = 0x98 // AF43
|
|
||||||
DiffServEFPHB = 0xb8 // EF PHB
|
|
||||||
DiffServVOICEADMIT = 0xb0 // VOICE-ADMIT
|
|
||||||
)
|
|
||||||
|
|
||||||
// IPv4 TOS Byte and IPv6 Traffic Class Octet, Updated: 2001-09-06
|
|
||||||
const (
|
|
||||||
NotECNTransport = 0x0 // Not-ECT (Not ECN-Capable Transport)
|
|
||||||
ECNTransport1 = 0x1 // ECT(1) (ECN-Capable Transport(1))
|
|
||||||
ECNTransport0 = 0x2 // ECT(0) (ECN-Capable Transport(0))
|
|
||||||
CongestionExperienced = 0x3 // CE (Congestion Experienced)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Protocol Numbers, Updated: 2014-08-12
|
|
||||||
const (
|
|
||||||
ProtocolIP = 0 // IPv4 encapsulation, pseudo protocol number
|
|
||||||
ProtocolHOPOPT = 0 // IPv6 Hop-by-Hop Option
|
|
||||||
ProtocolICMP = 1 // Internet Control Message
|
|
||||||
ProtocolIGMP = 2 // Internet Group Management
|
|
||||||
ProtocolGGP = 3 // Gateway-to-Gateway
|
|
||||||
ProtocolIPv4 = 4 // IPv4 encapsulation
|
|
||||||
ProtocolST = 5 // Stream
|
|
||||||
ProtocolTCP = 6 // Transmission Control
|
|
||||||
ProtocolCBT = 7 // CBT
|
|
||||||
ProtocolEGP = 8 // Exterior Gateway Protocol
|
|
||||||
ProtocolIGP = 9 // any private interior gateway (used by Cisco for their IGRP)
|
|
||||||
ProtocolBBNRCCMON = 10 // BBN RCC Monitoring
|
|
||||||
ProtocolNVPII = 11 // Network Voice Protocol
|
|
||||||
ProtocolPUP = 12 // PUP
|
|
||||||
ProtocolARGUS = 13 // ARGUS
|
|
||||||
ProtocolEMCON = 14 // EMCON
|
|
||||||
ProtocolXNET = 15 // Cross Net Debugger
|
|
||||||
ProtocolCHAOS = 16 // Chaos
|
|
||||||
ProtocolUDP = 17 // User Datagram
|
|
||||||
ProtocolMUX = 18 // Multiplexing
|
|
||||||
ProtocolDCNMEAS = 19 // DCN Measurement Subsystems
|
|
||||||
ProtocolHMP = 20 // Host Monitoring
|
|
||||||
ProtocolPRM = 21 // Packet Radio Measurement
|
|
||||||
ProtocolXNSIDP = 22 // XEROX NS IDP
|
|
||||||
ProtocolTRUNK1 = 23 // Trunk-1
|
|
||||||
ProtocolTRUNK2 = 24 // Trunk-2
|
|
||||||
ProtocolLEAF1 = 25 // Leaf-1
|
|
||||||
ProtocolLEAF2 = 26 // Leaf-2
|
|
||||||
ProtocolRDP = 27 // Reliable Data Protocol
|
|
||||||
ProtocolIRTP = 28 // Internet Reliable Transaction
|
|
||||||
ProtocolISOTP4 = 29 // ISO Transport Protocol Class 4
|
|
||||||
ProtocolNETBLT = 30 // Bulk Data Transfer Protocol
|
|
||||||
ProtocolMFENSP = 31 // MFE Network Services Protocol
|
|
||||||
ProtocolMERITINP = 32 // MERIT Internodal Protocol
|
|
||||||
ProtocolDCCP = 33 // Datagram Congestion Control Protocol
|
|
||||||
Protocol3PC = 34 // Third Party Connect Protocol
|
|
||||||
ProtocolIDPR = 35 // Inter-Domain Policy Routing Protocol
|
|
||||||
ProtocolXTP = 36 // XTP
|
|
||||||
ProtocolDDP = 37 // Datagram Delivery Protocol
|
|
||||||
ProtocolIDPRCMTP = 38 // IDPR Control Message Transport Proto
|
|
||||||
ProtocolTPPP = 39 // TP++ Transport Protocol
|
|
||||||
ProtocolIL = 40 // IL Transport Protocol
|
|
||||||
ProtocolIPv6 = 41 // IPv6 encapsulation
|
|
||||||
ProtocolSDRP = 42 // Source Demand Routing Protocol
|
|
||||||
ProtocolIPv6Route = 43 // Routing Header for IPv6
|
|
||||||
ProtocolIPv6Frag = 44 // Fragment Header for IPv6
|
|
||||||
ProtocolIDRP = 45 // Inter-Domain Routing Protocol
|
|
||||||
ProtocolRSVP = 46 // Reservation Protocol
|
|
||||||
ProtocolGRE = 47 // Generic Routing Encapsulation
|
|
||||||
ProtocolDSR = 48 // Dynamic Source Routing Protocol
|
|
||||||
ProtocolBNA = 49 // BNA
|
|
||||||
ProtocolESP = 50 // Encap Security Payload
|
|
||||||
ProtocolAH = 51 // Authentication Header
|
|
||||||
ProtocolINLSP = 52 // Integrated Net Layer Security TUBA
|
|
||||||
ProtocolSWIPE = 53 // IP with Encryption
|
|
||||||
ProtocolNARP = 54 // NBMA Address Resolution Protocol
|
|
||||||
ProtocolMOBILE = 55 // IP Mobility
|
|
||||||
ProtocolTLSP = 56 // Transport Layer Security Protocol using Kryptonet key management
|
|
||||||
ProtocolSKIP = 57 // SKIP
|
|
||||||
ProtocolIPv6ICMP = 58 // ICMP for IPv6
|
|
||||||
ProtocolIPv6NoNxt = 59 // No Next Header for IPv6
|
|
||||||
ProtocolIPv6Opts = 60 // Destination Options for IPv6
|
|
||||||
ProtocolCFTP = 62 // CFTP
|
|
||||||
ProtocolSATEXPAK = 64 // SATNET and Backroom EXPAK
|
|
||||||
ProtocolKRYPTOLAN = 65 // Kryptolan
|
|
||||||
ProtocolRVD = 66 // MIT Remote Virtual Disk Protocol
|
|
||||||
ProtocolIPPC = 67 // Internet Pluribus Packet Core
|
|
||||||
ProtocolSATMON = 69 // SATNET Monitoring
|
|
||||||
ProtocolVISA = 70 // VISA Protocol
|
|
||||||
ProtocolIPCV = 71 // Internet Packet Core Utility
|
|
||||||
ProtocolCPNX = 72 // Computer Protocol Network Executive
|
|
||||||
ProtocolCPHB = 73 // Computer Protocol Heart Beat
|
|
||||||
ProtocolWSN = 74 // Wang Span Network
|
|
||||||
ProtocolPVP = 75 // Packet Video Protocol
|
|
||||||
ProtocolBRSATMON = 76 // Backroom SATNET Monitoring
|
|
||||||
ProtocolSUNND = 77 // SUN ND PROTOCOL-Temporary
|
|
||||||
ProtocolWBMON = 78 // WIDEBAND Monitoring
|
|
||||||
ProtocolWBEXPAK = 79 // WIDEBAND EXPAK
|
|
||||||
ProtocolISOIP = 80 // ISO Internet Protocol
|
|
||||||
ProtocolVMTP = 81 // VMTP
|
|
||||||
ProtocolSECUREVMTP = 82 // SECURE-VMTP
|
|
||||||
ProtocolVINES = 83 // VINES
|
|
||||||
ProtocolTTP = 84 // Transaction Transport Protocol
|
|
||||||
ProtocolIPTM = 84 // Internet Protocol Traffic Manager
|
|
||||||
ProtocolNSFNETIGP = 85 // NSFNET-IGP
|
|
||||||
ProtocolDGP = 86 // Dissimilar Gateway Protocol
|
|
||||||
ProtocolTCF = 87 // TCF
|
|
||||||
ProtocolEIGRP = 88 // EIGRP
|
|
||||||
ProtocolOSPFIGP = 89 // OSPFIGP
|
|
||||||
ProtocolSpriteRPC = 90 // Sprite RPC Protocol
|
|
||||||
ProtocolLARP = 91 // Locus Address Resolution Protocol
|
|
||||||
ProtocolMTP = 92 // Multicast Transport Protocol
|
|
||||||
ProtocolAX25 = 93 // AX.25 Frames
|
|
||||||
ProtocolIPIP = 94 // IP-within-IP Encapsulation Protocol
|
|
||||||
ProtocolMICP = 95 // Mobile Internetworking Control Pro.
|
|
||||||
ProtocolSCCSP = 96 // Semaphore Communications Sec. Pro.
|
|
||||||
ProtocolETHERIP = 97 // Ethernet-within-IP Encapsulation
|
|
||||||
ProtocolENCAP = 98 // Encapsulation Header
|
|
||||||
ProtocolGMTP = 100 // GMTP
|
|
||||||
ProtocolIFMP = 101 // Ipsilon Flow Management Protocol
|
|
||||||
ProtocolPNNI = 102 // PNNI over IP
|
|
||||||
ProtocolPIM = 103 // Protocol Independent Multicast
|
|
||||||
ProtocolARIS = 104 // ARIS
|
|
||||||
ProtocolSCPS = 105 // SCPS
|
|
||||||
ProtocolQNX = 106 // QNX
|
|
||||||
ProtocolAN = 107 // Active Networks
|
|
||||||
ProtocolIPComp = 108 // IP Payload Compression Protocol
|
|
||||||
ProtocolSNP = 109 // Sitara Networks Protocol
|
|
||||||
ProtocolCompaqPeer = 110 // Compaq Peer Protocol
|
|
||||||
ProtocolIPXinIP = 111 // IPX in IP
|
|
||||||
ProtocolVRRP = 112 // Virtual Router Redundancy Protocol
|
|
||||||
ProtocolPGM = 113 // PGM Reliable Transport Protocol
|
|
||||||
ProtocolL2TP = 115 // Layer Two Tunneling Protocol
|
|
||||||
ProtocolDDX = 116 // D-II Data Exchange (DDX)
|
|
||||||
ProtocolIATP = 117 // Interactive Agent Transfer Protocol
|
|
||||||
ProtocolSTP = 118 // Schedule Transfer Protocol
|
|
||||||
ProtocolSRP = 119 // SpectraLink Radio Protocol
|
|
||||||
ProtocolUTI = 120 // UTI
|
|
||||||
ProtocolSMP = 121 // Simple Message Protocol
|
|
||||||
ProtocolSM = 122 // Simple Multicast Protocol
|
|
||||||
ProtocolPTP = 123 // Performance Transparency Protocol
|
|
||||||
ProtocolISIS = 124 // ISIS over IPv4
|
|
||||||
ProtocolFIRE = 125 // FIRE
|
|
||||||
ProtocolCRTP = 126 // Combat Radio Transport Protocol
|
|
||||||
ProtocolCRUDP = 127 // Combat Radio User Datagram
|
|
||||||
ProtocolSSCOPMCE = 128 // SSCOPMCE
|
|
||||||
ProtocolIPLT = 129 // IPLT
|
|
||||||
ProtocolSPS = 130 // Secure Packet Shield
|
|
||||||
ProtocolPIPE = 131 // Private IP Encapsulation within IP
|
|
||||||
ProtocolSCTP = 132 // Stream Control Transmission Protocol
|
|
||||||
ProtocolFC = 133 // Fibre Channel
|
|
||||||
ProtocolRSVPE2EIGNORE = 134 // RSVP-E2E-IGNORE
|
|
||||||
ProtocolMobilityHeader = 135 // Mobility Header
|
|
||||||
ProtocolUDPLite = 136 // UDPLite
|
|
||||||
ProtocolMPLSinIP = 137 // MPLS-in-IP
|
|
||||||
ProtocolMANET = 138 // MANET Protocols
|
|
||||||
ProtocolHIP = 139 // Host Identity Protocol
|
|
||||||
ProtocolShim6 = 140 // Shim6 Protocol
|
|
||||||
ProtocolWESP = 141 // Wrapped Encapsulating Security Payload
|
|
||||||
ProtocolROHC = 142 // Robust Header Compression
|
|
||||||
ProtocolReserved = 255 // Reserved
|
|
||||||
)
|
|
|
@ -1,70 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
type rawOpt struct {
|
|
||||||
sync.RWMutex
|
|
||||||
cflags ControlFlags
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *rawOpt) set(f ControlFlags) { c.cflags |= f }
|
|
||||||
func (c *rawOpt) clear(f ControlFlags) { c.cflags &^= f }
|
|
||||||
func (c *rawOpt) isset(f ControlFlags) bool { return c.cflags&f != 0 }
|
|
||||||
|
|
||||||
type ControlFlags uint
|
|
||||||
|
|
||||||
const (
|
|
||||||
FlagTTL ControlFlags = 1 << iota // pass the TTL on the received packet
|
|
||||||
FlagSrc // pass the source address on the received packet
|
|
||||||
FlagDst // pass the destination address on the received packet
|
|
||||||
FlagInterface // pass the interface index on the received packet
|
|
||||||
)
|
|
||||||
|
|
||||||
// A ControlMessage represents per packet basis IP-level socket options.
|
|
||||||
type ControlMessage struct {
|
|
||||||
// Receiving socket options: SetControlMessage allows to
|
|
||||||
// receive the options from the protocol stack using ReadFrom
|
|
||||||
// method of PacketConn or RawConn.
|
|
||||||
//
|
|
||||||
// Specifying socket options: ControlMessage for WriteTo
|
|
||||||
// method of PacketConn or RawConn allows to send the options
|
|
||||||
// to the protocol stack.
|
|
||||||
//
|
|
||||||
TTL int // time-to-live, receiving only
|
|
||||||
Src net.IP // source address, specifying only
|
|
||||||
Dst net.IP // destination address, receiving only
|
|
||||||
IfIndex int // interface index, must be 1 <= value when specifying
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cm *ControlMessage) String() string {
|
|
||||||
if cm == nil {
|
|
||||||
return "<nil>"
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("ttl: %v, src: %v, dst: %v, ifindex: %v", cm.TTL, cm.Src, cm.Dst, cm.IfIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ancillary data socket options
|
|
||||||
const (
|
|
||||||
ctlTTL = iota // header field
|
|
||||||
ctlSrc // header field
|
|
||||||
ctlDst // header field
|
|
||||||
ctlInterface // inbound or outbound interface
|
|
||||||
ctlPacketInfo // inbound or outbound packet path
|
|
||||||
ctlMax
|
|
||||||
)
|
|
||||||
|
|
||||||
// A ctlOpt represents a binding for ancillary data socket option.
|
|
||||||
type ctlOpt struct {
|
|
||||||
name int // option name, must be equal or greater than 1
|
|
||||||
length int // option length
|
|
||||||
marshal func([]byte, *ControlMessage) []byte
|
|
||||||
parse func(*ControlMessage, []byte)
|
|
||||||
}
|
|
|
@ -1,40 +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 darwin dragonfly freebsd netbsd openbsd
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hashicorp/go.net/internal/iana"
|
|
||||||
)
|
|
||||||
|
|
||||||
func marshalDst(b []byte, cm *ControlMessage) []byte {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
|
|
||||||
m.Level = iana.ProtocolIP
|
|
||||||
m.Type = sysIP_RECVDSTADDR
|
|
||||||
m.SetLen(syscall.CmsgLen(net.IPv4len))
|
|
||||||
return b[syscall.CmsgSpace(net.IPv4len):]
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseDst(cm *ControlMessage, b []byte) {
|
|
||||||
cm.Dst = b[:net.IPv4len]
|
|
||||||
}
|
|
||||||
|
|
||||||
func marshalInterface(b []byte, cm *ControlMessage) []byte {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
|
|
||||||
m.Level = iana.ProtocolIP
|
|
||||||
m.Type = sysIP_RECVIF
|
|
||||||
m.SetLen(syscall.CmsgLen(syscall.SizeofSockaddrDatalink))
|
|
||||||
return b[syscall.CmsgSpace(syscall.SizeofSockaddrDatalink):]
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseInterface(cm *ControlMessage, b []byte) {
|
|
||||||
sadl := (*syscall.SockaddrDatalink)(unsafe.Pointer(&b[0]))
|
|
||||||
cm.IfIndex = int(sadl.Index)
|
|
||||||
}
|
|
|
@ -1,37 +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 darwin linux
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hashicorp/go.net/internal/iana"
|
|
||||||
)
|
|
||||||
|
|
||||||
func marshalPacketInfo(b []byte, cm *ControlMessage) []byte {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
|
|
||||||
m.Level = iana.ProtocolIP
|
|
||||||
m.Type = sysIP_PKTINFO
|
|
||||||
m.SetLen(syscall.CmsgLen(sysSizeofInetPktinfo))
|
|
||||||
if cm != nil {
|
|
||||||
pi := (*sysInetPktinfo)(unsafe.Pointer(&b[syscall.CmsgLen(0)]))
|
|
||||||
if ip := cm.Src.To4(); ip != nil {
|
|
||||||
copy(pi.Spec_dst[:], ip)
|
|
||||||
}
|
|
||||||
if cm.IfIndex != 0 {
|
|
||||||
pi.setIfindex(cm.IfIndex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return b[syscall.CmsgSpace(sysSizeofInetPktinfo):]
|
|
||||||
}
|
|
||||||
|
|
||||||
func parsePacketInfo(cm *ControlMessage, b []byte) {
|
|
||||||
pi := (*sysInetPktinfo)(unsafe.Pointer(&b[0]))
|
|
||||||
cm.IfIndex = int(pi.Ifindex)
|
|
||||||
cm.Dst = pi.Addr[:]
|
|
||||||
}
|
|
|
@ -1,27 +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 nacl plan9 solaris
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func newControlMessage(opt *rawOpt) []byte {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseControlMessage(b []byte) (*ControlMessage, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func marshalControlMessage(cm *ControlMessage) []byte {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,166 +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 darwin dragonfly freebsd linux netbsd openbsd
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hashicorp/go.net/internal/iana"
|
|
||||||
)
|
|
||||||
|
|
||||||
func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error {
|
|
||||||
opt.Lock()
|
|
||||||
defer opt.Unlock()
|
|
||||||
if cf&FlagTTL != 0 {
|
|
||||||
if err := setInt(fd, &sockOpts[ssoReceiveTTL], boolint(on)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if on {
|
|
||||||
opt.set(FlagTTL)
|
|
||||||
} else {
|
|
||||||
opt.clear(FlagTTL)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if sockOpts[ssoPacketInfo].name > 0 {
|
|
||||||
if cf&(FlagSrc|FlagDst|FlagInterface) != 0 {
|
|
||||||
if err := setInt(fd, &sockOpts[ssoPacketInfo], boolint(on)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if on {
|
|
||||||
opt.set(cf & (FlagSrc | FlagDst | FlagInterface))
|
|
||||||
} else {
|
|
||||||
opt.clear(cf & (FlagSrc | FlagDst | FlagInterface))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if cf&FlagDst != 0 {
|
|
||||||
if err := setInt(fd, &sockOpts[ssoReceiveDst], boolint(on)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if on {
|
|
||||||
opt.set(FlagDst)
|
|
||||||
} else {
|
|
||||||
opt.clear(FlagDst)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if cf&FlagInterface != 0 {
|
|
||||||
if err := setInt(fd, &sockOpts[ssoReceiveInterface], boolint(on)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if on {
|
|
||||||
opt.set(FlagInterface)
|
|
||||||
} else {
|
|
||||||
opt.clear(FlagInterface)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func newControlMessage(opt *rawOpt) (oob []byte) {
|
|
||||||
opt.RLock()
|
|
||||||
var l int
|
|
||||||
if opt.isset(FlagTTL) {
|
|
||||||
l += syscall.CmsgSpace(ctlOpts[ctlTTL].length)
|
|
||||||
}
|
|
||||||
if ctlOpts[ctlPacketInfo].name > 0 {
|
|
||||||
if opt.isset(FlagSrc | FlagDst | FlagInterface) {
|
|
||||||
l += syscall.CmsgSpace(ctlOpts[ctlPacketInfo].length)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if opt.isset(FlagDst) {
|
|
||||||
l += syscall.CmsgSpace(ctlOpts[ctlDst].length)
|
|
||||||
}
|
|
||||||
if opt.isset(FlagInterface) {
|
|
||||||
l += syscall.CmsgSpace(ctlOpts[ctlInterface].length)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if l > 0 {
|
|
||||||
oob = make([]byte, l)
|
|
||||||
b := oob
|
|
||||||
if opt.isset(FlagTTL) {
|
|
||||||
b = ctlOpts[ctlTTL].marshal(b, nil)
|
|
||||||
}
|
|
||||||
if ctlOpts[ctlPacketInfo].name > 0 {
|
|
||||||
if opt.isset(FlagSrc | FlagDst | FlagInterface) {
|
|
||||||
b = ctlOpts[ctlPacketInfo].marshal(b, nil)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if opt.isset(FlagDst) {
|
|
||||||
b = ctlOpts[ctlDst].marshal(b, nil)
|
|
||||||
}
|
|
||||||
if opt.isset(FlagInterface) {
|
|
||||||
b = ctlOpts[ctlInterface].marshal(b, nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
opt.RUnlock()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseControlMessage(b []byte) (*ControlMessage, error) {
|
|
||||||
if len(b) == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
cmsgs, err := syscall.ParseSocketControlMessage(b)
|
|
||||||
if err != nil {
|
|
||||||
return nil, os.NewSyscallError("parse socket control message", err)
|
|
||||||
}
|
|
||||||
cm := &ControlMessage{}
|
|
||||||
for _, m := range cmsgs {
|
|
||||||
if m.Header.Level != iana.ProtocolIP {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch int(m.Header.Type) {
|
|
||||||
case ctlOpts[ctlTTL].name:
|
|
||||||
ctlOpts[ctlTTL].parse(cm, m.Data[:])
|
|
||||||
case ctlOpts[ctlDst].name:
|
|
||||||
ctlOpts[ctlDst].parse(cm, m.Data[:])
|
|
||||||
case ctlOpts[ctlInterface].name:
|
|
||||||
ctlOpts[ctlInterface].parse(cm, m.Data[:])
|
|
||||||
case ctlOpts[ctlPacketInfo].name:
|
|
||||||
ctlOpts[ctlPacketInfo].parse(cm, m.Data[:])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cm, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func marshalControlMessage(cm *ControlMessage) (oob []byte) {
|
|
||||||
if cm == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
var l int
|
|
||||||
if ctlOpts[ctlPacketInfo].name > 0 {
|
|
||||||
if cm.Src.To4() != nil || cm.IfIndex != 0 {
|
|
||||||
l += syscall.CmsgSpace(ctlOpts[ctlPacketInfo].length)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if l > 0 {
|
|
||||||
oob = make([]byte, l)
|
|
||||||
b := oob
|
|
||||||
if ctlOpts[ctlPacketInfo].name > 0 {
|
|
||||||
if cm.Src.To4() != nil || cm.IfIndex != 0 {
|
|
||||||
b = ctlOpts[ctlPacketInfo].marshal(b, cm)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func marshalTTL(b []byte, cm *ControlMessage) []byte {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
|
|
||||||
m.Level = iana.ProtocolIP
|
|
||||||
m.Type = sysIP_RECVTTL
|
|
||||||
m.SetLen(syscall.CmsgLen(1))
|
|
||||||
return b[syscall.CmsgSpace(1):]
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseTTL(cm *ControlMessage, b []byte) {
|
|
||||||
cm.TTL = int(*(*byte)(unsafe.Pointer(&b[:1][0])))
|
|
||||||
}
|
|
|
@ -1,27 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
func setControlMessage(fd syscall.Handle, opt *rawOpt, cf ControlFlags, on bool) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func newControlMessage(opt *rawOpt) []byte {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseControlMessage(b []byte) (*ControlMessage, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil, syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func marshalControlMessage(cm *ControlMessage) []byte {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,129 +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 darwin dragonfly freebsd linux netbsd openbsd windows
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MulticastTTL returns the time-to-live field value for outgoing
|
|
||||||
// multicast packets.
|
|
||||||
func (c *dgramOpt) MulticastTTL() (int, error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return getInt(fd, &sockOpts[ssoMulticastTTL])
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMulticastTTL sets the time-to-live field value for future
|
|
||||||
// outgoing multicast packets.
|
|
||||||
func (c *dgramOpt) SetMulticastTTL(ttl int) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setInt(fd, &sockOpts[ssoMulticastTTL], ttl)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MulticastInterface returns the default interface for multicast
|
|
||||||
// packet transmissions.
|
|
||||||
func (c *dgramOpt) MulticastInterface() (*net.Interface, error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return nil, syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return getInterface(fd, &sockOpts[ssoMulticastInterface])
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMulticastInterface sets the default interface for future
|
|
||||||
// multicast packet transmissions.
|
|
||||||
func (c *dgramOpt) SetMulticastInterface(ifi *net.Interface) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setInterface(fd, &sockOpts[ssoMulticastInterface], ifi)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MulticastLoopback reports whether transmitted multicast packets
|
|
||||||
// should be copied and send back to the originator.
|
|
||||||
func (c *dgramOpt) MulticastLoopback() (bool, error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return false, syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
on, err := getInt(fd, &sockOpts[ssoMulticastLoopback])
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return on == 1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMulticastLoopback sets whether transmitted multicast packets
|
|
||||||
// should be copied and send back to the originator.
|
|
||||||
func (c *dgramOpt) SetMulticastLoopback(on bool) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setInt(fd, &sockOpts[ssoMulticastLoopback], boolint(on))
|
|
||||||
}
|
|
||||||
|
|
||||||
// JoinGroup joins the group address group on the interface ifi.
|
|
||||||
// It uses the system assigned multicast interface when ifi is nil,
|
|
||||||
// although this is not recommended because the assignment depends on
|
|
||||||
// platforms and sometimes it might require routing configuration.
|
|
||||||
func (c *dgramOpt) JoinGroup(ifi *net.Interface, group net.Addr) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
grp := netAddrToIP4(group)
|
|
||||||
if grp == nil {
|
|
||||||
return errMissingAddress
|
|
||||||
}
|
|
||||||
return setGroup(fd, &sockOpts[ssoJoinGroup], ifi, grp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LeaveGroup leaves the group address group on the interface ifi.
|
|
||||||
func (c *dgramOpt) LeaveGroup(ifi *net.Interface, group net.Addr) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
grp := netAddrToIP4(group)
|
|
||||||
if grp == nil {
|
|
||||||
return errMissingAddress
|
|
||||||
}
|
|
||||||
return setGroup(fd, &sockOpts[ssoLeaveGroup], ifi, grp)
|
|
||||||
}
|
|
|
@ -1,49 +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 nacl plan9 solaris
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import "net"
|
|
||||||
|
|
||||||
func (c *dgramOpt) MulticastTTL() (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) SetMulticastTTL(ttl int) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) MulticastInterface() (*net.Interface, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) SetMulticastInterface(ifi *net.Interface) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) MulticastLoopback() (bool, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return false, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) SetMulticastLoopback(on bool) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) JoinGroup(ifi *net.Interface, grp net.Addr) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) LeaveGroup(ifi *net.Interface, grp net.Addr) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
|
@ -1,196 +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.
|
|
||||||
|
|
||||||
// Package ipv4 implements IP-level socket options for the Internet
|
|
||||||
// Protocol version 4.
|
|
||||||
//
|
|
||||||
// The package provides IP-level socket options that allow
|
|
||||||
// manipulation of IPv4 facilities. The IPv4 and basic host
|
|
||||||
// requirements for IPv4 are defined in RFC 791, RFC 1112 and RFC
|
|
||||||
// 1122.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Unicasting
|
|
||||||
//
|
|
||||||
// The options for unicasting are available for net.TCPConn,
|
|
||||||
// net.UDPConn and net.IPConn which are created as network connections
|
|
||||||
// that use the IPv4 transport. When a single TCP connection carrying
|
|
||||||
// a data flow of multiple packets needs to indicate the flow is
|
|
||||||
// important, ipv4.Conn is used to set the type-of-service field on
|
|
||||||
// the IPv4 header for each packet.
|
|
||||||
//
|
|
||||||
// ln, err := net.Listen("tcp4", "0.0.0.0:1024")
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// defer ln.Close()
|
|
||||||
// for {
|
|
||||||
// c, err := ln.Accept()
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// go func(c net.Conn) {
|
|
||||||
// defer c.Close()
|
|
||||||
//
|
|
||||||
// The outgoing packets will be labeled DiffServ assured forwarding
|
|
||||||
// class 1 low drop precedence, as known as AF11 packets.
|
|
||||||
//
|
|
||||||
// if err := ipv4.NewConn(c).SetTOS(DiffServAF11); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// if _, err := c.Write(data); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// }(c)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Multicasting
|
|
||||||
//
|
|
||||||
// The options for multicasting are available for net.UDPConn and
|
|
||||||
// net.IPconn which are created as network connections that use the
|
|
||||||
// IPv4 transport. A few network facilities must be prepared before
|
|
||||||
// you begin multicasting, at a minimum joining network interfaces and
|
|
||||||
// multicast groups.
|
|
||||||
//
|
|
||||||
// en0, err := net.InterfaceByName("en0")
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// en1, err := net.InterfaceByIndex(911)
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// group := net.IPv4(224, 0, 0, 250)
|
|
||||||
//
|
|
||||||
// First, an application listens to an appropriate address with an
|
|
||||||
// appropriate service port.
|
|
||||||
//
|
|
||||||
// c, err := net.ListenPacket("udp4", "0.0.0.0:1024")
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// defer c.Close()
|
|
||||||
//
|
|
||||||
// Second, the application joins multicast groups, starts listening to
|
|
||||||
// the groups on the specified network interfaces. Note that the
|
|
||||||
// service port for transport layer protocol does not matter with this
|
|
||||||
// operation as joining groups affects only network and link layer
|
|
||||||
// protocols, such as IPv4 and Ethernet.
|
|
||||||
//
|
|
||||||
// p := ipv4.NewPacketConn(c)
|
|
||||||
// if err := p.JoinGroup(en0, &net.UDPAddr{IP: group}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// if err := p.JoinGroup(en1, &net.UDPAddr{IP: group}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// The application might set per packet control message transmissions
|
|
||||||
// between the protocol stack within the kernel. When the application
|
|
||||||
// needs a destination address on an incoming packet,
|
|
||||||
// SetControlMessage of ipv4.PacketConn is used to enable control
|
|
||||||
// message transmissons.
|
|
||||||
//
|
|
||||||
// if err := p.SetControlMessage(ipv4.FlagDst, true); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// The application could identify whether the received packets are
|
|
||||||
// of interest by using the control message that contains the
|
|
||||||
// destination address of the received packet.
|
|
||||||
//
|
|
||||||
// b := make([]byte, 1500)
|
|
||||||
// for {
|
|
||||||
// n, cm, src, err := p.ReadFrom(b)
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// if cm.Dst.IsMulticast() {
|
|
||||||
// if cm.Dst.Equal(group)
|
|
||||||
// // joined group, do something
|
|
||||||
// } else {
|
|
||||||
// // unknown group, discard
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// The application can also send both unicast and multicast packets.
|
|
||||||
//
|
|
||||||
// p.SetTOS(DiffServCS0)
|
|
||||||
// p.SetTTL(16)
|
|
||||||
// if _, err := p.WriteTo(data, nil, src); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// dst := &net.UDPAddr{IP: group, Port: 1024}
|
|
||||||
// for _, ifi := range []*net.Interface{en0, en1} {
|
|
||||||
// if err := p.SetMulticastInterface(ifi); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// p.SetMulticastTTL(2)
|
|
||||||
// if _, err := p.WriteTo(data, nil, dst); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// More multicasting
|
|
||||||
//
|
|
||||||
// An application that uses PacketConn or RawConn may join multiple
|
|
||||||
// multicast groups. For example, a UDP listener with port 1024 might
|
|
||||||
// join two different groups across over two different network
|
|
||||||
// interfaces by using:
|
|
||||||
//
|
|
||||||
// c, err := net.ListenPacket("udp4", "0.0.0.0:1024")
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// defer c.Close()
|
|
||||||
// p := ipv4.NewPacketConn(c)
|
|
||||||
// if err := p.JoinGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 248)}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// if err := p.JoinGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 249)}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// if err := p.JoinGroup(en1, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 249)}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// It is possible for multiple UDP listeners that listen on the same
|
|
||||||
// UDP port to join the same multicast group. The net package will
|
|
||||||
// provide a socket that listens to a wildcard address with reusable
|
|
||||||
// UDP port when an appropriate multicast address prefix is passed to
|
|
||||||
// the net.ListenPacket or net.ListenUDP.
|
|
||||||
//
|
|
||||||
// c1, err := net.ListenPacket("udp4", "224.0.0.0:1024")
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// defer c1.Close()
|
|
||||||
// c2, err := net.ListenPacket("udp4", "224.0.0.0:1024")
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// defer c2.Close()
|
|
||||||
// p1 := ipv4.NewPacketConn(c1)
|
|
||||||
// if err := p1.JoinGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 248)}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// p2 := ipv4.NewPacketConn(c2)
|
|
||||||
// if err := p2.JoinGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 248)}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Also it is possible for the application to leave or rejoin a
|
|
||||||
// multicast group on the network interface.
|
|
||||||
//
|
|
||||||
// if err := p.LeaveGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 248)}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// if err := p.JoinGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 250)}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
package ipv4
|
|
|
@ -1,181 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// A Conn represents a network endpoint that uses the IPv4 transport.
|
|
||||||
// It is used to control basic IP-level socket options such as TOS and
|
|
||||||
// TTL.
|
|
||||||
type Conn struct {
|
|
||||||
genericOpt
|
|
||||||
}
|
|
||||||
|
|
||||||
type genericOpt struct {
|
|
||||||
net.Conn
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *genericOpt) ok() bool { return c != nil && c.Conn != nil }
|
|
||||||
|
|
||||||
// NewConn returns a new Conn.
|
|
||||||
func NewConn(c net.Conn) *Conn {
|
|
||||||
return &Conn{
|
|
||||||
genericOpt: genericOpt{Conn: c},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A PacketConn represents a packet network endpoint that uses the
|
|
||||||
// IPv4 transport. It is used to control several IP-level socket
|
|
||||||
// options including multicasting. It also provides datagram based
|
|
||||||
// network I/O methods specific to the IPv4 and higher layer protocols
|
|
||||||
// such as UDP.
|
|
||||||
type PacketConn struct {
|
|
||||||
genericOpt
|
|
||||||
dgramOpt
|
|
||||||
payloadHandler
|
|
||||||
}
|
|
||||||
|
|
||||||
type dgramOpt struct {
|
|
||||||
net.PacketConn
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) ok() bool { return c != nil && c.PacketConn != nil }
|
|
||||||
|
|
||||||
// SetControlMessage sets the per packet IP-level socket options.
|
|
||||||
func (c *PacketConn) SetControlMessage(cf ControlFlags, on bool) error {
|
|
||||||
if !c.payloadHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.payloadHandler.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setControlMessage(fd, &c.payloadHandler.rawOpt, cf, on)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDeadline sets the read and write deadlines associated with the
|
|
||||||
// endpoint.
|
|
||||||
func (c *PacketConn) SetDeadline(t time.Time) error {
|
|
||||||
if !c.payloadHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
return c.payloadHandler.PacketConn.SetDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetReadDeadline sets the read deadline associated with the
|
|
||||||
// endpoint.
|
|
||||||
func (c *PacketConn) SetReadDeadline(t time.Time) error {
|
|
||||||
if !c.payloadHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
return c.payloadHandler.PacketConn.SetReadDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetWriteDeadline sets the write deadline associated with the
|
|
||||||
// endpoint.
|
|
||||||
func (c *PacketConn) SetWriteDeadline(t time.Time) error {
|
|
||||||
if !c.payloadHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
return c.payloadHandler.PacketConn.SetWriteDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close closes the endpoint.
|
|
||||||
func (c *PacketConn) Close() error {
|
|
||||||
if !c.payloadHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
return c.payloadHandler.PacketConn.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPacketConn returns a new PacketConn using c as its underlying
|
|
||||||
// transport.
|
|
||||||
func NewPacketConn(c net.PacketConn) *PacketConn {
|
|
||||||
return &PacketConn{
|
|
||||||
genericOpt: genericOpt{Conn: c.(net.Conn)},
|
|
||||||
dgramOpt: dgramOpt{PacketConn: c},
|
|
||||||
payloadHandler: payloadHandler{PacketConn: c},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A RawConn represents a packet network endpoint that uses the IPv4
|
|
||||||
// transport. It is used to control several IP-level socket options
|
|
||||||
// including IPv4 header manipulation. It also provides datagram
|
|
||||||
// based network I/O methods specific to the IPv4 and higher layer
|
|
||||||
// protocols that handle IPv4 datagram directly such as OSPF, GRE.
|
|
||||||
type RawConn struct {
|
|
||||||
genericOpt
|
|
||||||
dgramOpt
|
|
||||||
packetHandler
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetControlMessage sets the per packet IP-level socket options.
|
|
||||||
func (c *RawConn) SetControlMessage(cf ControlFlags, on bool) error {
|
|
||||||
if !c.packetHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.packetHandler.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setControlMessage(fd, &c.packetHandler.rawOpt, cf, on)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDeadline sets the read and write deadlines associated with the
|
|
||||||
// endpoint.
|
|
||||||
func (c *RawConn) SetDeadline(t time.Time) error {
|
|
||||||
if !c.packetHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
return c.packetHandler.c.SetDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetReadDeadline sets the read deadline associated with the
|
|
||||||
// endpoint.
|
|
||||||
func (c *RawConn) SetReadDeadline(t time.Time) error {
|
|
||||||
if !c.packetHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
return c.packetHandler.c.SetReadDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetWriteDeadline sets the write deadline associated with the
|
|
||||||
// endpoint.
|
|
||||||
func (c *RawConn) SetWriteDeadline(t time.Time) error {
|
|
||||||
if !c.packetHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
return c.packetHandler.c.SetWriteDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close closes the endpoint.
|
|
||||||
func (c *RawConn) Close() error {
|
|
||||||
if !c.packetHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
return c.packetHandler.c.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRawConn returns a new RawConn using c as its underlying
|
|
||||||
// transport.
|
|
||||||
func NewRawConn(c net.PacketConn) (*RawConn, error) {
|
|
||||||
r := &RawConn{
|
|
||||||
genericOpt: genericOpt{Conn: c.(net.Conn)},
|
|
||||||
dgramOpt: dgramOpt{PacketConn: c},
|
|
||||||
packetHandler: packetHandler{c: c.(*net.IPConn)},
|
|
||||||
}
|
|
||||||
fd, err := r.packetHandler.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := setInt(fd, &sockOpts[ssoHeaderPrepend], boolint(true)); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return r, nil
|
|
||||||
}
|
|
|
@ -1,59 +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 darwin dragonfly freebsd linux netbsd openbsd windows
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
// TOS returns the type-of-service field value for outgoing packets.
|
|
||||||
func (c *genericOpt) TOS() (int, error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return getInt(fd, &sockOpts[ssoTOS])
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetTOS sets the type-of-service field value for future outgoing
|
|
||||||
// packets.
|
|
||||||
func (c *genericOpt) SetTOS(tos int) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setInt(fd, &sockOpts[ssoTOS], tos)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TTL returns the time-to-live field value for outgoing packets.
|
|
||||||
func (c *genericOpt) TTL() (int, error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return getInt(fd, &sockOpts[ssoTTL])
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetTTL sets the time-to-live field value for future outgoing
|
|
||||||
// packets.
|
|
||||||
func (c *genericOpt) SetTTL(ttl int) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setInt(fd, &sockOpts[ssoTTL], ttl)
|
|
||||||
}
|
|
|
@ -1,27 +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 nacl plan9 solaris
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
func (c *genericOpt) TOS() (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *genericOpt) SetTOS(tos int) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *genericOpt) TTL() (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *genericOpt) SetTTL(ttl int) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
|
@ -1,163 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
"runtime"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
errMissingAddress = errors.New("missing address")
|
|
||||||
errMissingHeader = errors.New("missing header")
|
|
||||||
errHeaderTooShort = errors.New("header too short")
|
|
||||||
errBufferTooShort = errors.New("buffer too short")
|
|
||||||
errInvalidConnType = errors.New("invalid conn type")
|
|
||||||
)
|
|
||||||
|
|
||||||
// References:
|
|
||||||
//
|
|
||||||
// RFC 791 Internet Protocol
|
|
||||||
// http://tools.ietf.org/html/rfc791
|
|
||||||
// RFC 1112 Host Extensions for IP Multicasting
|
|
||||||
// http://tools.ietf.org/html/rfc1112
|
|
||||||
// RFC 1122 Requirements for Internet Hosts
|
|
||||||
// http://tools.ietf.org/html/rfc1122
|
|
||||||
|
|
||||||
const (
|
|
||||||
Version = 4 // protocol version
|
|
||||||
HeaderLen = 20 // header length without extension headers
|
|
||||||
maxHeaderLen = 60 // sensible default, revisit if later RFCs define new usage of version and header length fields
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
posTOS = 1 // type-of-service
|
|
||||||
posTotalLen = 2 // packet total length
|
|
||||||
posID = 4 // identification
|
|
||||||
posFragOff = 6 // fragment offset
|
|
||||||
posTTL = 8 // time-to-live
|
|
||||||
posProtocol = 9 // next protocol
|
|
||||||
posChecksum = 10 // checksum
|
|
||||||
posSrc = 12 // source address
|
|
||||||
posDst = 16 // destination address
|
|
||||||
)
|
|
||||||
|
|
||||||
type HeaderFlags int
|
|
||||||
|
|
||||||
const (
|
|
||||||
MoreFragments HeaderFlags = 1 << iota // more fragments flag
|
|
||||||
DontFragment // don't fragment flag
|
|
||||||
)
|
|
||||||
|
|
||||||
// A Header represents an IPv4 header.
|
|
||||||
type Header struct {
|
|
||||||
Version int // protocol version
|
|
||||||
Len int // header length
|
|
||||||
TOS int // type-of-service
|
|
||||||
TotalLen int // packet total length
|
|
||||||
ID int // identification
|
|
||||||
Flags HeaderFlags // flags
|
|
||||||
FragOff int // fragment offset
|
|
||||||
TTL int // time-to-live
|
|
||||||
Protocol int // next protocol
|
|
||||||
Checksum int // checksum
|
|
||||||
Src net.IP // source address
|
|
||||||
Dst net.IP // destination address
|
|
||||||
Options []byte // options, extension headers
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Header) String() string {
|
|
||||||
if h == nil {
|
|
||||||
return "<nil>"
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("ver: %v, hdrlen: %v, tos: %#x, totallen: %v, id: %#x, flags: %#x, fragoff: %#x, ttl: %v, proto: %v, cksum: %#x, src: %v, dst: %v", h.Version, h.Len, h.TOS, h.TotalLen, h.ID, h.Flags, h.FragOff, h.TTL, h.Protocol, h.Checksum, h.Src, h.Dst)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Please refer to the online manual; IP(4) on Darwin, FreeBSD and
|
|
||||||
// OpenBSD. IP(7) on Linux.
|
|
||||||
const supportsNewIPInput = runtime.GOOS == "linux" || runtime.GOOS == "openbsd"
|
|
||||||
|
|
||||||
// Marshal returns the binary encoding of the IPv4 header h.
|
|
||||||
func (h *Header) Marshal() ([]byte, error) {
|
|
||||||
if h == nil {
|
|
||||||
return nil, syscall.EINVAL
|
|
||||||
}
|
|
||||||
if h.Len < HeaderLen {
|
|
||||||
return nil, errHeaderTooShort
|
|
||||||
}
|
|
||||||
hdrlen := HeaderLen + len(h.Options)
|
|
||||||
b := make([]byte, hdrlen)
|
|
||||||
b[0] = byte(Version<<4 | (hdrlen >> 2 & 0x0f))
|
|
||||||
b[posTOS] = byte(h.TOS)
|
|
||||||
flagsAndFragOff := (h.FragOff & 0x1fff) | int(h.Flags<<13)
|
|
||||||
if supportsNewIPInput {
|
|
||||||
b[posTotalLen], b[posTotalLen+1] = byte(h.TotalLen>>8), byte(h.TotalLen)
|
|
||||||
b[posFragOff], b[posFragOff+1] = byte(flagsAndFragOff>>8), byte(flagsAndFragOff)
|
|
||||||
} else {
|
|
||||||
*(*uint16)(unsafe.Pointer(&b[posTotalLen : posTotalLen+1][0])) = uint16(h.TotalLen)
|
|
||||||
*(*uint16)(unsafe.Pointer(&b[posFragOff : posFragOff+1][0])) = uint16(flagsAndFragOff)
|
|
||||||
}
|
|
||||||
b[posID], b[posID+1] = byte(h.ID>>8), byte(h.ID)
|
|
||||||
b[posTTL] = byte(h.TTL)
|
|
||||||
b[posProtocol] = byte(h.Protocol)
|
|
||||||
b[posChecksum], b[posChecksum+1] = byte(h.Checksum>>8), byte(h.Checksum)
|
|
||||||
if ip := h.Src.To4(); ip != nil {
|
|
||||||
copy(b[posSrc:posSrc+net.IPv4len], ip[:net.IPv4len])
|
|
||||||
}
|
|
||||||
if ip := h.Dst.To4(); ip != nil {
|
|
||||||
copy(b[posDst:posDst+net.IPv4len], ip[:net.IPv4len])
|
|
||||||
} else {
|
|
||||||
return nil, errMissingAddress
|
|
||||||
}
|
|
||||||
if len(h.Options) > 0 {
|
|
||||||
copy(b[HeaderLen:], h.Options)
|
|
||||||
}
|
|
||||||
return b, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// See http://www.freebsd.org/doc/en/books/porters-handbook/freebsd-versions.html.
|
|
||||||
var freebsdVersion uint32
|
|
||||||
|
|
||||||
// ParseHeader parses b as an IPv4 header.
|
|
||||||
func ParseHeader(b []byte) (*Header, error) {
|
|
||||||
if len(b) < HeaderLen {
|
|
||||||
return nil, errHeaderTooShort
|
|
||||||
}
|
|
||||||
hdrlen := int(b[0]&0x0f) << 2
|
|
||||||
if hdrlen > len(b) {
|
|
||||||
return nil, errBufferTooShort
|
|
||||||
}
|
|
||||||
h := &Header{}
|
|
||||||
h.Version = int(b[0] >> 4)
|
|
||||||
h.Len = hdrlen
|
|
||||||
h.TOS = int(b[posTOS])
|
|
||||||
if supportsNewIPInput {
|
|
||||||
h.TotalLen = int(b[posTotalLen])<<8 | int(b[posTotalLen+1])
|
|
||||||
h.FragOff = int(b[posFragOff])<<8 | int(b[posFragOff+1])
|
|
||||||
} else {
|
|
||||||
h.TotalLen = int(*(*uint16)(unsafe.Pointer(&b[posTotalLen : posTotalLen+1][0])))
|
|
||||||
if runtime.GOOS != "freebsd" || freebsdVersion < 1000000 {
|
|
||||||
h.TotalLen += hdrlen
|
|
||||||
}
|
|
||||||
h.FragOff = int(*(*uint16)(unsafe.Pointer(&b[posFragOff : posFragOff+1][0])))
|
|
||||||
}
|
|
||||||
h.Flags = HeaderFlags(h.FragOff&0xe000) >> 13
|
|
||||||
h.FragOff = h.FragOff & 0x1fff
|
|
||||||
h.ID = int(b[posID])<<8 | int(b[posID+1])
|
|
||||||
h.TTL = int(b[posTTL])
|
|
||||||
h.Protocol = int(b[posProtocol])
|
|
||||||
h.Checksum = int(b[posChecksum])<<8 | int(b[posChecksum+1])
|
|
||||||
h.Src = net.IPv4(b[posSrc], b[posSrc+1], b[posSrc+2], b[posSrc+3])
|
|
||||||
h.Dst = net.IPv4(b[posDst], b[posDst+1], b[posDst+2], b[posDst+3])
|
|
||||||
if hdrlen-HeaderLen > 0 {
|
|
||||||
h.Options = make([]byte, hdrlen-HeaderLen)
|
|
||||||
copy(h.Options, b[HeaderLen:])
|
|
||||||
}
|
|
||||||
return h, nil
|
|
||||||
}
|
|
|
@ -1,37 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"net"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
errOpNoSupport = errors.New("operation not supported")
|
|
||||||
errNoSuchInterface = errors.New("no such interface")
|
|
||||||
errNoSuchMulticastInterface = errors.New("no such multicast interface")
|
|
||||||
)
|
|
||||||
|
|
||||||
func boolint(b bool) int {
|
|
||||||
if b {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func netAddrToIP4(a net.Addr) net.IP {
|
|
||||||
switch v := a.(type) {
|
|
||||||
case *net.UDPAddr:
|
|
||||||
if ip := v.IP.To4(); ip != nil {
|
|
||||||
return ip
|
|
||||||
}
|
|
||||||
case *net.IPAddr:
|
|
||||||
if ip := v.IP.To4(); ip != nil {
|
|
||||||
return ip
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,27 +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 nacl plan9 solaris
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
func (c *genericOpt) sysfd() (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) sysfd() (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *payloadHandler) sysfd() (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *packetHandler) sysfd() (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
|
@ -1,50 +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 darwin dragonfly freebsd linux netbsd openbsd
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *genericOpt) sysfd() (int, error) {
|
|
||||||
switch p := c.Conn.(type) {
|
|
||||||
case *net.TCPConn, *net.UDPConn, *net.IPConn:
|
|
||||||
return sysfd(p)
|
|
||||||
}
|
|
||||||
return 0, errInvalidConnType
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) sysfd() (int, error) {
|
|
||||||
switch p := c.PacketConn.(type) {
|
|
||||||
case *net.UDPConn, *net.IPConn:
|
|
||||||
return sysfd(p.(net.Conn))
|
|
||||||
}
|
|
||||||
return 0, errInvalidConnType
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *payloadHandler) sysfd() (int, error) {
|
|
||||||
return sysfd(c.PacketConn.(net.Conn))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *packetHandler) sysfd() (int, error) {
|
|
||||||
return sysfd(c.c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func sysfd(c net.Conn) (int, error) {
|
|
||||||
cv := reflect.ValueOf(c)
|
|
||||||
switch ce := cv.Elem(); ce.Kind() {
|
|
||||||
case reflect.Struct:
|
|
||||||
netfd := ce.FieldByName("conn").FieldByName("fd")
|
|
||||||
switch fe := netfd.Elem(); fe.Kind() {
|
|
||||||
case reflect.Struct:
|
|
||||||
fd := fe.FieldByName("sysfd")
|
|
||||||
return int(fd.Int()), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0, errInvalidConnType
|
|
||||||
}
|
|
|
@ -1,49 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"reflect"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *genericOpt) sysfd() (syscall.Handle, error) {
|
|
||||||
switch p := c.Conn.(type) {
|
|
||||||
case *net.TCPConn, *net.UDPConn, *net.IPConn:
|
|
||||||
return sysfd(p)
|
|
||||||
}
|
|
||||||
return syscall.InvalidHandle, errInvalidConnType
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) sysfd() (syscall.Handle, error) {
|
|
||||||
switch p := c.PacketConn.(type) {
|
|
||||||
case *net.UDPConn, *net.IPConn:
|
|
||||||
return sysfd(p.(net.Conn))
|
|
||||||
}
|
|
||||||
return syscall.InvalidHandle, errInvalidConnType
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *payloadHandler) sysfd() (syscall.Handle, error) {
|
|
||||||
return sysfd(c.PacketConn.(net.Conn))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *packetHandler) sysfd() (syscall.Handle, error) {
|
|
||||||
return sysfd(c.c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func sysfd(c net.Conn) (syscall.Handle, error) {
|
|
||||||
cv := reflect.ValueOf(c)
|
|
||||||
switch ce := cv.Elem(); ce.Kind() {
|
|
||||||
case reflect.Struct:
|
|
||||||
netfd := ce.FieldByName("conn").FieldByName("fd")
|
|
||||||
switch fe := netfd.Elem(); fe.Kind() {
|
|
||||||
case reflect.Struct:
|
|
||||||
fd := fe.FieldByName("sysfd")
|
|
||||||
return syscall.Handle(fd.Uint()), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return syscall.InvalidHandle, errInvalidConnType
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
// go generate gen.go
|
|
||||||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
// Internet Control Message Protocol (ICMP) Parameters, Updated: 2013-04-19
|
|
||||||
const (
|
|
||||||
ICMPTypeEchoReply ICMPType = 0 // Echo Reply
|
|
||||||
ICMPTypeDestinationUnreachable ICMPType = 3 // Destination Unreachable
|
|
||||||
ICMPTypeRedirect ICMPType = 5 // Redirect
|
|
||||||
ICMPTypeEcho ICMPType = 8 // Echo
|
|
||||||
ICMPTypeRouterAdvertisement ICMPType = 9 // Router Advertisement
|
|
||||||
ICMPTypeRouterSolicitation ICMPType = 10 // Router Solicitation
|
|
||||||
ICMPTypeTimeExceeded ICMPType = 11 // Time Exceeded
|
|
||||||
ICMPTypeParameterProblem ICMPType = 12 // Parameter Problem
|
|
||||||
ICMPTypeTimestamp ICMPType = 13 // Timestamp
|
|
||||||
ICMPTypeTimestampReply ICMPType = 14 // Timestamp Reply
|
|
||||||
ICMPTypePhoturis ICMPType = 40 // Photuris
|
|
||||||
)
|
|
||||||
|
|
||||||
// Internet Control Message Protocol (ICMP) Parameters, Updated: 2013-04-19
|
|
||||||
var icmpTypes = map[ICMPType]string{
|
|
||||||
0: "echo reply",
|
|
||||||
3: "destination unreachable",
|
|
||||||
5: "redirect",
|
|
||||||
8: "echo",
|
|
||||||
9: "router advertisement",
|
|
||||||
10: "router solicitation",
|
|
||||||
11: "time exceeded",
|
|
||||||
12: "parameter problem",
|
|
||||||
13: "timestamp",
|
|
||||||
14: "timestamp reply",
|
|
||||||
40: "photuris",
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
// An ICMPType represents a type of ICMP message.
|
|
||||||
type ICMPType int
|
|
||||||
|
|
||||||
func (typ ICMPType) String() string {
|
|
||||||
s, ok := icmpTypes[typ]
|
|
||||||
if !ok {
|
|
||||||
return "<nil>"
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
|
@ -1,97 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// A packetHandler represents the IPv4 datagram handler.
|
|
||||||
type packetHandler struct {
|
|
||||||
c *net.IPConn
|
|
||||||
rawOpt
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *packetHandler) ok() bool { return c != nil && c.c != nil }
|
|
||||||
|
|
||||||
// ReadFrom reads an IPv4 datagram from the endpoint c, copying the
|
|
||||||
// datagram into b. It returns the received datagram as the IPv4
|
|
||||||
// header h, the payload p and the control message cm.
|
|
||||||
func (c *packetHandler) ReadFrom(b []byte) (h *Header, p []byte, cm *ControlMessage, err error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return nil, nil, nil, syscall.EINVAL
|
|
||||||
}
|
|
||||||
oob := newControlMessage(&c.rawOpt)
|
|
||||||
n, oobn, _, src, err := c.c.ReadMsgIP(b, oob)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, nil, err
|
|
||||||
}
|
|
||||||
var hs []byte
|
|
||||||
if hs, p, err = slicePacket(b[:n]); err != nil {
|
|
||||||
return nil, nil, nil, err
|
|
||||||
}
|
|
||||||
if h, err = ParseHeader(hs); err != nil {
|
|
||||||
return nil, nil, nil, err
|
|
||||||
}
|
|
||||||
if cm, err = parseControlMessage(oob[:oobn]); err != nil {
|
|
||||||
return nil, nil, nil, err
|
|
||||||
}
|
|
||||||
if src != nil && cm != nil {
|
|
||||||
cm.Src = src.IP
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func slicePacket(b []byte) (h, p []byte, err error) {
|
|
||||||
if len(b) < HeaderLen {
|
|
||||||
return nil, nil, errHeaderTooShort
|
|
||||||
}
|
|
||||||
hdrlen := int(b[0]&0x0f) << 2
|
|
||||||
return b[:hdrlen], b[hdrlen:], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteTo writes an IPv4 datagram through the endpoint c, copying the
|
|
||||||
// datagram from the IPv4 header h and the payload p. The control
|
|
||||||
// message cm allows the datagram path and the outgoing interface to be
|
|
||||||
// specified. Currently only Darwin and Linux support this. The cm
|
|
||||||
// may be nil if control of the outgoing datagram is not required.
|
|
||||||
//
|
|
||||||
// The IPv4 header h must contain appropriate fields that include:
|
|
||||||
//
|
|
||||||
// Version = ipv4.Version
|
|
||||||
// Len = <must be specified>
|
|
||||||
// TOS = <must be specified>
|
|
||||||
// TotalLen = <must be specified>
|
|
||||||
// ID = platform sets an appropriate value if ID is zero
|
|
||||||
// FragOff = <must be specified>
|
|
||||||
// TTL = <must be specified>
|
|
||||||
// Protocol = <must be specified>
|
|
||||||
// Checksum = platform sets an appropriate value if Checksum is zero
|
|
||||||
// Src = platform sets an appropriate value if Src is nil
|
|
||||||
// Dst = <must be specified>
|
|
||||||
// Options = optional
|
|
||||||
func (c *packetHandler) WriteTo(h *Header, p []byte, cm *ControlMessage) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
oob := marshalControlMessage(cm)
|
|
||||||
wh, err := h.Marshal()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
dst := &net.IPAddr{}
|
|
||||||
if cm != nil {
|
|
||||||
if ip := cm.Dst.To4(); ip != nil {
|
|
||||||
dst.IP = ip
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if dst.IP == nil {
|
|
||||||
dst.IP = h.Dst
|
|
||||||
}
|
|
||||||
wh = append(wh, p...)
|
|
||||||
_, _, err = c.c.WriteMsgIP(wh, oob, dst)
|
|
||||||
return err
|
|
||||||
}
|
|
|
@ -1,15 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import "net"
|
|
||||||
|
|
||||||
// A payloadHandler represents the IPv4 datagram payload handler.
|
|
||||||
type payloadHandler struct {
|
|
||||||
net.PacketConn
|
|
||||||
rawOpt
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *payloadHandler) ok() bool { return c != nil && c.PacketConn != nil }
|
|
|
@ -1,75 +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 !plan9,!solaris,!windows
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ReadFrom reads a payload of the received IPv4 datagram, from the
|
|
||||||
// endpoint c, copying the payload into b. It returns the number of
|
|
||||||
// bytes copied into b, the control message cm and the source address
|
|
||||||
// src of the received datagram.
|
|
||||||
func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, nil, nil, syscall.EINVAL
|
|
||||||
}
|
|
||||||
oob := newControlMessage(&c.rawOpt)
|
|
||||||
var oobn int
|
|
||||||
switch c := c.PacketConn.(type) {
|
|
||||||
case *net.UDPConn:
|
|
||||||
if n, oobn, _, src, err = c.ReadMsgUDP(b, oob); err != nil {
|
|
||||||
return 0, nil, nil, err
|
|
||||||
}
|
|
||||||
case *net.IPConn:
|
|
||||||
nb := make([]byte, maxHeaderLen+len(b))
|
|
||||||
if n, oobn, _, src, err = c.ReadMsgIP(nb, oob); err != nil {
|
|
||||||
return 0, nil, nil, err
|
|
||||||
}
|
|
||||||
hdrlen := int(nb[0]&0x0f) << 2
|
|
||||||
copy(b, nb[hdrlen:])
|
|
||||||
n -= hdrlen
|
|
||||||
default:
|
|
||||||
return 0, nil, nil, errInvalidConnType
|
|
||||||
}
|
|
||||||
if cm, err = parseControlMessage(oob[:oobn]); err != nil {
|
|
||||||
return 0, nil, nil, err
|
|
||||||
}
|
|
||||||
if cm != nil {
|
|
||||||
cm.Src = netAddrToIP4(src)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteTo writes a payload of the IPv4 datagram, to the destination
|
|
||||||
// address dst through the endpoint c, copying the payload from b. It
|
|
||||||
// returns the number of bytes written. The control message cm allows
|
|
||||||
// the datagram path and the outgoing interface to be specified.
|
|
||||||
// Currently only Darwin and Darwin support this. The cm may be nil if
|
|
||||||
// control of the outgoing datagram is not required.
|
|
||||||
func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, syscall.EINVAL
|
|
||||||
}
|
|
||||||
oob := marshalControlMessage(cm)
|
|
||||||
if dst == nil {
|
|
||||||
return 0, errMissingAddress
|
|
||||||
}
|
|
||||||
switch c := c.PacketConn.(type) {
|
|
||||||
case *net.UDPConn:
|
|
||||||
n, _, err = c.WriteMsgUDP(b, oob, dst.(*net.UDPAddr))
|
|
||||||
case *net.IPConn:
|
|
||||||
n, _, err = c.WriteMsgIP(b, oob, dst.(*net.IPAddr))
|
|
||||||
default:
|
|
||||||
return 0, errInvalidConnType
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,42 +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 plan9 solaris windows
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ReadFrom reads a payload of the received IPv4 datagram, from the
|
|
||||||
// endpoint c, copying the payload into b. It returns the number of
|
|
||||||
// bytes copied into b, the control message cm and the source address
|
|
||||||
// src of the received datagram.
|
|
||||||
func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, nil, nil, syscall.EINVAL
|
|
||||||
}
|
|
||||||
if n, src, err = c.PacketConn.ReadFrom(b); err != nil {
|
|
||||||
return 0, nil, nil, err
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteTo writes a payload of the IPv4 datagram, to the destination
|
|
||||||
// address dst through the endpoint c, copying the payload from b. It
|
|
||||||
// returns the number of bytes written. The control message cm allows
|
|
||||||
// the datagram path and the outgoing interface to be specified.
|
|
||||||
// Currently only Darwin and Linux support this. The cm may be nil if
|
|
||||||
// control of the outgoing datagram is not required.
|
|
||||||
func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, syscall.EINVAL
|
|
||||||
}
|
|
||||||
if dst == nil {
|
|
||||||
return 0, errMissingAddress
|
|
||||||
}
|
|
||||||
return c.PacketConn.WriteTo(b, dst)
|
|
||||||
}
|
|
|
@ -1,37 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
// Sticky socket options
|
|
||||||
const (
|
|
||||||
ssoTOS = iota // header field for unicast packet
|
|
||||||
ssoTTL // header field for unicast packet
|
|
||||||
ssoMulticastTTL // header field for multicast packet
|
|
||||||
ssoMulticastInterface // outbound interface for multicast packet
|
|
||||||
ssoMulticastLoopback // loopback for multicast packet
|
|
||||||
ssoReceiveTTL // header field on received packet
|
|
||||||
ssoReceiveDst // header field on received packet
|
|
||||||
ssoReceiveInterface // inbound interface on received packet
|
|
||||||
ssoPacketInfo // incbound or outbound packet path
|
|
||||||
ssoHeaderPrepend // ipv4 header
|
|
||||||
ssoJoinGroup // any-source multicast
|
|
||||||
ssoLeaveGroup // any-source multicast
|
|
||||||
ssoMax
|
|
||||||
)
|
|
||||||
|
|
||||||
// Sticky socket option value types
|
|
||||||
const (
|
|
||||||
ssoTypeByte = iota + 1
|
|
||||||
ssoTypeInt
|
|
||||||
ssoTypeInterface
|
|
||||||
ssoTypeIPMreq
|
|
||||||
ssoTypeIPMreqn
|
|
||||||
)
|
|
||||||
|
|
||||||
// A sockOpt represents a binding for sticky socket option.
|
|
||||||
type sockOpt struct {
|
|
||||||
name int // option name, must be equal or greater than 1
|
|
||||||
typ int // option value type, must be equal or greater than 1
|
|
||||||
}
|
|
|
@ -1,83 +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 darwin dragonfly freebsd netbsd openbsd windows
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import "net"
|
|
||||||
|
|
||||||
func setIPMreqInterface(mreq *sysIPMreq, ifi *net.Interface) error {
|
|
||||||
if ifi == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
ifat, err := ifi.Addrs()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, ifa := range ifat {
|
|
||||||
switch ifa := ifa.(type) {
|
|
||||||
case *net.IPAddr:
|
|
||||||
if ip := ifa.IP.To4(); ip != nil {
|
|
||||||
copy(mreq.Interface[:], ip)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
case *net.IPNet:
|
|
||||||
if ip := ifa.IP.To4(); ip != nil {
|
|
||||||
copy(mreq.Interface[:], ip)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return errNoSuchInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
func netIP4ToInterface(ip net.IP) (*net.Interface, error) {
|
|
||||||
ift, err := net.Interfaces()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for _, ifi := range ift {
|
|
||||||
ifat, err := ifi.Addrs()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for _, ifa := range ifat {
|
|
||||||
switch ifa := ifa.(type) {
|
|
||||||
case *net.IPAddr:
|
|
||||||
if ip.Equal(ifa.IP) {
|
|
||||||
return &ifi, nil
|
|
||||||
}
|
|
||||||
case *net.IPNet:
|
|
||||||
if ip.Equal(ifa.IP) {
|
|
||||||
return &ifi, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, errNoSuchInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
func netInterfaceToIP4(ifi *net.Interface) (net.IP, error) {
|
|
||||||
if ifi == nil {
|
|
||||||
return net.IPv4zero.To4(), nil
|
|
||||||
}
|
|
||||||
ifat, err := ifi.Addrs()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for _, ifa := range ifat {
|
|
||||||
switch ifa := ifa.(type) {
|
|
||||||
case *net.IPAddr:
|
|
||||||
if ip := ifa.IP.To4(); ip != nil {
|
|
||||||
return ip, nil
|
|
||||||
}
|
|
||||||
case *net.IPNet:
|
|
||||||
if ip := ifa.IP.To4(); ip != nil {
|
|
||||||
return ip, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, errNoSuchInterface
|
|
||||||
}
|
|
|
@ -1,21 +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 !darwin,!dragonfly,!freebsd,!netbsd,!openbsd,!windows
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import "net"
|
|
||||||
|
|
||||||
func setsockoptIPMreq(fd, name int, ifi *net.Interface, grp net.IP) error {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func getsockoptInterface(fd, name int) (*net.Interface, error) {
|
|
||||||
return nil, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func setsockoptInterface(fd, name int, ifi *net.Interface) error {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
|
@ -1,46 +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 darwin dragonfly freebsd netbsd openbsd
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hashicorp/go.net/internal/iana"
|
|
||||||
)
|
|
||||||
|
|
||||||
func setsockoptIPMreq(fd, name int, ifi *net.Interface, grp net.IP) error {
|
|
||||||
mreq := sysIPMreq{Multiaddr: [4]byte{grp[0], grp[1], grp[2], grp[3]}}
|
|
||||||
if err := setIPMreqInterface(&mreq, ifi); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&mreq), sysSizeofIPMreq))
|
|
||||||
}
|
|
||||||
|
|
||||||
func getsockoptInterface(fd, name int) (*net.Interface, error) {
|
|
||||||
var b [4]byte
|
|
||||||
l := sysSockoptLen(4)
|
|
||||||
if err := getsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), &l); err != nil {
|
|
||||||
return nil, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
ifi, err := netIP4ToInterface(net.IPv4(b[0], b[1], b[2], b[3]))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return ifi, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setsockoptInterface(fd, name int, ifi *net.Interface) error {
|
|
||||||
ip, err := netInterfaceToIP4(ifi)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var b [4]byte
|
|
||||||
copy(b[:], ip)
|
|
||||||
return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), sysSockoptLen(4)))
|
|
||||||
}
|
|
|
@ -1,45 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hashicorp/go.net/internal/iana"
|
|
||||||
)
|
|
||||||
|
|
||||||
func setsockoptIPMreq(fd syscall.Handle, name int, ifi *net.Interface, grp net.IP) error {
|
|
||||||
mreq := sysIPMreq{Multiaddr: [4]byte{grp[0], grp[1], grp[2], grp[3]}}
|
|
||||||
if err := setIPMreqInterface(&mreq, ifi); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, iana.ProtocolIP, int32(name), (*byte)(unsafe.Pointer(&mreq)), int32(sysSizeofIPMreq)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func getsockoptInterface(fd syscall.Handle, name int) (*net.Interface, error) {
|
|
||||||
var b [4]byte
|
|
||||||
l := int32(4)
|
|
||||||
if err := syscall.Getsockopt(fd, iana.ProtocolIP, int32(name), (*byte)(unsafe.Pointer(&b[0])), &l); err != nil {
|
|
||||||
return nil, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
ifi, err := netIP4ToInterface(net.IPv4(b[0], b[1], b[2], b[3]))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return ifi, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setsockoptInterface(fd syscall.Handle, name int, ifi *net.Interface) error {
|
|
||||||
ip, err := netInterfaceToIP4(ifi)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var b [4]byte
|
|
||||||
copy(b[:], ip)
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, iana.ProtocolIP, int32(name), (*byte)(unsafe.Pointer(&b[0])), 4))
|
|
||||||
}
|
|
|
@ -1,17 +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 !darwin,!freebsd,!linux,!windows
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import "net"
|
|
||||||
|
|
||||||
func getsockoptIPMreqn(fd, name int) (*net.Interface, error) {
|
|
||||||
return nil, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func setsockoptIPMreqn(fd, name int, ifi *net.Interface, grp net.IP) error {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
|
@ -1,42 +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 darwin freebsd linux
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hashicorp/go.net/internal/iana"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getsockoptIPMreqn(fd, name int) (*net.Interface, error) {
|
|
||||||
var mreqn sysIPMreqn
|
|
||||||
l := sysSockoptLen(sysSizeofIPMreqn)
|
|
||||||
if err := getsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&mreqn), &l); err != nil {
|
|
||||||
return nil, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
if mreqn.Ifindex == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
ifi, err := net.InterfaceByIndex(int(mreqn.Ifindex))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return ifi, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setsockoptIPMreqn(fd, name int, ifi *net.Interface, grp net.IP) error {
|
|
||||||
var mreqn sysIPMreqn
|
|
||||||
if ifi != nil {
|
|
||||||
mreqn.Ifindex = int32(ifi.Index)
|
|
||||||
}
|
|
||||||
if grp != nil {
|
|
||||||
mreqn.Multiaddr = [4]byte{grp[0], grp[1], grp[2], grp[3]}
|
|
||||||
}
|
|
||||||
return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&mreqn), sysSizeofIPMreqn))
|
|
||||||
}
|
|
|
@ -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 nacl plan9 solaris
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import "net"
|
|
||||||
|
|
||||||
func getInt(fd int, opt *sockOpt) (int, error) {
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func setInt(fd int, opt *sockOpt, v int) error {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func getInterface(fd int, opt *sockOpt) (*net.Interface, error) {
|
|
||||||
return nil, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func setInterface(fd int, opt *sockOpt, ifi *net.Interface) error {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func setGroup(fd int, opt *sockOpt, ifi *net.Interface, ip net.IP) error {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
|
@ -1,94 +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 darwin dragonfly freebsd linux netbsd openbsd
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hashicorp/go.net/internal/iana"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getInt(fd int, opt *sockOpt) (int, error) {
|
|
||||||
if opt.name < 1 || (opt.typ != ssoTypeByte && opt.typ != ssoTypeInt) {
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
var i int32
|
|
||||||
var b byte
|
|
||||||
p := unsafe.Pointer(&i)
|
|
||||||
l := sysSockoptLen(4)
|
|
||||||
if opt.typ == ssoTypeByte {
|
|
||||||
p = unsafe.Pointer(&b)
|
|
||||||
l = sysSockoptLen(1)
|
|
||||||
}
|
|
||||||
if err := getsockopt(fd, iana.ProtocolIP, opt.name, p, &l); err != nil {
|
|
||||||
return 0, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
if opt.typ == ssoTypeByte {
|
|
||||||
return int(b), nil
|
|
||||||
}
|
|
||||||
return int(i), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setInt(fd int, opt *sockOpt, v int) error {
|
|
||||||
if opt.name < 1 || (opt.typ != ssoTypeByte && opt.typ != ssoTypeInt) {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
i := int32(v)
|
|
||||||
var b byte
|
|
||||||
p := unsafe.Pointer(&i)
|
|
||||||
l := sysSockoptLen(4)
|
|
||||||
if opt.typ == ssoTypeByte {
|
|
||||||
b = byte(v)
|
|
||||||
p = unsafe.Pointer(&b)
|
|
||||||
l = sysSockoptLen(1)
|
|
||||||
}
|
|
||||||
return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolIP, opt.name, p, l))
|
|
||||||
}
|
|
||||||
|
|
||||||
func getInterface(fd int, opt *sockOpt) (*net.Interface, error) {
|
|
||||||
if opt.name < 1 {
|
|
||||||
return nil, errOpNoSupport
|
|
||||||
}
|
|
||||||
switch opt.typ {
|
|
||||||
case ssoTypeInterface:
|
|
||||||
return getsockoptInterface(fd, opt.name)
|
|
||||||
case ssoTypeIPMreqn:
|
|
||||||
return getsockoptIPMreqn(fd, opt.name)
|
|
||||||
default:
|
|
||||||
return nil, errOpNoSupport
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func setInterface(fd int, opt *sockOpt, ifi *net.Interface) error {
|
|
||||||
if opt.name < 1 {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
switch opt.typ {
|
|
||||||
case ssoTypeInterface:
|
|
||||||
return setsockoptInterface(fd, opt.name, ifi)
|
|
||||||
case ssoTypeIPMreqn:
|
|
||||||
return setsockoptIPMreqn(fd, opt.name, ifi, nil)
|
|
||||||
default:
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func setGroup(fd int, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
|
|
||||||
if opt.name < 1 {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
switch opt.typ {
|
|
||||||
case ssoTypeIPMreq:
|
|
||||||
return setsockoptIPMreq(fd, opt.name, ifi, grp)
|
|
||||||
case ssoTypeIPMreqn:
|
|
||||||
return setsockoptIPMreqn(fd, opt.name, ifi, grp)
|
|
||||||
default:
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,55 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hashicorp/go.net/internal/iana"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getInt(fd syscall.Handle, opt *sockOpt) (int, error) {
|
|
||||||
if opt.name < 1 || opt.typ != ssoTypeInt {
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
var i int32
|
|
||||||
l := int32(4)
|
|
||||||
if err := syscall.Getsockopt(fd, iana.ProtocolIP, int32(opt.name), (*byte)(unsafe.Pointer(&i)), &l); err != nil {
|
|
||||||
return 0, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return int(i), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setInt(fd syscall.Handle, opt *sockOpt, v int) error {
|
|
||||||
if opt.name < 1 || opt.typ != ssoTypeInt {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
i := int32(v)
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, iana.ProtocolIP, int32(opt.name), (*byte)(unsafe.Pointer(&i)), 4))
|
|
||||||
}
|
|
||||||
|
|
||||||
func getInterface(fd syscall.Handle, opt *sockOpt) (*net.Interface, error) {
|
|
||||||
if opt.name < 1 || opt.typ != ssoTypeInterface {
|
|
||||||
return nil, errOpNoSupport
|
|
||||||
}
|
|
||||||
return getsockoptInterface(fd, opt.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setInterface(fd syscall.Handle, opt *sockOpt, ifi *net.Interface) error {
|
|
||||||
if opt.name < 1 || opt.typ != ssoTypeInterface {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
return setsockoptInterface(fd, opt.name, ifi)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setGroup(fd syscall.Handle, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
|
|
||||||
if opt.name < 1 || opt.typ != ssoTypeIPMreq {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
return setsockoptIPMreq(fd, opt.name, ifi, grp)
|
|
||||||
}
|
|
|
@ -1,36 +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 dragonfly netbsd
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysSockoptLen int32
|
|
||||||
|
|
||||||
var (
|
|
||||||
ctlOpts = [ctlMax]ctlOpt{
|
|
||||||
ctlTTL: {sysIP_RECVTTL, 1, marshalTTL, parseTTL},
|
|
||||||
ctlDst: {sysIP_RECVDSTADDR, net.IPv4len, marshalDst, parseDst},
|
|
||||||
ctlInterface: {sysIP_RECVIF, syscall.SizeofSockaddrDatalink, marshalInterface, parseInterface},
|
|
||||||
}
|
|
||||||
|
|
||||||
sockOpts = [ssoMax]sockOpt{
|
|
||||||
ssoTOS: {sysIP_TOS, ssoTypeInt},
|
|
||||||
ssoTTL: {sysIP_TTL, ssoTypeInt},
|
|
||||||
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeByte},
|
|
||||||
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeInterface},
|
|
||||||
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeInt},
|
|
||||||
ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
|
|
||||||
ssoReceiveDst: {sysIP_RECVDSTADDR, ssoTypeInt},
|
|
||||||
ssoReceiveInterface: {sysIP_RECVIF, ssoTypeInt},
|
|
||||||
ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
|
|
||||||
ssoJoinGroup: {sysIP_ADD_MEMBERSHIP, ssoTypeIPMreq},
|
|
||||||
ssoLeaveGroup: {sysIP_DROP_MEMBERSHIP, ssoTypeIPMreq},
|
|
||||||
}
|
|
||||||
)
|
|
|
@ -1,64 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysSockoptLen int32
|
|
||||||
|
|
||||||
var (
|
|
||||||
ctlOpts = [ctlMax]ctlOpt{
|
|
||||||
ctlTTL: {sysIP_RECVTTL, 1, marshalTTL, parseTTL},
|
|
||||||
ctlDst: {sysIP_RECVDSTADDR, net.IPv4len, marshalDst, parseDst},
|
|
||||||
ctlInterface: {sysIP_RECVIF, syscall.SizeofSockaddrDatalink, marshalInterface, parseInterface},
|
|
||||||
}
|
|
||||||
|
|
||||||
sockOpts = [ssoMax]sockOpt{
|
|
||||||
ssoTOS: {sysIP_TOS, ssoTypeInt},
|
|
||||||
ssoTTL: {sysIP_TTL, ssoTypeInt},
|
|
||||||
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeByte},
|
|
||||||
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeInterface},
|
|
||||||
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeInt},
|
|
||||||
ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
|
|
||||||
ssoReceiveDst: {sysIP_RECVDSTADDR, ssoTypeInt},
|
|
||||||
ssoReceiveInterface: {sysIP_RECVIF, ssoTypeInt},
|
|
||||||
ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
|
|
||||||
ssoJoinGroup: {sysIP_ADD_MEMBERSHIP, ssoTypeIPMreq},
|
|
||||||
ssoLeaveGroup: {sysIP_DROP_MEMBERSHIP, ssoTypeIPMreq},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// Seems like kern.osreldate is veiled on latest OS X. We use
|
|
||||||
// kern.osrelease instead.
|
|
||||||
osver, err := syscall.Sysctl("kern.osrelease")
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var i int
|
|
||||||
for i = range osver {
|
|
||||||
if osver[i] != '.' {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// The IP_PKTINFO was introduced in OS X 10.7 (Darwin
|
|
||||||
// 11.0.0). See http://support.apple.com/kb/HT1633.
|
|
||||||
if i > 2 || i == 2 && osver[0] >= '1' && osver[1] >= '1' {
|
|
||||||
ctlOpts[ctlPacketInfo].name = sysIP_PKTINFO
|
|
||||||
ctlOpts[ctlPacketInfo].length = sysSizeofInetPktinfo
|
|
||||||
ctlOpts[ctlPacketInfo].marshal = marshalPacketInfo
|
|
||||||
ctlOpts[ctlPacketInfo].parse = parsePacketInfo
|
|
||||||
sockOpts[ssoPacketInfo].name = sysIP_RECVPKTINFO
|
|
||||||
sockOpts[ssoPacketInfo].typ = ssoTypeInt
|
|
||||||
sockOpts[ssoMulticastInterface].typ = ssoTypeIPMreqn
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pi *sysInetPktinfo) setIfindex(i int) {
|
|
||||||
pi.Ifindex = uint32(i)
|
|
||||||
}
|
|
|
@ -1,41 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysSockoptLen int32
|
|
||||||
|
|
||||||
var (
|
|
||||||
ctlOpts = [ctlMax]ctlOpt{
|
|
||||||
ctlTTL: {sysIP_RECVTTL, 1, marshalTTL, parseTTL},
|
|
||||||
ctlDst: {sysIP_RECVDSTADDR, net.IPv4len, marshalDst, parseDst},
|
|
||||||
ctlInterface: {sysIP_RECVIF, syscall.SizeofSockaddrDatalink, marshalInterface, parseInterface},
|
|
||||||
}
|
|
||||||
|
|
||||||
sockOpts = [ssoMax]sockOpt{
|
|
||||||
ssoTOS: {sysIP_TOS, ssoTypeInt},
|
|
||||||
ssoTTL: {sysIP_TTL, ssoTypeInt},
|
|
||||||
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeByte},
|
|
||||||
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeInterface},
|
|
||||||
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeInt},
|
|
||||||
ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
|
|
||||||
ssoReceiveDst: {sysIP_RECVDSTADDR, ssoTypeInt},
|
|
||||||
ssoReceiveInterface: {sysIP_RECVIF, ssoTypeInt},
|
|
||||||
ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
|
|
||||||
ssoJoinGroup: {sysIP_ADD_MEMBERSHIP, ssoTypeIPMreq},
|
|
||||||
ssoLeaveGroup: {sysIP_DROP_MEMBERSHIP, ssoTypeIPMreq},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
freebsdVersion, _ = syscall.SysctlUint32("kern.osreldate")
|
|
||||||
if freebsdVersion >= 1000000 {
|
|
||||||
sockOpts[ssoMulticastInterface].typ = ssoTypeIPMreqn
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
type sysSockoptLen int32
|
|
||||||
|
|
||||||
var (
|
|
||||||
ctlOpts = [ctlMax]ctlOpt{
|
|
||||||
ctlTTL: {sysIP_TTL, 1, marshalTTL, parseTTL},
|
|
||||||
ctlPacketInfo: {sysIP_PKTINFO, sysSizeofInetPktinfo, marshalPacketInfo, parsePacketInfo},
|
|
||||||
}
|
|
||||||
|
|
||||||
sockOpts = [ssoMax]sockOpt{
|
|
||||||
ssoTOS: {sysIP_TOS, ssoTypeInt},
|
|
||||||
ssoTTL: {sysIP_TTL, ssoTypeInt},
|
|
||||||
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeInt},
|
|
||||||
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeIPMreqn},
|
|
||||||
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeInt},
|
|
||||||
ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
|
|
||||||
ssoPacketInfo: {sysIP_PKTINFO, ssoTypeInt},
|
|
||||||
ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
|
|
||||||
ssoJoinGroup: {sysIP_ADD_MEMBERSHIP, ssoTypeIPMreqn},
|
|
||||||
ssoLeaveGroup: {sysIP_DROP_MEMBERSHIP, ssoTypeIPMreqn},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func (pi *sysInetPktinfo) setIfindex(i int) {
|
|
||||||
pi.Ifindex = int32(i)
|
|
||||||
}
|
|
|
@ -1,34 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysSockoptLen int32
|
|
||||||
|
|
||||||
var (
|
|
||||||
ctlOpts = [ctlMax]ctlOpt{
|
|
||||||
ctlTTL: {sysIP_RECVTTL, 1, marshalTTL, parseTTL},
|
|
||||||
ctlDst: {sysIP_RECVDSTADDR, net.IPv4len, marshalDst, parseDst},
|
|
||||||
ctlInterface: {sysIP_RECVIF, syscall.SizeofSockaddrDatalink, marshalInterface, parseInterface},
|
|
||||||
}
|
|
||||||
|
|
||||||
sockOpts = [ssoMax]sockOpt{
|
|
||||||
ssoTOS: {sysIP_TOS, ssoTypeInt},
|
|
||||||
ssoTTL: {sysIP_TTL, ssoTypeInt},
|
|
||||||
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeByte},
|
|
||||||
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeInterface},
|
|
||||||
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeByte},
|
|
||||||
ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
|
|
||||||
ssoReceiveDst: {sysIP_RECVDSTADDR, ssoTypeInt},
|
|
||||||
ssoReceiveInterface: {sysIP_RECVIF, ssoTypeInt},
|
|
||||||
ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
|
|
||||||
ssoJoinGroup: {sysIP_ADD_MEMBERSHIP, ssoTypeIPMreq},
|
|
||||||
ssoLeaveGroup: {sysIP_DROP_MEMBERSHIP, ssoTypeIPMreq},
|
|
||||||
}
|
|
||||||
)
|
|
|
@ -1,15 +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 nacl plan9 solaris
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
type sysSockoptLen int32
|
|
||||||
|
|
||||||
var (
|
|
||||||
ctlOpts = [ctlMax]ctlOpt{}
|
|
||||||
|
|
||||||
sockOpts = [ssoMax]sockOpt{}
|
|
||||||
)
|
|
|
@ -1,61 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
const (
|
|
||||||
// See ws2tcpip.h.
|
|
||||||
sysIP_OPTIONS = 0x1
|
|
||||||
sysIP_HDRINCL = 0x2
|
|
||||||
sysIP_TOS = 0x3
|
|
||||||
sysIP_TTL = 0x4
|
|
||||||
sysIP_MULTICAST_IF = 0x9
|
|
||||||
sysIP_MULTICAST_TTL = 0xa
|
|
||||||
sysIP_MULTICAST_LOOP = 0xb
|
|
||||||
sysIP_ADD_MEMBERSHIP = 0xc
|
|
||||||
sysIP_DROP_MEMBERSHIP = 0xd
|
|
||||||
sysIP_DONTFRAGMENT = 0xe
|
|
||||||
sysIP_ADD_SOURCE_MEMBERSHIP = 0xf
|
|
||||||
sysIP_DROP_SOURCE_MEMBERSHIP = 0x10
|
|
||||||
sysIP_PKTINFO = 0x13
|
|
||||||
|
|
||||||
sysSizeofInetPktinfo = 0x8
|
|
||||||
sysSizeofIPMreq = 0x8
|
|
||||||
sysSizeofIPMreqSource = 0xc
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysInetPktinfo struct {
|
|
||||||
Addr [4]byte
|
|
||||||
Ifindex int32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPMreq struct {
|
|
||||||
Multiaddr [4]byte
|
|
||||||
Interface [4]byte
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPMreqSource struct {
|
|
||||||
Multiaddr [4]byte
|
|
||||||
Sourceaddr [4]byte
|
|
||||||
Interface [4]byte
|
|
||||||
}
|
|
||||||
|
|
||||||
// See http://msdn.microsoft.com/en-us/library/windows/desktop/ms738586(v=vs.85).aspx
|
|
||||||
var (
|
|
||||||
ctlOpts = [ctlMax]ctlOpt{}
|
|
||||||
|
|
||||||
sockOpts = [ssoMax]sockOpt{
|
|
||||||
ssoTOS: {sysIP_TOS, ssoTypeInt},
|
|
||||||
ssoTTL: {sysIP_TTL, ssoTypeInt},
|
|
||||||
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeInt},
|
|
||||||
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeInterface},
|
|
||||||
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeInt},
|
|
||||||
ssoJoinGroup: {sysIP_ADD_MEMBERSHIP, ssoTypeIPMreq},
|
|
||||||
ssoLeaveGroup: {sysIP_DROP_MEMBERSHIP, ssoTypeIPMreq},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func (pi *sysInetPktinfo) setIfindex(i int) {
|
|
||||||
pi.Ifindex = int32(i)
|
|
||||||
}
|
|
|
@ -1,31 +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.
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysGETSOCKOPT = 0xf
|
|
||||||
sysSETSOCKOPT = 0xe
|
|
||||||
)
|
|
||||||
|
|
||||||
func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno)
|
|
||||||
|
|
||||||
func getsockopt(fd, level, name int, v unsafe.Pointer, l *sysSockoptLen) error {
|
|
||||||
if _, errno := socketcall(sysGETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
|
|
||||||
return error(errno)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setsockopt(fd, level, name int, v unsafe.Pointer, l sysSockoptLen) error {
|
|
||||||
if _, errno := socketcall(sysSETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
|
|
||||||
return error(errno)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,26 +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 darwin dragonfly freebsd linux,amd64 linux,arm netbsd openbsd
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getsockopt(fd, level, name int, v unsafe.Pointer, l *sysSockoptLen) error {
|
|
||||||
if _, _, errno := syscall.Syscall6(syscall.SYS_GETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
|
|
||||||
return error(errno)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setsockopt(fd, level, name int, v unsafe.Pointer, l sysSockoptLen) error {
|
|
||||||
if _, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
|
|
||||||
return error(errno)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,8 +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 go1.2
|
|
||||||
|
|
||||||
TEXT ·socketcall(SB),4,$0-36
|
|
||||||
JMP syscall·socketcall(SB)
|
|
|
@ -1,62 +0,0 @@
|
||||||
// Created by cgo -godefs - DO NOT EDIT
|
|
||||||
// cgo -godefs defs_darwin.go
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysIP_OPTIONS = 0x1
|
|
||||||
sysIP_HDRINCL = 0x2
|
|
||||||
sysIP_TOS = 0x3
|
|
||||||
sysIP_TTL = 0x4
|
|
||||||
sysIP_RECVOPTS = 0x5
|
|
||||||
sysIP_RECVRETOPTS = 0x6
|
|
||||||
sysIP_RECVDSTADDR = 0x7
|
|
||||||
sysIP_RETOPTS = 0x8
|
|
||||||
sysIP_RECVIF = 0x14
|
|
||||||
sysIP_STRIPHDR = 0x17
|
|
||||||
sysIP_RECVTTL = 0x18
|
|
||||||
sysIP_BOUND_IF = 0x19
|
|
||||||
sysIP_PKTINFO = 0x1a
|
|
||||||
sysIP_RECVPKTINFO = 0x1a
|
|
||||||
|
|
||||||
sysIP_MULTICAST_IF = 0x9
|
|
||||||
sysIP_MULTICAST_TTL = 0xa
|
|
||||||
sysIP_MULTICAST_LOOP = 0xb
|
|
||||||
sysIP_ADD_MEMBERSHIP = 0xc
|
|
||||||
sysIP_DROP_MEMBERSHIP = 0xd
|
|
||||||
sysIP_MULTICAST_VIF = 0xe
|
|
||||||
sysIP_MULTICAST_IFINDEX = 0x42
|
|
||||||
sysIP_ADD_SOURCE_MEMBERSHIP = 0x46
|
|
||||||
sysIP_DROP_SOURCE_MEMBERSHIP = 0x47
|
|
||||||
sysIP_BLOCK_SOURCE = 0x48
|
|
||||||
sysIP_UNBLOCK_SOURCE = 0x49
|
|
||||||
|
|
||||||
sysSizeofInetPktinfo = 0xc
|
|
||||||
|
|
||||||
sysSizeofIPMreq = 0x8
|
|
||||||
sysSizeofIPMreqn = 0xc
|
|
||||||
sysSizeofIPMreqSource = 0xc
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysInetPktinfo struct {
|
|
||||||
Ifindex uint32
|
|
||||||
Spec_dst [4]byte /* in_addr */
|
|
||||||
Addr [4]byte /* in_addr */
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPMreq struct {
|
|
||||||
Multiaddr [4]byte /* in_addr */
|
|
||||||
Interface [4]byte /* in_addr */
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPMreqn struct {
|
|
||||||
Multiaddr [4]byte /* in_addr */
|
|
||||||
Address [4]byte /* in_addr */
|
|
||||||
Ifindex int32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPMreqSource struct {
|
|
||||||
Multiaddr [4]byte /* in_addr */
|
|
||||||
Sourceaddr [4]byte /* in_addr */
|
|
||||||
Interface [4]byte /* in_addr */
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
// Created by cgo -godefs - DO NOT EDIT
|
|
||||||
// cgo -godefs defs_dragonfly.go
|
|
||||||
|
|
||||||
// +build dragonfly
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysIP_OPTIONS = 0x1
|
|
||||||
sysIP_HDRINCL = 0x2
|
|
||||||
sysIP_TOS = 0x3
|
|
||||||
sysIP_TTL = 0x4
|
|
||||||
sysIP_RECVOPTS = 0x5
|
|
||||||
sysIP_RECVRETOPTS = 0x6
|
|
||||||
sysIP_RECVDSTADDR = 0x7
|
|
||||||
sysIP_RETOPTS = 0x8
|
|
||||||
sysIP_RECVIF = 0x14
|
|
||||||
sysIP_RECVTTL = 0x41
|
|
||||||
|
|
||||||
sysIP_MULTICAST_IF = 0x9
|
|
||||||
sysIP_MULTICAST_TTL = 0xa
|
|
||||||
sysIP_MULTICAST_LOOP = 0xb
|
|
||||||
sysIP_MULTICAST_VIF = 0xe
|
|
||||||
sysIP_ADD_MEMBERSHIP = 0xc
|
|
||||||
sysIP_DROP_MEMBERSHIP = 0xd
|
|
||||||
|
|
||||||
sysSizeofIPMreq = 0x8
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysIPMreq struct {
|
|
||||||
Multiaddr [4]byte /* in_addr */
|
|
||||||
Interface [4]byte /* in_addr */
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
// Created by cgo -godefs - DO NOT EDIT
|
|
||||||
// cgo -godefs defs_freebsd.go
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysIP_OPTIONS = 0x1
|
|
||||||
sysIP_HDRINCL = 0x2
|
|
||||||
sysIP_TOS = 0x3
|
|
||||||
sysIP_TTL = 0x4
|
|
||||||
sysIP_RECVOPTS = 0x5
|
|
||||||
sysIP_RECVRETOPTS = 0x6
|
|
||||||
sysIP_RECVDSTADDR = 0x7
|
|
||||||
sysIP_SENDSRCADDR = 0x7
|
|
||||||
sysIP_RETOPTS = 0x8
|
|
||||||
sysIP_RECVIF = 0x14
|
|
||||||
sysIP_ONESBCAST = 0x17
|
|
||||||
sysIP_BINDANY = 0x18
|
|
||||||
sysIP_RECVTTL = 0x41
|
|
||||||
sysIP_MINTTL = 0x42
|
|
||||||
sysIP_DONTFRAG = 0x43
|
|
||||||
sysIP_RECVTOS = 0x44
|
|
||||||
|
|
||||||
sysIP_MULTICAST_IF = 0x9
|
|
||||||
sysIP_MULTICAST_TTL = 0xa
|
|
||||||
sysIP_MULTICAST_LOOP = 0xb
|
|
||||||
sysIP_ADD_MEMBERSHIP = 0xc
|
|
||||||
sysIP_DROP_MEMBERSHIP = 0xd
|
|
||||||
sysIP_MULTICAST_VIF = 0xe
|
|
||||||
sysIP_ADD_SOURCE_MEMBERSHIP = 0x46
|
|
||||||
sysIP_DROP_SOURCE_MEMBERSHIP = 0x47
|
|
||||||
sysIP_BLOCK_SOURCE = 0x48
|
|
||||||
sysIP_UNBLOCK_SOURCE = 0x49
|
|
||||||
|
|
||||||
sysSizeofIPMreq = 0x8
|
|
||||||
sysSizeofIPMreqn = 0xc
|
|
||||||
sysSizeofIPMreqSource = 0xc
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysIPMreq struct {
|
|
||||||
Multiaddr [4]byte /* in_addr */
|
|
||||||
Interface [4]byte /* in_addr */
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPMreqn struct {
|
|
||||||
Multiaddr [4]byte /* in_addr */
|
|
||||||
Address [4]byte /* in_addr */
|
|
||||||
Ifindex int32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPMreqSource struct {
|
|
||||||
Multiaddr [4]byte /* in_addr */
|
|
||||||
Sourceaddr [4]byte /* in_addr */
|
|
||||||
Interface [4]byte /* in_addr */
|
|
||||||
}
|
|
|
@ -1,94 +0,0 @@
|
||||||
// Created by cgo -godefs - DO NOT EDIT
|
|
||||||
// cgo -godefs defs_linux.go
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysIP_TOS = 0x1
|
|
||||||
sysIP_TTL = 0x2
|
|
||||||
sysIP_HDRINCL = 0x3
|
|
||||||
sysIP_OPTIONS = 0x4
|
|
||||||
sysIP_ROUTER_ALERT = 0x5
|
|
||||||
sysIP_RECVOPTS = 0x6
|
|
||||||
sysIP_RETOPTS = 0x7
|
|
||||||
sysIP_PKTINFO = 0x8
|
|
||||||
sysIP_PKTOPTIONS = 0x9
|
|
||||||
sysIP_MTU_DISCOVER = 0xa
|
|
||||||
sysIP_RECVERR = 0xb
|
|
||||||
sysIP_RECVTTL = 0xc
|
|
||||||
sysIP_RECVTOS = 0xd
|
|
||||||
sysIP_MTU = 0xe
|
|
||||||
sysIP_FREEBIND = 0xf
|
|
||||||
sysIP_TRANSPARENT = 0x13
|
|
||||||
sysIP_RECVRETOPTS = 0x7
|
|
||||||
sysIP_ORIGDSTADDR = 0x14
|
|
||||||
sysIP_RECVORIGDSTADDR = 0x14
|
|
||||||
sysIP_MINTTL = 0x15
|
|
||||||
sysIP_NODEFRAG = 0x16
|
|
||||||
sysIP_UNICAST_IF = 0x32
|
|
||||||
|
|
||||||
sysIP_MULTICAST_IF = 0x20
|
|
||||||
sysIP_MULTICAST_TTL = 0x21
|
|
||||||
sysIP_MULTICAST_LOOP = 0x22
|
|
||||||
sysIP_ADD_MEMBERSHIP = 0x23
|
|
||||||
sysIP_DROP_MEMBERSHIP = 0x24
|
|
||||||
sysIP_UNBLOCK_SOURCE = 0x25
|
|
||||||
sysIP_BLOCK_SOURCE = 0x26
|
|
||||||
sysIP_ADD_SOURCE_MEMBERSHIP = 0x27
|
|
||||||
sysIP_DROP_SOURCE_MEMBERSHIP = 0x28
|
|
||||||
sysIP_MULTICAST_ALL = 0x31
|
|
||||||
|
|
||||||
sysIP_PMTUDISC_DONT = 0x0
|
|
||||||
sysIP_PMTUDISC_WANT = 0x1
|
|
||||||
sysIP_PMTUDISC_DO = 0x2
|
|
||||||
sysIP_PMTUDISC_PROBE = 0x3
|
|
||||||
sysIP_PMTUDISC_INTERFACE = 0x4
|
|
||||||
sysIP_PMTUDISC_OMIT = 0x5
|
|
||||||
|
|
||||||
sysSO_EE_ORIGIN_NONE = 0x0
|
|
||||||
sysSO_EE_ORIGIN_LOCAL = 0x1
|
|
||||||
sysSO_EE_ORIGIN_ICMP = 0x2
|
|
||||||
sysSO_EE_ORIGIN_ICMP6 = 0x3
|
|
||||||
sysSO_EE_ORIGIN_TXSTATUS = 0x4
|
|
||||||
sysSO_EE_ORIGIN_TIMESTAMPING = 0x4
|
|
||||||
|
|
||||||
sysSizeofInetPktinfo = 0xc
|
|
||||||
sysSizeofSockExtendedErr = 0x10
|
|
||||||
|
|
||||||
sysSizeofIPMreq = 0x8
|
|
||||||
sysSizeofIPMreqn = 0xc
|
|
||||||
sysSizeofIPMreqSource = 0xc
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysInetPktinfo struct {
|
|
||||||
Ifindex int32
|
|
||||||
Spec_dst [4]byte /* in_addr */
|
|
||||||
Addr [4]byte /* in_addr */
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysSockExtendedErr struct {
|
|
||||||
Errno uint32
|
|
||||||
Origin uint8
|
|
||||||
Type uint8
|
|
||||||
Code uint8
|
|
||||||
Pad uint8
|
|
||||||
Info uint32
|
|
||||||
Data uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPMreq struct {
|
|
||||||
Multiaddr [4]byte /* in_addr */
|
|
||||||
Interface [4]byte /* in_addr */
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPMreqn struct {
|
|
||||||
Multiaddr [4]byte /* in_addr */
|
|
||||||
Address [4]byte /* in_addr */
|
|
||||||
Ifindex int32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPMreqSource struct {
|
|
||||||
Multiaddr uint32
|
|
||||||
Interface uint32
|
|
||||||
Sourceaddr uint32
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
// Created by cgo -godefs - DO NOT EDIT
|
|
||||||
// cgo -godefs defs_netbsd.go
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysIP_OPTIONS = 0x1
|
|
||||||
sysIP_HDRINCL = 0x2
|
|
||||||
sysIP_TOS = 0x3
|
|
||||||
sysIP_TTL = 0x4
|
|
||||||
sysIP_RECVOPTS = 0x5
|
|
||||||
sysIP_RECVRETOPTS = 0x6
|
|
||||||
sysIP_RECVDSTADDR = 0x7
|
|
||||||
sysIP_RETOPTS = 0x8
|
|
||||||
sysIP_RECVIF = 0x14
|
|
||||||
sysIP_RECVTTL = 0x17
|
|
||||||
|
|
||||||
sysIP_MULTICAST_IF = 0x9
|
|
||||||
sysIP_MULTICAST_TTL = 0xa
|
|
||||||
sysIP_MULTICAST_LOOP = 0xb
|
|
||||||
sysIP_ADD_MEMBERSHIP = 0xc
|
|
||||||
sysIP_DROP_MEMBERSHIP = 0xd
|
|
||||||
|
|
||||||
sysSizeofIPMreq = 0x8
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysIPMreq struct {
|
|
||||||
Multiaddr [4]byte /* in_addr */
|
|
||||||
Interface [4]byte /* in_addr */
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
// Created by cgo -godefs - DO NOT EDIT
|
|
||||||
// cgo -godefs defs_openbsd.go
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysIP_OPTIONS = 0x1
|
|
||||||
sysIP_HDRINCL = 0x2
|
|
||||||
sysIP_TOS = 0x3
|
|
||||||
sysIP_TTL = 0x4
|
|
||||||
sysIP_RECVOPTS = 0x5
|
|
||||||
sysIP_RECVRETOPTS = 0x6
|
|
||||||
sysIP_RECVDSTADDR = 0x7
|
|
||||||
sysIP_RETOPTS = 0x8
|
|
||||||
sysIP_RECVIF = 0x1e
|
|
||||||
sysIP_RECVTTL = 0x1f
|
|
||||||
|
|
||||||
sysIP_MULTICAST_IF = 0x9
|
|
||||||
sysIP_MULTICAST_TTL = 0xa
|
|
||||||
sysIP_MULTICAST_LOOP = 0xb
|
|
||||||
sysIP_ADD_MEMBERSHIP = 0xc
|
|
||||||
sysIP_DROP_MEMBERSHIP = 0xd
|
|
||||||
|
|
||||||
sysSizeofIPMreq = 0x8
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysIPMreq struct {
|
|
||||||
Multiaddr [4]byte /* in_addr */
|
|
||||||
Interface [4]byte /* in_addr */
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
// Created by cgo -godefs - DO NOT EDIT
|
|
||||||
// cgo -godefs defs_solaris.go
|
|
||||||
|
|
||||||
// +build solaris
|
|
||||||
|
|
||||||
package ipv4
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysIP_OPTIONS = 0x1
|
|
||||||
sysIP_HDRINCL = 0x2
|
|
||||||
sysIP_TOS = 0x3
|
|
||||||
sysIP_TTL = 0x4
|
|
||||||
sysIP_RECVOPTS = 0x5
|
|
||||||
sysIP_RECVRETOPTS = 0x6
|
|
||||||
sysIP_RECVDSTADDR = 0x7
|
|
||||||
sysIP_RETOPTS = 0x8
|
|
||||||
sysIP_RECVIF = 0x9
|
|
||||||
sysIP_RECVSLLA = 0xa
|
|
||||||
sysIP_RECVTTL = 0xb
|
|
||||||
sysIP_NEXTHOP = 0x19
|
|
||||||
sysIP_PKTINFO = 0x1a
|
|
||||||
sysIP_RECVPKTINFO = 0x1a
|
|
||||||
sysIP_DONTFRAG = 0x1b
|
|
||||||
sysIP_BOUND_IF = 0x41
|
|
||||||
sysIP_UNSPEC_SRC = 0x42
|
|
||||||
sysIP_BROADCAST_TTL = 0x43
|
|
||||||
sysIP_DHCPINIT_IF = 0x45
|
|
||||||
|
|
||||||
sysIP_MULTICAST_IF = 0x10
|
|
||||||
sysIP_MULTICAST_TTL = 0x11
|
|
||||||
sysIP_MULTICAST_LOOP = 0x12
|
|
||||||
sysIP_ADD_MEMBERSHIP = 0x13
|
|
||||||
sysIP_DROP_MEMBERSHIP = 0x14
|
|
||||||
sysIP_BLOCK_SOURCE = 0x15
|
|
||||||
sysIP_UNBLOCK_SOURCE = 0x16
|
|
||||||
sysIP_ADD_SOURCE_MEMBERSHIP = 0x17
|
|
||||||
sysIP_DROP_SOURCE_MEMBERSHIP = 0x18
|
|
||||||
|
|
||||||
sysSizeofInetPktinfo = 0xc
|
|
||||||
|
|
||||||
sysSizeofIPMreq = 0x8
|
|
||||||
sysSizeofIPMreqSource = 0xc
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysInetPktinfo struct {
|
|
||||||
Ifindex uint32
|
|
||||||
Spec_dst [4]byte /* in_addr */
|
|
||||||
Addr [4]byte /* in_addr */
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPMreq struct {
|
|
||||||
Multiaddr [4]byte /* in_addr */
|
|
||||||
Interface [4]byte /* in_addr */
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPMreqSource struct {
|
|
||||||
Multiaddr [4]byte /* in_addr */
|
|
||||||
Sourceaddr [4]byte /* in_addr */
|
|
||||||
Interface [4]byte /* in_addr */
|
|
||||||
}
|
|
|
@ -1,83 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
errMissingAddress = errors.New("missing address")
|
|
||||||
errInvalidConnType = errors.New("invalid conn type")
|
|
||||||
errNoSuchInterface = errors.New("no such interface")
|
|
||||||
)
|
|
||||||
|
|
||||||
// References:
|
|
||||||
//
|
|
||||||
// RFC 2292 Advanced Sockets API for IPv6
|
|
||||||
// http://tools.ietf.org/html/rfc2292
|
|
||||||
// RFC 2460 Internet Protocol, Version 6 (IPv6) Specification
|
|
||||||
// http://tools.ietf.org/html/rfc2460
|
|
||||||
// RFC 3493 Basic Socket Interface Extensions for IPv6
|
|
||||||
// http://tools.ietf.org/html/rfc3493.html
|
|
||||||
// RFC 3542 Advanced Sockets Application Program Interface (API) for IPv6
|
|
||||||
// http://tools.ietf.org/html/rfc3542
|
|
||||||
//
|
|
||||||
// Note that RFC 3542 obsoletes RFC 2292 but OS X Snow Leopard and the
|
|
||||||
// former still support RFC 2292 only. Please be aware that almost
|
|
||||||
// all protocol implementations prohibit using a combination of RFC
|
|
||||||
// 2292 and RFC 3542 for some practical reasons.
|
|
||||||
|
|
||||||
type rawOpt struct {
|
|
||||||
sync.Mutex
|
|
||||||
cflags ControlFlags
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *rawOpt) set(f ControlFlags) { c.cflags |= f }
|
|
||||||
func (c *rawOpt) clear(f ControlFlags) { c.cflags &^= f }
|
|
||||||
func (c *rawOpt) isset(f ControlFlags) bool { return c.cflags&f != 0 }
|
|
||||||
|
|
||||||
// A ControlFlags represents per packet basis IP-level socket option
|
|
||||||
// control flags.
|
|
||||||
type ControlFlags uint
|
|
||||||
|
|
||||||
const (
|
|
||||||
FlagTrafficClass ControlFlags = 1 << iota // pass the traffic class on the received packet
|
|
||||||
FlagHopLimit // pass the hop limit on the received packet
|
|
||||||
FlagSrc // pass the source address on the received packet
|
|
||||||
FlagDst // pass the destination address on the received packet
|
|
||||||
FlagInterface // pass the interface index on the received packet
|
|
||||||
FlagPathMTU // pass the path MTU on the received packet path
|
|
||||||
)
|
|
||||||
|
|
||||||
// A ControlMessage represents per packet basis IP-level socket
|
|
||||||
// options.
|
|
||||||
type ControlMessage struct {
|
|
||||||
// Receiving socket options: SetControlMessage allows to
|
|
||||||
// receive the options from the protocol stack using ReadFrom
|
|
||||||
// method of PacketConn.
|
|
||||||
//
|
|
||||||
// Specifying socket options: ControlMessage for WriteTo
|
|
||||||
// method of PacketConn allows to send the options to the
|
|
||||||
// protocol stack.
|
|
||||||
//
|
|
||||||
TrafficClass int // traffic class, must be 1 <= value <= 255 when specifying
|
|
||||||
HopLimit int // hop limit, must be 1 <= value <= 255 when specifying
|
|
||||||
Src net.IP // source address, specifying only
|
|
||||||
Dst net.IP // destination address, receiving only
|
|
||||||
IfIndex int // interface index, must be 1 <= value when specifying
|
|
||||||
NextHop net.IP // next hop address, specifying only
|
|
||||||
MTU int // path MTU, receiving only
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cm *ControlMessage) String() string {
|
|
||||||
if cm == nil {
|
|
||||||
return "<nil>"
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("tclass: %#x, hoplim: %v, src: %v, dst: %v, ifindex: %v, nexthop: %v, mtu: %v", cm.TrafficClass, cm.HopLimit, cm.Src, cm.Dst, cm.IfIndex, cm.NextHop, cm.MTU)
|
|
||||||
}
|
|
|
@ -1,151 +0,0 @@
|
||||||
// Copyright 2013 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 darwin
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
const pktinfo = FlagDst | FlagInterface
|
|
||||||
|
|
||||||
func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error {
|
|
||||||
opt.Lock()
|
|
||||||
defer opt.Unlock()
|
|
||||||
if cf&FlagHopLimit != 0 {
|
|
||||||
if err := setIPv6ReceiveHopLimit(fd, on); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if on {
|
|
||||||
opt.set(FlagHopLimit)
|
|
||||||
} else {
|
|
||||||
opt.clear(FlagHopLimit)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if cf&pktinfo != 0 {
|
|
||||||
if err := setIPv6ReceivePacketInfo(fd, on); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if on {
|
|
||||||
opt.set(cf & pktinfo)
|
|
||||||
} else {
|
|
||||||
opt.clear(cf & pktinfo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func newControlMessage(opt *rawOpt) (oob []byte) {
|
|
||||||
opt.Lock()
|
|
||||||
defer opt.Unlock()
|
|
||||||
l, off := 0, 0
|
|
||||||
if opt.isset(FlagHopLimit) {
|
|
||||||
l += syscall.CmsgSpace(4)
|
|
||||||
}
|
|
||||||
if opt.isset(pktinfo) {
|
|
||||||
l += syscall.CmsgSpace(sysSizeofPacketInfo)
|
|
||||||
}
|
|
||||||
if l > 0 {
|
|
||||||
oob = make([]byte, l)
|
|
||||||
if opt.isset(FlagHopLimit) {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
|
|
||||||
m.Level = ianaProtocolIPv6
|
|
||||||
m.Type = sysSockopt2292HopLimit
|
|
||||||
m.SetLen(syscall.CmsgLen(4))
|
|
||||||
off += syscall.CmsgSpace(4)
|
|
||||||
}
|
|
||||||
if opt.isset(pktinfo) {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
|
|
||||||
m.Level = ianaProtocolIPv6
|
|
||||||
m.Type = sysSockopt2292PacketInfo
|
|
||||||
m.SetLen(syscall.CmsgLen(sysSizeofPacketInfo))
|
|
||||||
off += syscall.CmsgSpace(sysSizeofPacketInfo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseControlMessage(b []byte) (*ControlMessage, error) {
|
|
||||||
if len(b) == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
cmsgs, err := syscall.ParseSocketControlMessage(b)
|
|
||||||
if err != nil {
|
|
||||||
return nil, os.NewSyscallError("parse socket control message", err)
|
|
||||||
}
|
|
||||||
cm := &ControlMessage{}
|
|
||||||
for _, m := range cmsgs {
|
|
||||||
if m.Header.Level != ianaProtocolIPv6 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch m.Header.Type {
|
|
||||||
case sysSockopt2292HopLimit:
|
|
||||||
cm.HopLimit = int(*(*byte)(unsafe.Pointer(&m.Data[:1][0])))
|
|
||||||
case sysSockopt2292PacketInfo:
|
|
||||||
pi := (*sysPacketInfo)(unsafe.Pointer(&m.Data[0]))
|
|
||||||
cm.IfIndex = int(pi.IfIndex)
|
|
||||||
cm.Dst = pi.IP[:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cm, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func marshalControlMessage(cm *ControlMessage) (oob []byte) {
|
|
||||||
if cm == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
l, off := 0, 0
|
|
||||||
if cm.HopLimit > 0 {
|
|
||||||
l += syscall.CmsgSpace(4)
|
|
||||||
}
|
|
||||||
pion := false
|
|
||||||
if cm.Src.To4() == nil && cm.Src.To16() != nil || cm.IfIndex != 0 {
|
|
||||||
pion = true
|
|
||||||
l += syscall.CmsgSpace(sysSizeofPacketInfo)
|
|
||||||
}
|
|
||||||
if len(cm.NextHop) == net.IPv6len {
|
|
||||||
l += syscall.CmsgSpace(syscall.SizeofSockaddrInet6)
|
|
||||||
}
|
|
||||||
if l > 0 {
|
|
||||||
oob = make([]byte, l)
|
|
||||||
if cm.HopLimit > 0 {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
|
|
||||||
m.Level = ianaProtocolIPv6
|
|
||||||
m.Type = sysSockopt2292HopLimit
|
|
||||||
m.SetLen(syscall.CmsgLen(4))
|
|
||||||
data := oob[off+syscall.CmsgLen(0):]
|
|
||||||
*(*byte)(unsafe.Pointer(&data[:1][0])) = byte(cm.HopLimit)
|
|
||||||
off += syscall.CmsgSpace(4)
|
|
||||||
}
|
|
||||||
if pion {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
|
|
||||||
m.Level = ianaProtocolIPv6
|
|
||||||
m.Type = sysSockopt2292PacketInfo
|
|
||||||
m.SetLen(syscall.CmsgLen(sysSizeofPacketInfo))
|
|
||||||
pi := (*sysPacketInfo)(unsafe.Pointer(&oob[off+syscall.CmsgLen(0)]))
|
|
||||||
if ip := cm.Src.To16(); ip != nil && ip.To4() == nil {
|
|
||||||
copy(pi.IP[:], ip)
|
|
||||||
}
|
|
||||||
if cm.IfIndex != 0 {
|
|
||||||
pi.IfIndex = uint32(cm.IfIndex)
|
|
||||||
}
|
|
||||||
off += syscall.CmsgSpace(sysSizeofPacketInfo)
|
|
||||||
}
|
|
||||||
if len(cm.NextHop) == net.IPv6len {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
|
|
||||||
m.Level = ianaProtocolIPv6
|
|
||||||
m.Type = sysSockopt2292NextHop
|
|
||||||
m.SetLen(syscall.CmsgLen(syscall.SizeofSockaddrInet6))
|
|
||||||
sa := (*syscall.RawSockaddrInet6)(unsafe.Pointer(&oob[off+syscall.CmsgLen(0)]))
|
|
||||||
setSockaddr(sa, cm.NextHop, cm.IfIndex)
|
|
||||||
off += syscall.CmsgSpace(syscall.SizeofSockaddrInet6)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
// Copyright 2013 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 nacl plan9 solaris
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func newControlMessage(opt *rawOpt) (oob []byte) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseControlMessage(b []byte) (*ControlMessage, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func marshalControlMessage(cm *ControlMessage) (oob []byte) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,210 +0,0 @@
|
||||||
// Copyright 2013 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 dragonfly freebsd linux netbsd openbsd
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
const pktinfo = FlagDst | FlagInterface
|
|
||||||
|
|
||||||
func setControlMessage(fd int, opt *rawOpt, cf ControlFlags, on bool) error {
|
|
||||||
opt.Lock()
|
|
||||||
defer opt.Unlock()
|
|
||||||
if cf&FlagTrafficClass != 0 {
|
|
||||||
if err := setIPv6ReceiveTrafficClass(fd, on); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if on {
|
|
||||||
opt.set(FlagTrafficClass)
|
|
||||||
} else {
|
|
||||||
opt.clear(FlagTrafficClass)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if cf&FlagHopLimit != 0 {
|
|
||||||
if err := setIPv6ReceiveHopLimit(fd, on); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if on {
|
|
||||||
opt.set(FlagHopLimit)
|
|
||||||
} else {
|
|
||||||
opt.clear(FlagHopLimit)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if cf&pktinfo != 0 {
|
|
||||||
if err := setIPv6ReceivePacketInfo(fd, on); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if on {
|
|
||||||
opt.set(cf & pktinfo)
|
|
||||||
} else {
|
|
||||||
opt.clear(cf & pktinfo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if cf&FlagPathMTU != 0 {
|
|
||||||
if err := setIPv6ReceivePathMTU(fd, on); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if on {
|
|
||||||
opt.set(FlagPathMTU)
|
|
||||||
} else {
|
|
||||||
opt.clear(FlagPathMTU)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func newControlMessage(opt *rawOpt) (oob []byte) {
|
|
||||||
opt.Lock()
|
|
||||||
defer opt.Unlock()
|
|
||||||
l, off := 0, 0
|
|
||||||
if opt.isset(FlagTrafficClass) {
|
|
||||||
l += syscall.CmsgSpace(4)
|
|
||||||
}
|
|
||||||
if opt.isset(FlagHopLimit) {
|
|
||||||
l += syscall.CmsgSpace(4)
|
|
||||||
}
|
|
||||||
if opt.isset(pktinfo) {
|
|
||||||
l += syscall.CmsgSpace(sysSizeofPacketInfo)
|
|
||||||
}
|
|
||||||
if opt.isset(FlagPathMTU) {
|
|
||||||
l += syscall.CmsgSpace(sysSizeofMTUInfo)
|
|
||||||
}
|
|
||||||
if l > 0 {
|
|
||||||
oob = make([]byte, l)
|
|
||||||
if opt.isset(FlagTrafficClass) {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
|
|
||||||
m.Level = ianaProtocolIPv6
|
|
||||||
m.Type = sysSockoptReceiveTrafficClass
|
|
||||||
m.SetLen(syscall.CmsgLen(4))
|
|
||||||
off += syscall.CmsgSpace(4)
|
|
||||||
}
|
|
||||||
if opt.isset(FlagHopLimit) {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
|
|
||||||
m.Level = ianaProtocolIPv6
|
|
||||||
m.Type = sysSockoptReceiveHopLimit
|
|
||||||
m.SetLen(syscall.CmsgLen(4))
|
|
||||||
off += syscall.CmsgSpace(4)
|
|
||||||
}
|
|
||||||
if opt.isset(pktinfo) {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
|
|
||||||
m.Level = ianaProtocolIPv6
|
|
||||||
m.Type = sysSockoptReceivePacketInfo
|
|
||||||
m.SetLen(syscall.CmsgLen(sysSizeofPacketInfo))
|
|
||||||
off += syscall.CmsgSpace(sysSizeofPacketInfo)
|
|
||||||
}
|
|
||||||
if opt.isset(FlagPathMTU) {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
|
|
||||||
m.Level = ianaProtocolIPv6
|
|
||||||
m.Type = sysSockoptReceivePathMTU
|
|
||||||
m.SetLen(syscall.CmsgLen(sysSizeofMTUInfo))
|
|
||||||
off += syscall.CmsgSpace(sysSizeofMTUInfo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseControlMessage(b []byte) (*ControlMessage, error) {
|
|
||||||
if len(b) == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
cmsgs, err := syscall.ParseSocketControlMessage(b)
|
|
||||||
if err != nil {
|
|
||||||
return nil, os.NewSyscallError("parse socket control message", err)
|
|
||||||
}
|
|
||||||
cm := &ControlMessage{}
|
|
||||||
for _, m := range cmsgs {
|
|
||||||
if m.Header.Level != ianaProtocolIPv6 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch m.Header.Type {
|
|
||||||
case sysSockoptTrafficClass:
|
|
||||||
cm.TrafficClass = int(*(*byte)(unsafe.Pointer(&m.Data[:1][0])))
|
|
||||||
case sysSockoptHopLimit:
|
|
||||||
cm.HopLimit = int(*(*byte)(unsafe.Pointer(&m.Data[:1][0])))
|
|
||||||
case sysSockoptPacketInfo:
|
|
||||||
pi := (*sysPacketInfo)(unsafe.Pointer(&m.Data[0]))
|
|
||||||
cm.Dst = pi.IP[:]
|
|
||||||
cm.IfIndex = int(pi.IfIndex)
|
|
||||||
case sysSockoptPathMTU:
|
|
||||||
mi := (*sysMTUInfo)(unsafe.Pointer(&m.Data[0]))
|
|
||||||
cm.Dst = mi.Addr.Addr[:]
|
|
||||||
cm.IfIndex = int(mi.Addr.Scope_id)
|
|
||||||
cm.MTU = int(mi.MTU)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cm, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func marshalControlMessage(cm *ControlMessage) (oob []byte) {
|
|
||||||
if cm == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
l, off := 0, 0
|
|
||||||
if cm.TrafficClass > 0 {
|
|
||||||
l += syscall.CmsgSpace(4)
|
|
||||||
}
|
|
||||||
if cm.HopLimit > 0 {
|
|
||||||
l += syscall.CmsgSpace(4)
|
|
||||||
}
|
|
||||||
pion := false
|
|
||||||
if cm.Src.To4() == nil && cm.Src.To16() != nil || cm.IfIndex != 0 {
|
|
||||||
pion = true
|
|
||||||
l += syscall.CmsgSpace(sysSizeofPacketInfo)
|
|
||||||
}
|
|
||||||
if len(cm.NextHop) == net.IPv6len {
|
|
||||||
l += syscall.CmsgSpace(syscall.SizeofSockaddrInet6)
|
|
||||||
}
|
|
||||||
if l > 0 {
|
|
||||||
oob = make([]byte, l)
|
|
||||||
if cm.TrafficClass > 0 {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
|
|
||||||
m.Level = ianaProtocolIPv6
|
|
||||||
m.Type = sysSockoptTrafficClass
|
|
||||||
m.SetLen(syscall.CmsgLen(4))
|
|
||||||
data := oob[off+syscall.CmsgLen(0):]
|
|
||||||
*(*byte)(unsafe.Pointer(&data[:1][0])) = byte(cm.TrafficClass)
|
|
||||||
off += syscall.CmsgSpace(4)
|
|
||||||
}
|
|
||||||
if cm.HopLimit > 0 {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
|
|
||||||
m.Level = ianaProtocolIPv6
|
|
||||||
m.Type = sysSockoptHopLimit
|
|
||||||
m.SetLen(syscall.CmsgLen(4))
|
|
||||||
data := oob[off+syscall.CmsgLen(0):]
|
|
||||||
*(*byte)(unsafe.Pointer(&data[:1][0])) = byte(cm.HopLimit)
|
|
||||||
off += syscall.CmsgSpace(4)
|
|
||||||
}
|
|
||||||
if pion {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
|
|
||||||
m.Level = ianaProtocolIPv6
|
|
||||||
m.Type = sysSockoptPacketInfo
|
|
||||||
m.SetLen(syscall.CmsgLen(sysSizeofPacketInfo))
|
|
||||||
pi := (*sysPacketInfo)(unsafe.Pointer(&oob[off+syscall.CmsgLen(0)]))
|
|
||||||
if ip := cm.Src.To16(); ip != nil && ip.To4() == nil {
|
|
||||||
copy(pi.IP[:], ip)
|
|
||||||
}
|
|
||||||
if cm.IfIndex != 0 {
|
|
||||||
pi.IfIndex = uint32(cm.IfIndex)
|
|
||||||
}
|
|
||||||
off += syscall.CmsgSpace(sysSizeofPacketInfo)
|
|
||||||
}
|
|
||||||
if len(cm.NextHop) == net.IPv6len {
|
|
||||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
|
|
||||||
m.Level = ianaProtocolIPv6
|
|
||||||
m.Type = sysSockoptNextHop
|
|
||||||
m.SetLen(syscall.CmsgLen(syscall.SizeofSockaddrInet6))
|
|
||||||
sa := (*syscall.RawSockaddrInet6)(unsafe.Pointer(&oob[off+syscall.CmsgLen(0)]))
|
|
||||||
setSockaddr(sa, cm.NextHop, cm.IfIndex)
|
|
||||||
off += syscall.CmsgSpace(syscall.SizeofSockaddrInet6)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
func setControlMessage(fd syscall.Handle, opt *rawOpt, cf ControlFlags, on bool) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func newControlMessage(opt *rawOpt) (oob []byte) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseControlMessage(b []byte) (*ControlMessage, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil, syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func marshalControlMessage(cm *ControlMessage) (oob []byte) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,178 +0,0 @@
|
||||||
// Copyright 2013 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 darwin dragonfly freebsd linux netbsd openbsd windows
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MulticastHopLimit returns the hop limit field value for outgoing
|
|
||||||
// multicast packets.
|
|
||||||
func (c *dgramOpt) MulticastHopLimit() (int, error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return ipv6MulticastHopLimit(fd)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMulticastHopLimit sets the hop limit field value for future
|
|
||||||
// outgoing multicast packets.
|
|
||||||
func (c *dgramOpt) SetMulticastHopLimit(hoplim int) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setIPv6MulticastHopLimit(fd, hoplim)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MulticastInterface returns the default interface for multicast
|
|
||||||
// packet transmissions.
|
|
||||||
func (c *dgramOpt) MulticastInterface() (*net.Interface, error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return nil, syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return ipv6MulticastInterface(fd)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMulticastInterface sets the default interface for future
|
|
||||||
// multicast packet transmissions.
|
|
||||||
func (c *dgramOpt) SetMulticastInterface(ifi *net.Interface) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setIPv6MulticastInterface(fd, ifi)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MulticastLoopback reports whether transmitted multicast packets
|
|
||||||
// should be copied and send back to the originator.
|
|
||||||
func (c *dgramOpt) MulticastLoopback() (bool, error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return false, syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return ipv6MulticastLoopback(fd)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMulticastLoopback sets whether transmitted multicast packets
|
|
||||||
// should be copied and send back to the originator.
|
|
||||||
func (c *dgramOpt) SetMulticastLoopback(on bool) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setIPv6MulticastLoopback(fd, on)
|
|
||||||
}
|
|
||||||
|
|
||||||
// JoinGroup joins the group address group on the interface ifi.
|
|
||||||
// It uses the system assigned multicast interface when ifi is nil,
|
|
||||||
// although this is not recommended because the assignment depends on
|
|
||||||
// platforms and sometimes it might require routing configuration.
|
|
||||||
func (c *dgramOpt) JoinGroup(ifi *net.Interface, group net.Addr) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
grp := netAddrToIP16(group)
|
|
||||||
if grp == nil {
|
|
||||||
return errMissingAddress
|
|
||||||
}
|
|
||||||
return joinIPv6Group(fd, ifi, grp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LeaveGroup leaves the group address group on the interface ifi.
|
|
||||||
func (c *dgramOpt) LeaveGroup(ifi *net.Interface, group net.Addr) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
grp := netAddrToIP16(group)
|
|
||||||
if grp == nil {
|
|
||||||
return errMissingAddress
|
|
||||||
}
|
|
||||||
return leaveIPv6Group(fd, ifi, grp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checksum reports whether the kernel will compute, store or verify a
|
|
||||||
// checksum for both incoming and outgoing packets. If on is true, it
|
|
||||||
// returns an offset in bytes into the data of where the checksum
|
|
||||||
// field is located.
|
|
||||||
func (c *dgramOpt) Checksum() (on bool, offset int, err error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return false, 0, syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return false, 0, err
|
|
||||||
}
|
|
||||||
return ipv6Checksum(fd)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetChecksum enables the kernel checksum processing. If on is ture,
|
|
||||||
// the offset should be an offset in bytes into the data of where the
|
|
||||||
// checksum field is located.
|
|
||||||
func (c *dgramOpt) SetChecksum(on bool, offset int) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setIPv6Checksum(fd, on, offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ICMPFilter returns an ICMP filter.
|
|
||||||
func (c *dgramOpt) ICMPFilter() (*ICMPFilter, error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return nil, syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return ipv6ICMPFilter(fd)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetICMPFilter deploys the ICMP filter.
|
|
||||||
func (c *dgramOpt) SetICMPFilter(f *ICMPFilter) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setIPv6ICMPFilter(fd, f)
|
|
||||||
}
|
|
|
@ -1,95 +0,0 @@
|
||||||
// Copyright 2013 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 nacl plan9 solaris
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import "net"
|
|
||||||
|
|
||||||
// MulticastHopLimit returns the hop limit field value for outgoing
|
|
||||||
// multicast packets.
|
|
||||||
func (c *dgramOpt) MulticastHopLimit() (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMulticastHopLimit sets the hop limit field value for future
|
|
||||||
// outgoing multicast packets.
|
|
||||||
func (c *dgramOpt) SetMulticastHopLimit(hoplim int) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// MulticastInterface returns the default interface for multicast
|
|
||||||
// packet transmissions.
|
|
||||||
func (c *dgramOpt) MulticastInterface() (*net.Interface, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMulticastInterface sets the default interface for future
|
|
||||||
// multicast packet transmissions.
|
|
||||||
func (c *dgramOpt) SetMulticastInterface(ifi *net.Interface) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// MulticastLoopback reports whether transmitted multicast packets
|
|
||||||
// should be copied and send back to the originator.
|
|
||||||
func (c *dgramOpt) MulticastLoopback() (bool, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return false, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMulticastLoopback sets whether transmitted multicast packets
|
|
||||||
// should be copied and send back to the originator.
|
|
||||||
func (c *dgramOpt) SetMulticastLoopback(on bool) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// JoinGroup joins the group address group on the interface ifi.
|
|
||||||
// It uses the system assigned multicast interface when ifi is nil,
|
|
||||||
// although this is not recommended because the assignment depends on
|
|
||||||
// platforms and sometimes it might require routing configuration.
|
|
||||||
func (c *dgramOpt) JoinGroup(ifi *net.Interface, group net.Addr) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// LeaveGroup leaves the group address group on the interface ifi.
|
|
||||||
func (c *dgramOpt) LeaveGroup(ifi *net.Interface, group net.Addr) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checksum reports whether the kernel will compute, store or verify a
|
|
||||||
// checksum for both incoming and outgoing packets. If on is true, it
|
|
||||||
// returns an offset in bytes into the data of where the checksum
|
|
||||||
// field is located.
|
|
||||||
func (c *dgramOpt) Checksum() (on bool, offset int, err error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return false, 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetChecksum enables the kernel checksum processing. If on is ture,
|
|
||||||
// the offset should be an offset in bytes into the data of where the
|
|
||||||
// checksum field is located.
|
|
||||||
func (c *dgramOpt) SetChecksum(on bool, offset int) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// ICMPFilter returns an ICMP filter.
|
|
||||||
func (c *dgramOpt) ICMPFilter() (*ICMPFilter, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetICMPFilter deploys the ICMP filter.
|
|
||||||
func (c *dgramOpt) SetICMPFilter(f *ICMPFilter) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
|
@ -1,193 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
// Package ipv6 implements IP-level socket options for the Internet
|
|
||||||
// Protocol version 6.
|
|
||||||
//
|
|
||||||
// The package provides IP-level socket options that allow
|
|
||||||
// manipulation of IPv6 facilities. The IPv6 and socket options for
|
|
||||||
// IPv6 are defined in RFC 2460, RFC 3493 and RFC 3542.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Unicasting
|
|
||||||
//
|
|
||||||
// The options for unicasting are available for net.TCPConn,
|
|
||||||
// net.UDPConn and net.IPConn which are created as network connections
|
|
||||||
// that use the IPv6 transport. When a single TCP connection carrying
|
|
||||||
// a data flow of multiple packets needs to indicate the flow is
|
|
||||||
// important, ipv6.Conn is used to set the traffic class field on the
|
|
||||||
// IPv6 header for each packet.
|
|
||||||
//
|
|
||||||
// ln, err := net.Listen("tcp6", "[::]:1024")
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// defer ln.Close()
|
|
||||||
// for {
|
|
||||||
// c, err := ln.Accept()
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// go func(c net.Conn) {
|
|
||||||
// defer c.Close()
|
|
||||||
//
|
|
||||||
// The outgoing packets will be labeled DiffServ assured forwarding
|
|
||||||
// class 1 low drop precedence, as known as AF11 packets.
|
|
||||||
//
|
|
||||||
// if err := ipv6.NewConn(c).SetTrafficClass(DiffServAF11); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// if _, err := c.Write(data); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// }(c)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Multicasting
|
|
||||||
//
|
|
||||||
// The options for multicasting are available for net.UDPConn and
|
|
||||||
// net.IPconn which are created as network connections that use the
|
|
||||||
// IPv6 transport. A few network facilities must be prepared before
|
|
||||||
// you begin multicasting, at a minimum joining network interfaces and
|
|
||||||
// multicast groups.
|
|
||||||
//
|
|
||||||
// en0, err := net.InterfaceByName("en0")
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// en1, err := net.InterfaceByIndex(911)
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// group := net.ParseIP("ff02::114")
|
|
||||||
//
|
|
||||||
// First, an application listens to an appropriate address with an
|
|
||||||
// appropriate service port.
|
|
||||||
//
|
|
||||||
// c, err := net.ListenPacket("udp6", "[::]:1024")
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// defer c.Close()
|
|
||||||
//
|
|
||||||
// Second, the application joins multicast groups, starts listening to
|
|
||||||
// the groups on the specified network interfaces. Note that the
|
|
||||||
// service port for transport layer protocol does not matter with this
|
|
||||||
// operation as joining groups affects only network and link layer
|
|
||||||
// protocols, such as IPv6 and Ethernet.
|
|
||||||
//
|
|
||||||
// p := ipv6.NewPacketConn(c)
|
|
||||||
// if err := p.JoinGroup(en0, &net.UDPAddr{IP: group}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// if err := p.JoinGroup(en1, &net.UDPAddr{IP: group}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// The application might set per packet control message transmissions
|
|
||||||
// between the protocol stack within the kernel. When the application
|
|
||||||
// needs a destination address on an incoming packet,
|
|
||||||
// SetControlMessage of ipv6.PacketConn is used to enable control
|
|
||||||
// message transmissons.
|
|
||||||
//
|
|
||||||
// if err := p.SetControlMessage(ipv6.FlagDst, true); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// The application could identify whether the received packets are
|
|
||||||
// of interest by using the control message that contains the
|
|
||||||
// destination address of the received packet.
|
|
||||||
//
|
|
||||||
// b := make([]byte, 1500)
|
|
||||||
// for {
|
|
||||||
// n, rcm, src, err := p.ReadFrom(b)
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// if rcm.Dst.IsMulticast() {
|
|
||||||
// if rcm.Dst.Equal(group)
|
|
||||||
// // joined group, do something
|
|
||||||
// } else {
|
|
||||||
// // unknown group, discard
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// The application can also send both unicast and multicast packets.
|
|
||||||
//
|
|
||||||
// p.SetTrafficClass(DiffServCS0)
|
|
||||||
// p.SetHopLimit(16)
|
|
||||||
// if _, err := p.WriteTo(data[:n], nil, src); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// dst := &net.UDPAddr{IP: group, Port: 1024}
|
|
||||||
// wcm := ipv6.ControlMessage{TrafficClass: DiffServCS7, HopLimit: 1}
|
|
||||||
// for _, ifi := range []*net.Interface{en0, en1} {
|
|
||||||
// wcm.IfIndex = ifi.Index
|
|
||||||
// if _, err := p.WriteTo(data[:n], &wcm, dst); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// More multicasting
|
|
||||||
//
|
|
||||||
// An application that uses PacketConn may join multiple multicast
|
|
||||||
// groups. For example, a UDP listener with port 1024 might join two
|
|
||||||
// different groups across over two different network interfaces by
|
|
||||||
// using:
|
|
||||||
//
|
|
||||||
// c, err := net.ListenPacket("udp6", "[::]:1024")
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// defer c.Close()
|
|
||||||
// p := ipv6.NewPacketConn(c)
|
|
||||||
// if err := p.JoinGroup(en0, &net.UDPAddr{IP: net.ParseIP("ff02::1:114")}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// if err := p.JoinGroup(en0, &net.UDPAddr{IP: net.ParseIP("ff02::2:114")}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// if err := p.JoinGroup(en1, &net.UDPAddr{IP: net.ParseIP("ff02::2:114")}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// It is possible for multiple UDP listeners that listen on the same
|
|
||||||
// UDP port to join the same multicast group. The net package will
|
|
||||||
// provide a socket that listens to a wildcard address with reusable
|
|
||||||
// UDP port when an appropriate multicast address prefix is passed to
|
|
||||||
// the net.ListenPacket or net.ListenUDP.
|
|
||||||
//
|
|
||||||
// c1, err := net.ListenPacket("udp6", "[ff02::]:1024")
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// defer c1.Close()
|
|
||||||
// c2, err := net.ListenPacket("udp6", "[ff02::]:1024")
|
|
||||||
// if err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// defer c2.Close()
|
|
||||||
// p1 := ipv6.NewPacketConn(c1)
|
|
||||||
// if err := p1.JoinGroup(en0, &net.UDPAddr{IP: net.ParseIP("ff02::114")}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// p2 := ipv6.NewPacketConn(c2)
|
|
||||||
// if err := p2.JoinGroup(en0, &net.UDPAddr{IP: net.ParseIP("ff02::114")}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Also it is possible for the application to leave or rejoin a
|
|
||||||
// multicast group on the network interface.
|
|
||||||
//
|
|
||||||
// if err := p.LeaveGroup(en0, &net.UDPAddr{IP: net.ParseIP("ff02::114")}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
// if err := p.JoinGroup(en0, &net.UDPAddr{IP: net.ParseIP("ff01::114")}); err != nil {
|
|
||||||
// // error handling
|
|
||||||
// }
|
|
||||||
package ipv6
|
|
|
@ -1,119 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// A Conn represents a network endpoint that uses IPv6 transport.
|
|
||||||
// It allows to set basic IP-level socket options such as traffic
|
|
||||||
// class and hop limit.
|
|
||||||
type Conn struct {
|
|
||||||
genericOpt
|
|
||||||
}
|
|
||||||
|
|
||||||
type genericOpt struct {
|
|
||||||
net.Conn
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *genericOpt) ok() bool { return c != nil && c.Conn != nil }
|
|
||||||
|
|
||||||
// PathMTU returns a path MTU value for the destination associated
|
|
||||||
// with the endpoint.
|
|
||||||
func (c *Conn) PathMTU() (int, error) {
|
|
||||||
if !c.genericOpt.ok() {
|
|
||||||
return 0, syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.genericOpt.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return ipv6PathMTU(fd)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewConn returns a new Conn.
|
|
||||||
func NewConn(c net.Conn) *Conn {
|
|
||||||
return &Conn{
|
|
||||||
genericOpt: genericOpt{Conn: c},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A PacketConn represents a packet network endpoint that uses IPv6
|
|
||||||
// transport. It is used to control several IP-level socket options
|
|
||||||
// including IPv6 header manipulation. It also provides datagram
|
|
||||||
// based network I/O methods specific to the IPv6 and higher layer
|
|
||||||
// protocols such as OSPF, GRE, and UDP.
|
|
||||||
type PacketConn struct {
|
|
||||||
genericOpt
|
|
||||||
dgramOpt
|
|
||||||
payloadHandler
|
|
||||||
}
|
|
||||||
|
|
||||||
type dgramOpt struct {
|
|
||||||
net.PacketConn
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) ok() bool { return c != nil && c.PacketConn != nil }
|
|
||||||
|
|
||||||
// SetControlMessage allows to receive the per packet basis IP-level
|
|
||||||
// socket options.
|
|
||||||
func (c *PacketConn) SetControlMessage(cf ControlFlags, on bool) error {
|
|
||||||
if !c.payloadHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.payloadHandler.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setControlMessage(fd, &c.payloadHandler.rawOpt, cf, on)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDeadline sets the read and write deadlines associated with the
|
|
||||||
// endpoint.
|
|
||||||
func (c *PacketConn) SetDeadline(t time.Time) error {
|
|
||||||
if !c.payloadHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
return c.payloadHandler.SetDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetReadDeadline sets the read deadline associated with the
|
|
||||||
// endpoint.
|
|
||||||
func (c *PacketConn) SetReadDeadline(t time.Time) error {
|
|
||||||
if !c.payloadHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
return c.payloadHandler.SetReadDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetWriteDeadline sets the write deadline associated with the
|
|
||||||
// endpoint.
|
|
||||||
func (c *PacketConn) SetWriteDeadline(t time.Time) error {
|
|
||||||
if !c.payloadHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
return c.payloadHandler.SetWriteDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close closes the endpoint.
|
|
||||||
func (c *PacketConn) Close() error {
|
|
||||||
if !c.payloadHandler.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
return c.payloadHandler.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPacketConn returns a new PacketConn using c as its underlying
|
|
||||||
// transport.
|
|
||||||
func NewPacketConn(c net.PacketConn) *PacketConn {
|
|
||||||
return &PacketConn{
|
|
||||||
genericOpt: genericOpt{Conn: c.(net.Conn)},
|
|
||||||
dgramOpt: dgramOpt{PacketConn: c},
|
|
||||||
payloadHandler: payloadHandler{PacketConn: c},
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
// Copyright 2013 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 darwin dragonfly freebsd linux netbsd openbsd windows
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
// TrafficClass returns the traffic class field value for outgoing
|
|
||||||
// packets.
|
|
||||||
func (c *genericOpt) TrafficClass() (int, error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return ipv6TrafficClass(fd)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetTrafficClass sets the traffic class field value for future
|
|
||||||
// outgoing packets.
|
|
||||||
func (c *genericOpt) SetTrafficClass(tclass int) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setIPv6TrafficClass(fd, tclass)
|
|
||||||
}
|
|
||||||
|
|
||||||
// HopLimit returns the hop limit field value for outgoing packets.
|
|
||||||
func (c *genericOpt) HopLimit() (int, error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return ipv6HopLimit(fd)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetHopLimit sets the hop limit field value for future outgoing
|
|
||||||
// packets.
|
|
||||||
func (c *genericOpt) SetHopLimit(hoplim int) error {
|
|
||||||
if !c.ok() {
|
|
||||||
return syscall.EINVAL
|
|
||||||
}
|
|
||||||
fd, err := c.sysfd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return setIPv6HopLimit(fd, hoplim)
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
// Copyright 2013 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 nacl plan9 solaris
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
// TrafficClass returns the traffic class field value for outgoing
|
|
||||||
// packets.
|
|
||||||
func (c *genericOpt) TrafficClass() (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetTrafficClass sets the traffic class field value for future
|
|
||||||
// outgoing packets.
|
|
||||||
func (c *genericOpt) SetTrafficClass(tclass int) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// HopLimit returns the hop limit field value for outgoing packets.
|
|
||||||
func (c *genericOpt) HopLimit() (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetHopLimit sets the hop limit field value for future outgoing
|
|
||||||
// packets.
|
|
||||||
func (c *genericOpt) SetHopLimit(hoplim int) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"net"
|
|
||||||
)
|
|
||||||
|
|
||||||
var errOpNoSupport = errors.New("operation not supported")
|
|
||||||
|
|
||||||
func boolint(b bool) int {
|
|
||||||
if b {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func netAddrToIP16(a net.Addr) net.IP {
|
|
||||||
switch v := a.(type) {
|
|
||||||
case *net.UDPAddr:
|
|
||||||
if ip := v.IP.To16(); ip != nil && ip.To4() == nil {
|
|
||||||
return ip
|
|
||||||
}
|
|
||||||
case *net.IPAddr:
|
|
||||||
if ip := v.IP.To16(); ip != nil && ip.To4() == nil {
|
|
||||||
return ip
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
// Copyright 2013 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 nacl plan9 solaris
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
func (c *genericOpt) sysfd() (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) sysfd() (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *payloadHandler) sysfd() (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
// Copyright 2013 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 darwin dragonfly freebsd linux netbsd openbsd
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *genericOpt) sysfd() (int, error) {
|
|
||||||
switch p := c.Conn.(type) {
|
|
||||||
case *net.TCPConn, *net.UDPConn, *net.IPConn:
|
|
||||||
return sysfd(p)
|
|
||||||
}
|
|
||||||
return 0, errInvalidConnType
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) sysfd() (int, error) {
|
|
||||||
switch p := c.PacketConn.(type) {
|
|
||||||
case *net.UDPConn, *net.IPConn:
|
|
||||||
return sysfd(p.(net.Conn))
|
|
||||||
}
|
|
||||||
return 0, errInvalidConnType
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *payloadHandler) sysfd() (int, error) {
|
|
||||||
return sysfd(c.PacketConn.(net.Conn))
|
|
||||||
}
|
|
||||||
|
|
||||||
func sysfd(c net.Conn) (int, error) {
|
|
||||||
cv := reflect.ValueOf(c)
|
|
||||||
switch ce := cv.Elem(); ce.Kind() {
|
|
||||||
case reflect.Struct:
|
|
||||||
nfd := ce.FieldByName("conn").FieldByName("fd")
|
|
||||||
switch fe := nfd.Elem(); fe.Kind() {
|
|
||||||
case reflect.Struct:
|
|
||||||
fd := fe.FieldByName("sysfd")
|
|
||||||
return int(fd.Int()), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0, errInvalidConnType
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"reflect"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *genericOpt) sysfd() (syscall.Handle, error) {
|
|
||||||
switch p := c.Conn.(type) {
|
|
||||||
case *net.TCPConn, *net.UDPConn, *net.IPConn:
|
|
||||||
return sysfd(p)
|
|
||||||
}
|
|
||||||
return syscall.InvalidHandle, errInvalidConnType
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *dgramOpt) sysfd() (syscall.Handle, error) {
|
|
||||||
switch p := c.PacketConn.(type) {
|
|
||||||
case *net.UDPConn, *net.IPConn:
|
|
||||||
return sysfd(p.(net.Conn))
|
|
||||||
}
|
|
||||||
return syscall.InvalidHandle, errInvalidConnType
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *payloadHandler) sysfd() (syscall.Handle, error) {
|
|
||||||
return sysfd(c.PacketConn.(net.Conn))
|
|
||||||
}
|
|
||||||
|
|
||||||
func sysfd(c net.Conn) (syscall.Handle, error) {
|
|
||||||
cv := reflect.ValueOf(c)
|
|
||||||
switch ce := cv.Elem(); ce.Kind() {
|
|
||||||
case reflect.Struct:
|
|
||||||
netfd := ce.FieldByName("conn").FieldByName("fd")
|
|
||||||
switch fe := netfd.Elem(); fe.Kind() {
|
|
||||||
case reflect.Struct:
|
|
||||||
fd := fe.FieldByName("sysfd")
|
|
||||||
return syscall.Handle(fd.Uint()), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return syscall.InvalidHandle, errInvalidConnType
|
|
||||||
}
|
|
|
@ -1,224 +0,0 @@
|
||||||
// go run gen.go
|
|
||||||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
// Internet Control Message Protocol version 6 (ICMPv6) Parameters, Updated: 2013-07-03
|
|
||||||
const (
|
|
||||||
ICMPTypeDestinationUnreachable ICMPType = 1 // Destination Unreachable
|
|
||||||
ICMPTypePacketTooBig ICMPType = 2 // Packet Too Big
|
|
||||||
ICMPTypeTimeExceeded ICMPType = 3 // Time Exceeded
|
|
||||||
ICMPTypeParameterProblem ICMPType = 4 // Parameter Problem
|
|
||||||
ICMPTypeEchoRequest ICMPType = 128 // Echo Request
|
|
||||||
ICMPTypeEchoReply ICMPType = 129 // Echo Reply
|
|
||||||
ICMPTypeMulticastListenerQuery ICMPType = 130 // Multicast Listener Query
|
|
||||||
ICMPTypeMulticastListenerReport ICMPType = 131 // Multicast Listener Report
|
|
||||||
ICMPTypeMulticastListenerDone ICMPType = 132 // Multicast Listener Done
|
|
||||||
ICMPTypeRouterSolicitation ICMPType = 133 // Router Solicitation
|
|
||||||
ICMPTypeRouterAdvertisement ICMPType = 134 // Router Advertisement
|
|
||||||
ICMPTypeNeighborSolicitation ICMPType = 135 // Neighbor Solicitation
|
|
||||||
ICMPTypeNeighborAdvertisement ICMPType = 136 // Neighbor Advertisement
|
|
||||||
ICMPTypeRedirect ICMPType = 137 // Redirect Message
|
|
||||||
ICMPTypeRouterRenumbering ICMPType = 138 // Router Renumbering
|
|
||||||
ICMPTypeNodeInformationQuery ICMPType = 139 // ICMP Node Information Query
|
|
||||||
ICMPTypeNodeInformationResponse ICMPType = 140 // ICMP Node Information Response
|
|
||||||
ICMPTypeInverseNeighborDiscoverySolicitation ICMPType = 141 // Inverse Neighbor Discovery Solicitation Message
|
|
||||||
ICMPTypeInverseNeighborDiscoveryAdvertisement ICMPType = 142 // Inverse Neighbor Discovery Advertisement Message
|
|
||||||
ICMPTypeVersion2MulticastListenerReport ICMPType = 143 // Version 2 Multicast Listener Report
|
|
||||||
ICMPTypeHomeAgentAddressDiscoveryRequest ICMPType = 144 // Home Agent Address Discovery Request Message
|
|
||||||
ICMPTypeHomeAgentAddressDiscoveryReply ICMPType = 145 // Home Agent Address Discovery Reply Message
|
|
||||||
ICMPTypeMobilePrefixSolicitation ICMPType = 146 // Mobile Prefix Solicitation
|
|
||||||
ICMPTypeMobilePrefixAdvertisement ICMPType = 147 // Mobile Prefix Advertisement
|
|
||||||
ICMPTypeCertificationPathSolicitation ICMPType = 148 // Certification Path Solicitation Message
|
|
||||||
ICMPTypeCertificationPathAdvertisement ICMPType = 149 // Certification Path Advertisement Message
|
|
||||||
ICMPTypeMulticastRouterAdvertisement ICMPType = 151 // Multicast Router Advertisement
|
|
||||||
ICMPTypeMulticastRouterSolicitation ICMPType = 152 // Multicast Router Solicitation
|
|
||||||
ICMPTypeMulticastRouterTermination ICMPType = 153 // Multicast Router Termination
|
|
||||||
ICMPTypeFMIPv6 ICMPType = 154 // FMIPv6 Messages
|
|
||||||
ICMPTypeRPLControl ICMPType = 155 // RPL Control Message
|
|
||||||
ICMPTypeILNPv6LocatorUpdate ICMPType = 156 // ILNPv6 Locator Update Message
|
|
||||||
ICMPTypeDuplicateAddressRequest ICMPType = 157 // Duplicate Address Request
|
|
||||||
ICMPTypeDuplicateAddressConfirmation ICMPType = 158 // Duplicate Address Confirmation
|
|
||||||
)
|
|
||||||
|
|
||||||
// Internet Control Message Protocol version 6 (ICMPv6) Parameters, Updated: 2013-07-03
|
|
||||||
var icmpTypes = map[ICMPType]string{
|
|
||||||
1: "destination unreachable",
|
|
||||||
2: "packet too big",
|
|
||||||
3: "time exceeded",
|
|
||||||
4: "parameter problem",
|
|
||||||
128: "echo request",
|
|
||||||
129: "echo reply",
|
|
||||||
130: "multicast listener query",
|
|
||||||
131: "multicast listener report",
|
|
||||||
132: "multicast listener done",
|
|
||||||
133: "router solicitation",
|
|
||||||
134: "router advertisement",
|
|
||||||
135: "neighbor solicitation",
|
|
||||||
136: "neighbor advertisement",
|
|
||||||
137: "redirect message",
|
|
||||||
138: "router renumbering",
|
|
||||||
139: "icmp node information query",
|
|
||||||
140: "icmp node information response",
|
|
||||||
141: "inverse neighbor discovery solicitation message",
|
|
||||||
142: "inverse neighbor discovery advertisement message",
|
|
||||||
143: "version 2 multicast listener report",
|
|
||||||
144: "home agent address discovery request message",
|
|
||||||
145: "home agent address discovery reply message",
|
|
||||||
146: "mobile prefix solicitation",
|
|
||||||
147: "mobile prefix advertisement",
|
|
||||||
148: "certification path solicitation message",
|
|
||||||
149: "certification path advertisement message",
|
|
||||||
151: "multicast router advertisement",
|
|
||||||
152: "multicast router solicitation",
|
|
||||||
153: "multicast router termination",
|
|
||||||
154: "fmipv6 messages",
|
|
||||||
155: "rpl control message",
|
|
||||||
156: "ilnpv6 locator update message",
|
|
||||||
157: "duplicate address request",
|
|
||||||
158: "duplicate address confirmation",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Protocol Numbers, Updated: 2013-02-17
|
|
||||||
const (
|
|
||||||
ianaProtocolHOPOPT = 0 // IPv6 Hop-by-Hop Option
|
|
||||||
ianaProtocolICMP = 1 // Internet Control Message
|
|
||||||
ianaProtocolIGMP = 2 // Internet Group Management
|
|
||||||
ianaProtocolGGP = 3 // Gateway-to-Gateway
|
|
||||||
ianaProtocolIPv4 = 4 // IPv4 encapsulation
|
|
||||||
ianaProtocolST = 5 // Stream
|
|
||||||
ianaProtocolTCP = 6 // Transmission Control
|
|
||||||
ianaProtocolCBT = 7 // CBT
|
|
||||||
ianaProtocolEGP = 8 // Exterior Gateway Protocol
|
|
||||||
ianaProtocolIGP = 9 // any private interior gateway (used by Cisco for their IGRP)
|
|
||||||
ianaProtocolBBNRCCMON = 10 // BBN RCC Monitoring
|
|
||||||
ianaProtocolNVPII = 11 // Network Voice Protocol
|
|
||||||
ianaProtocolPUP = 12 // PUP
|
|
||||||
ianaProtocolARGUS = 13 // ARGUS
|
|
||||||
ianaProtocolEMCON = 14 // EMCON
|
|
||||||
ianaProtocolXNET = 15 // Cross Net Debugger
|
|
||||||
ianaProtocolCHAOS = 16 // Chaos
|
|
||||||
ianaProtocolUDP = 17 // User Datagram
|
|
||||||
ianaProtocolMUX = 18 // Multiplexing
|
|
||||||
ianaProtocolDCNMEAS = 19 // DCN Measurement Subsystems
|
|
||||||
ianaProtocolHMP = 20 // Host Monitoring
|
|
||||||
ianaProtocolPRM = 21 // Packet Radio Measurement
|
|
||||||
ianaProtocolXNSIDP = 22 // XEROX NS IDP
|
|
||||||
ianaProtocolTRUNK1 = 23 // Trunk-1
|
|
||||||
ianaProtocolTRUNK2 = 24 // Trunk-2
|
|
||||||
ianaProtocolLEAF1 = 25 // Leaf-1
|
|
||||||
ianaProtocolLEAF2 = 26 // Leaf-2
|
|
||||||
ianaProtocolRDP = 27 // Reliable Data Protocol
|
|
||||||
ianaProtocolIRTP = 28 // Internet Reliable Transaction
|
|
||||||
ianaProtocolISOTP4 = 29 // ISO Transport Protocol Class 4
|
|
||||||
ianaProtocolNETBLT = 30 // Bulk Data Transfer Protocol
|
|
||||||
ianaProtocolMFENSP = 31 // MFE Network Services Protocol
|
|
||||||
ianaProtocolMERITINP = 32 // MERIT Internodal Protocol
|
|
||||||
ianaProtocolDCCP = 33 // Datagram Congestion Control Protocol
|
|
||||||
ianaProtocol3PC = 34 // Third Party Connect Protocol
|
|
||||||
ianaProtocolIDPR = 35 // Inter-Domain Policy Routing Protocol
|
|
||||||
ianaProtocolXTP = 36 // XTP
|
|
||||||
ianaProtocolDDP = 37 // Datagram Delivery Protocol
|
|
||||||
ianaProtocolIDPRCMTP = 38 // IDPR Control Message Transport Proto
|
|
||||||
ianaProtocolTPPP = 39 // TP++ Transport Protocol
|
|
||||||
ianaProtocolIL = 40 // IL Transport Protocol
|
|
||||||
ianaProtocolIPv6 = 41 // IPv6 encapsulation
|
|
||||||
ianaProtocolSDRP = 42 // Source Demand Routing Protocol
|
|
||||||
ianaProtocolIPv6Route = 43 // Routing Header for IPv6
|
|
||||||
ianaProtocolIPv6Frag = 44 // Fragment Header for IPv6
|
|
||||||
ianaProtocolIDRP = 45 // Inter-Domain Routing Protocol
|
|
||||||
ianaProtocolRSVP = 46 // Reservation Protocol
|
|
||||||
ianaProtocolGRE = 47 // Generic Routing Encapsulation
|
|
||||||
ianaProtocolDSR = 48 // Dynamic Source Routing Protocol
|
|
||||||
ianaProtocolBNA = 49 // BNA
|
|
||||||
ianaProtocolESP = 50 // Encap Security Payload
|
|
||||||
ianaProtocolAH = 51 // Authentication Header
|
|
||||||
ianaProtocolINLSP = 52 // Integrated Net Layer Security TUBA
|
|
||||||
ianaProtocolSWIPE = 53 // IP with Encryption
|
|
||||||
ianaProtocolNARP = 54 // NBMA Address Resolution Protocol
|
|
||||||
ianaProtocolMOBILE = 55 // IP Mobility
|
|
||||||
ianaProtocolTLSP = 56 // Transport Layer Security Protocol using Kryptonet key management
|
|
||||||
ianaProtocolSKIP = 57 // SKIP
|
|
||||||
ianaProtocolIPv6ICMP = 58 // ICMP for IPv6
|
|
||||||
ianaProtocolIPv6NoNxt = 59 // No Next Header for IPv6
|
|
||||||
ianaProtocolIPv6Opts = 60 // Destination Options for IPv6
|
|
||||||
ianaProtocolCFTP = 62 // CFTP
|
|
||||||
ianaProtocolSATEXPAK = 64 // SATNET and Backroom EXPAK
|
|
||||||
ianaProtocolKRYPTOLAN = 65 // Kryptolan
|
|
||||||
ianaProtocolRVD = 66 // MIT Remote Virtual Disk Protocol
|
|
||||||
ianaProtocolIPPC = 67 // Internet Pluribus Packet Core
|
|
||||||
ianaProtocolSATMON = 69 // SATNET Monitoring
|
|
||||||
ianaProtocolVISA = 70 // VISA Protocol
|
|
||||||
ianaProtocolIPCV = 71 // Internet Packet Core Utility
|
|
||||||
ianaProtocolCPNX = 72 // Computer Protocol Network Executive
|
|
||||||
ianaProtocolCPHB = 73 // Computer Protocol Heart Beat
|
|
||||||
ianaProtocolWSN = 74 // Wang Span Network
|
|
||||||
ianaProtocolPVP = 75 // Packet Video Protocol
|
|
||||||
ianaProtocolBRSATMON = 76 // Backroom SATNET Monitoring
|
|
||||||
ianaProtocolSUNND = 77 // SUN ND PROTOCOL-Temporary
|
|
||||||
ianaProtocolWBMON = 78 // WIDEBAND Monitoring
|
|
||||||
ianaProtocolWBEXPAK = 79 // WIDEBAND EXPAK
|
|
||||||
ianaProtocolISOIP = 80 // ISO Internet Protocol
|
|
||||||
ianaProtocolVMTP = 81 // VMTP
|
|
||||||
ianaProtocolSECUREVMTP = 82 // SECURE-VMTP
|
|
||||||
ianaProtocolVINES = 83 // VINES
|
|
||||||
ianaProtocolTTP = 84 // TTP
|
|
||||||
ianaProtocolIPTM = 84 // Protocol Internet Protocol Traffic Manager
|
|
||||||
ianaProtocolNSFNETIGP = 85 // NSFNET-IGP
|
|
||||||
ianaProtocolDGP = 86 // Dissimilar Gateway Protocol
|
|
||||||
ianaProtocolTCF = 87 // TCF
|
|
||||||
ianaProtocolEIGRP = 88 // EIGRP
|
|
||||||
ianaProtocolOSPFIGP = 89 // OSPFIGP
|
|
||||||
ianaProtocolSpriteRPC = 90 // Sprite RPC Protocol
|
|
||||||
ianaProtocolLARP = 91 // Locus Address Resolution Protocol
|
|
||||||
ianaProtocolMTP = 92 // Multicast Transport Protocol
|
|
||||||
ianaProtocolAX25 = 93 // AX.25 Frames
|
|
||||||
ianaProtocolIPIP = 94 // IP-within-IP Encapsulation Protocol
|
|
||||||
ianaProtocolMICP = 95 // Mobile Internetworking Control Pro.
|
|
||||||
ianaProtocolSCCSP = 96 // Semaphore Communications Sec. Pro.
|
|
||||||
ianaProtocolETHERIP = 97 // Ethernet-within-IP Encapsulation
|
|
||||||
ianaProtocolENCAP = 98 // Encapsulation Header
|
|
||||||
ianaProtocolGMTP = 100 // GMTP
|
|
||||||
ianaProtocolIFMP = 101 // Ipsilon Flow Management Protocol
|
|
||||||
ianaProtocolPNNI = 102 // PNNI over IP
|
|
||||||
ianaProtocolPIM = 103 // Protocol Independent Multicast
|
|
||||||
ianaProtocolARIS = 104 // ARIS
|
|
||||||
ianaProtocolSCPS = 105 // SCPS
|
|
||||||
ianaProtocolQNX = 106 // QNX
|
|
||||||
ianaProtocolAN = 107 // Active Networks
|
|
||||||
ianaProtocolIPComp = 108 // IP Payload Compression Protocol
|
|
||||||
ianaProtocolSNP = 109 // Sitara Networks Protocol
|
|
||||||
ianaProtocolCompaqPeer = 110 // Compaq Peer Protocol
|
|
||||||
ianaProtocolIPXinIP = 111 // IPX in IP
|
|
||||||
ianaProtocolVRRP = 112 // Virtual Router Redundancy Protocol
|
|
||||||
ianaProtocolPGM = 113 // PGM Reliable Transport Protocol
|
|
||||||
ianaProtocolL2TP = 115 // Layer Two Tunneling Protocol
|
|
||||||
ianaProtocolDDX = 116 // D-II Data Exchange (DDX)
|
|
||||||
ianaProtocolIATP = 117 // Interactive Agent Transfer Protocol
|
|
||||||
ianaProtocolSTP = 118 // Schedule Transfer Protocol
|
|
||||||
ianaProtocolSRP = 119 // SpectraLink Radio Protocol
|
|
||||||
ianaProtocolUTI = 120 // UTI
|
|
||||||
ianaProtocolSMP = 121 // Simple Message Protocol
|
|
||||||
ianaProtocolSM = 122 // SM
|
|
||||||
ianaProtocolPTP = 123 // Performance Transparency Protocol
|
|
||||||
ianaProtocolISIS = 124 // ISIS over IPv4
|
|
||||||
ianaProtocolFIRE = 125 // FIRE
|
|
||||||
ianaProtocolCRTP = 126 // Combat Radio Transport Protocol
|
|
||||||
ianaProtocolCRUDP = 127 // Combat Radio User Datagram
|
|
||||||
ianaProtocolSSCOPMCE = 128 // SSCOPMCE
|
|
||||||
ianaProtocolIPLT = 129 // IPLT
|
|
||||||
ianaProtocolSPS = 130 // Secure Packet Shield
|
|
||||||
ianaProtocolPIPE = 131 // Private IP Encapsulation within IP
|
|
||||||
ianaProtocolSCTP = 132 // Stream Control Transmission Protocol
|
|
||||||
ianaProtocolFC = 133 // Fibre Channel
|
|
||||||
ianaProtocolRSVPE2EIGNORE = 134 // RSVP-E2E-IGNORE
|
|
||||||
ianaProtocolMobilityHeader = 135 // Mobility Header
|
|
||||||
ianaProtocolUDPLite = 136 // UDPLite
|
|
||||||
ianaProtocolMPLSinIP = 137 // MPLS-in-IP
|
|
||||||
ianaProtocolMANET = 138 // MANET Protocols
|
|
||||||
ianaProtocolHIP = 139 // Host Identity Protocol
|
|
||||||
ianaProtocolShim6 = 140 // Shim6 Protocol
|
|
||||||
ianaProtocolWESP = 141 // Wrapped Encapsulating Security Payload
|
|
||||||
ianaProtocolROHC = 142 // Robust Header Compression
|
|
||||||
ianaProtocolReserved = 255 // Reserved
|
|
||||||
)
|
|
|
@ -1,47 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import "sync"
|
|
||||||
|
|
||||||
// An ICMPType represents a type of ICMP message.
|
|
||||||
type ICMPType int
|
|
||||||
|
|
||||||
func (typ ICMPType) String() string {
|
|
||||||
s, ok := icmpTypes[typ]
|
|
||||||
if !ok {
|
|
||||||
return "<nil>"
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// An ICMPFilter represents an ICMP message filter for incoming
|
|
||||||
// packets.
|
|
||||||
type ICMPFilter struct {
|
|
||||||
mu sync.RWMutex
|
|
||||||
sysICMPFilter
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set sets the ICMP type and filter action to the filter.
|
|
||||||
func (f *ICMPFilter) Set(typ ICMPType, block bool) {
|
|
||||||
f.mu.Lock()
|
|
||||||
f.set(typ, block)
|
|
||||||
f.mu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetAll sets the filter action to the filter.
|
|
||||||
func (f *ICMPFilter) SetAll(block bool) {
|
|
||||||
f.mu.Lock()
|
|
||||||
f.setAll(block)
|
|
||||||
f.mu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// WillBlock reports whether the ICMP type will be blocked.
|
|
||||||
func (f *ICMPFilter) WillBlock(typ ICMPType) bool {
|
|
||||||
f.mu.RLock()
|
|
||||||
ok := f.willBlock(typ)
|
|
||||||
f.mu.RUnlock()
|
|
||||||
return ok
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
// Copyright 2013 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 darwin dragonfly freebsd netbsd openbsd
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
type sysICMPFilter struct {
|
|
||||||
Filt [8]uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *sysICMPFilter) set(typ ICMPType, block bool) {
|
|
||||||
if block {
|
|
||||||
f.Filt[typ>>5] &^= 1 << (uint32(typ) & 31)
|
|
||||||
} else {
|
|
||||||
f.Filt[typ>>5] |= 1 << (uint32(typ) & 31)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *sysICMPFilter) setAll(block bool) {
|
|
||||||
for i := range f.Filt {
|
|
||||||
if block {
|
|
||||||
f.Filt[i] = 0
|
|
||||||
} else {
|
|
||||||
f.Filt[i] = 1<<32 - 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *sysICMPFilter) willBlock(typ ICMPType) bool {
|
|
||||||
return f.Filt[typ>>5]&(1<<(uint32(typ)&31)) == 0
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
type sysICMPFilter struct {
|
|
||||||
Data [8]uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *sysICMPFilter) set(typ ICMPType, block bool) {
|
|
||||||
if block {
|
|
||||||
f.Data[typ>>5] |= 1 << (uint32(typ) & 31)
|
|
||||||
} else {
|
|
||||||
f.Data[typ>>5] &^= 1 << (uint32(typ) & 31)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *sysICMPFilter) setAll(block bool) {
|
|
||||||
for i := range f.Data {
|
|
||||||
if block {
|
|
||||||
f.Data[i] = 1<<32 - 1
|
|
||||||
} else {
|
|
||||||
f.Data[i] = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *sysICMPFilter) willBlock(typ ICMPType) bool {
|
|
||||||
return f.Data[typ>>5]&(1<<(uint32(typ)&31)) != 0
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
// Copyright 2013 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 nacl plan9 solaris
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
type sysICMPFilter struct {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *sysICMPFilter) set(typ ICMPType, block bool) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *sysICMPFilter) setAll(block bool) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *sysICMPFilter) willBlock(typ ICMPType) bool {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return false
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
type sysICMPFilter struct {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *sysICMPFilter) set(typ ICMPType, block bool) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *sysICMPFilter) setAll(block bool) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *sysICMPFilter) willBlock(typ ICMPType) bool {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return false
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import "net"
|
|
||||||
|
|
||||||
// A payloadHandler represents the IPv6 datagram payload handler.
|
|
||||||
type payloadHandler struct {
|
|
||||||
net.PacketConn
|
|
||||||
rawOpt
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *payloadHandler) ok() bool { return c != nil && c.PacketConn != nil }
|
|
|
@ -1,70 +0,0 @@
|
||||||
// Copyright 2013 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 !nacl,!plan9,!windows
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ReadFrom reads a payload of the received IPv6 datagram, from the
|
|
||||||
// endpoint c, copying the payload into b. It returns the number of
|
|
||||||
// bytes copied into b, the control message cm and the source address
|
|
||||||
// src of the received datagram.
|
|
||||||
func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, nil, nil, syscall.EINVAL
|
|
||||||
}
|
|
||||||
oob := newControlMessage(&c.rawOpt)
|
|
||||||
var oobn int
|
|
||||||
switch c := c.PacketConn.(type) {
|
|
||||||
case *net.UDPConn:
|
|
||||||
if n, oobn, _, src, err = c.ReadMsgUDP(b, oob); err != nil {
|
|
||||||
return 0, nil, nil, err
|
|
||||||
}
|
|
||||||
case *net.IPConn:
|
|
||||||
if n, oobn, _, src, err = c.ReadMsgIP(b, oob); err != nil {
|
|
||||||
return 0, nil, nil, err
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return 0, nil, nil, errInvalidConnType
|
|
||||||
}
|
|
||||||
if cm, err = parseControlMessage(oob[:oobn]); err != nil {
|
|
||||||
return 0, nil, nil, err
|
|
||||||
}
|
|
||||||
if cm != nil {
|
|
||||||
cm.Src = netAddrToIP16(src)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteTo writes a payload of the IPv6 datagram, to the destination
|
|
||||||
// address dst through the endpoint c, copying the payload from b. It
|
|
||||||
// returns the number of bytes written. The control message cm allows
|
|
||||||
// the IPv6 header fields and the datagram path to be specified. The
|
|
||||||
// cm may be nil if control of the outgoing datagram is not required.
|
|
||||||
func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, syscall.EINVAL
|
|
||||||
}
|
|
||||||
oob := marshalControlMessage(cm)
|
|
||||||
if dst == nil {
|
|
||||||
return 0, errMissingAddress
|
|
||||||
}
|
|
||||||
switch c := c.PacketConn.(type) {
|
|
||||||
case *net.UDPConn:
|
|
||||||
n, _, err = c.WriteMsgUDP(b, oob, dst.(*net.UDPAddr))
|
|
||||||
case *net.IPConn:
|
|
||||||
n, _, err = c.WriteMsgIP(b, oob, dst.(*net.IPAddr))
|
|
||||||
default:
|
|
||||||
return 0, errInvalidConnType
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
// Copyright 2013 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 nacl plan9 windows
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ReadFrom reads a payload of the received IPv6 datagram, from the
|
|
||||||
// endpoint c, copying the payload into b. It returns the number of
|
|
||||||
// bytes copied into b, the control message cm and the source address
|
|
||||||
// src of the received datagram.
|
|
||||||
func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, nil, nil, syscall.EINVAL
|
|
||||||
}
|
|
||||||
if n, src, err = c.PacketConn.ReadFrom(b); err != nil {
|
|
||||||
return 0, nil, nil, err
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteTo writes a payload of the IPv6 datagram, to the destination
|
|
||||||
// address dst through the endpoint c, copying the payload from b. It
|
|
||||||
// returns the number of bytes written. The control message cm allows
|
|
||||||
// the IPv6 header fields and the datagram path to be specified. The
|
|
||||||
// cm may be nil if control of the outgoing datagram is not required.
|
|
||||||
func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
|
|
||||||
if !c.ok() {
|
|
||||||
return 0, syscall.EINVAL
|
|
||||||
}
|
|
||||||
if dst == nil {
|
|
||||||
return 0, errMissingAddress
|
|
||||||
}
|
|
||||||
return c.PacketConn.WriteTo(b, dst)
|
|
||||||
}
|
|
|
@ -1,40 +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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
// Sticky socket options
|
|
||||||
const (
|
|
||||||
ssoTrafficClass = iota // header field for unicast packet, RFC 3542
|
|
||||||
ssoHopLimit // header field for unicast packet, RFC 3493
|
|
||||||
ssoMulticastInterface // outbound interface for multicast packet, RFC 3493
|
|
||||||
ssoMulticastHopLimit // header field for multicast packet, RFC 3493
|
|
||||||
ssoMulticastLoopback // loopback for multicast packet, RFC 3493
|
|
||||||
ssoReceiveTrafficClass // header field on received packet, RFC 3542
|
|
||||||
ssoReceiveHopLimit // header field on received packet, RFC 2292 or 3542
|
|
||||||
ssoReceivePacketInfo // incbound or outbound packet path, RFC 2292 or 3542
|
|
||||||
ssoReceivePathMTU // path mtu, RFC 3542
|
|
||||||
ssoPathMTU // path mtu, RFC 3542
|
|
||||||
ssoChecksum // packet checksum, RFC 2292 or 3542
|
|
||||||
ssoICMPFilter // icmp filter, RFC 2292 or 3542
|
|
||||||
ssoJoinGroup // any-source multicast, RFC 3493
|
|
||||||
ssoLeaveGroup // any-source multicast, RFC 3493
|
|
||||||
ssoMax
|
|
||||||
)
|
|
||||||
|
|
||||||
// Sticky socket option value types
|
|
||||||
const (
|
|
||||||
ssoTypeInt = iota + 1
|
|
||||||
ssoTypeInterface
|
|
||||||
ssoTypeICMPFilter
|
|
||||||
ssoTypeMTUInfo
|
|
||||||
ssoTypeIPMreq
|
|
||||||
)
|
|
||||||
|
|
||||||
// A sockOpt represents a binding for sticky socket option.
|
|
||||||
type sockOpt struct {
|
|
||||||
level int // option level
|
|
||||||
name int // option name, must be equal or greater than 1
|
|
||||||
typ int // option value type, must be equal or greater than 1
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
// Copyright 2013 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 darwin
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ipv6ReceiveTrafficClass(fd int) (bool, error) {
|
|
||||||
return false, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ReceiveTrafficClass(fd int, v bool) error {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6ReceiveHopLimit(fd int) (bool, error) {
|
|
||||||
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockopt2292HopLimit)
|
|
||||||
if err != nil {
|
|
||||||
return false, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return v == 1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ReceiveHopLimit(fd int, v bool) error {
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockopt2292HopLimit, boolint(v)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6ReceivePacketInfo(fd int) (bool, error) {
|
|
||||||
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockopt2292PacketInfo)
|
|
||||||
if err != nil {
|
|
||||||
return false, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return v == 1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ReceivePacketInfo(fd int, v bool) error {
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockopt2292PacketInfo, boolint(v)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6PathMTU(fd int) (int, error) {
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6ReceivePathMTU(fd int) (bool, error) {
|
|
||||||
return false, errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ReceivePathMTU(fd int, v bool) error {
|
|
||||||
return errOpNoSupport
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6ICMPFilter(fd int) (*ICMPFilter, error) {
|
|
||||||
var v ICMPFilter
|
|
||||||
l := sysSockoptLen(sysSizeofICMPFilter)
|
|
||||||
if err := getsockopt(fd, ianaProtocolIPv6ICMP, sysSockoptICMPFilter, unsafe.Pointer(&v.sysICMPFilter), &l); err != nil {
|
|
||||||
return nil, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return &v, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ICMPFilter(fd int, f *ICMPFilter) error {
|
|
||||||
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6ICMP, sysSockoptICMPFilter, unsafe.Pointer(&f.sysICMPFilter), sysSizeofICMPFilter))
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
// Copyright 2013 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 darwin dragonfly freebsd netbsd openbsd
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
func setIPv6Checksum(fd int, on bool, offset int) error {
|
|
||||||
if !on {
|
|
||||||
offset = -1
|
|
||||||
}
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptChecksum, offset))
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
func setIPv6Checksum(fd int, on bool, offset int) error {
|
|
||||||
if !on {
|
|
||||||
offset = -1
|
|
||||||
}
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolReserved, sysSockoptChecksum, offset))
|
|
||||||
}
|
|
|
@ -1,115 +0,0 @@
|
||||||
// Copyright 2013 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 darwin dragonfly freebsd linux netbsd openbsd
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ipv6TrafficClass(fd int) (int, error) {
|
|
||||||
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptTrafficClass)
|
|
||||||
if err != nil {
|
|
||||||
return 0, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6TrafficClass(fd, v int) error {
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptTrafficClass, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6HopLimit(fd int) (int, error) {
|
|
||||||
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptUnicastHopLimit)
|
|
||||||
if err != nil {
|
|
||||||
return 0, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6HopLimit(fd, v int) error {
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptUnicastHopLimit, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6Checksum(fd int) (bool, int, error) {
|
|
||||||
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptChecksum)
|
|
||||||
if err != nil {
|
|
||||||
return false, 0, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
on := true
|
|
||||||
if v == -1 {
|
|
||||||
on = false
|
|
||||||
}
|
|
||||||
return on, v, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6MulticastHopLimit(fd int) (int, error) {
|
|
||||||
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptMulticastHopLimit)
|
|
||||||
if err != nil {
|
|
||||||
return 0, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6MulticastHopLimit(fd, v int) error {
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptMulticastHopLimit, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6MulticastInterface(fd int) (*net.Interface, error) {
|
|
||||||
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptMulticastInterface)
|
|
||||||
if err != nil {
|
|
||||||
return nil, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
if v == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
ifi, err := net.InterfaceByIndex(v)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return ifi, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6MulticastInterface(fd int, ifi *net.Interface) error {
|
|
||||||
var v int
|
|
||||||
if ifi != nil {
|
|
||||||
v = ifi.Index
|
|
||||||
}
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptMulticastInterface, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6MulticastLoopback(fd int) (bool, error) {
|
|
||||||
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptMulticastLoopback)
|
|
||||||
if err != nil {
|
|
||||||
return false, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return v == 1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6MulticastLoopback(fd int, v bool) error {
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptMulticastLoopback, boolint(v)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func joinIPv6Group(fd int, ifi *net.Interface, grp net.IP) error {
|
|
||||||
mreq := sysMulticastReq{}
|
|
||||||
copy(mreq.IP[:], grp)
|
|
||||||
if ifi != nil {
|
|
||||||
mreq.IfIndex = uint32(ifi.Index)
|
|
||||||
}
|
|
||||||
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptJoinGroup, unsafe.Pointer(&mreq), sysSizeofMulticastReq))
|
|
||||||
}
|
|
||||||
|
|
||||||
func leaveIPv6Group(fd int, ifi *net.Interface, grp net.IP) error {
|
|
||||||
mreq := sysMulticastReq{}
|
|
||||||
copy(mreq.IP[:], grp)
|
|
||||||
if ifi != nil {
|
|
||||||
mreq.IfIndex = uint32(ifi.Index)
|
|
||||||
}
|
|
||||||
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptLeaveGroup, unsafe.Pointer(&mreq), sysSizeofMulticastReq))
|
|
||||||
}
|
|
|
@ -1,116 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ipv6TrafficClass(fd syscall.Handle) (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6TrafficClass(fd syscall.Handle, v int) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6HopLimit(fd syscall.Handle) (int, error) {
|
|
||||||
var v int32
|
|
||||||
l := int32(4)
|
|
||||||
if err := syscall.Getsockopt(fd, ianaProtocolIPv6, sysSockoptUnicastHopLimit, (*byte)(unsafe.Pointer(&v)), &l); err != nil {
|
|
||||||
return 0, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return int(v), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6HopLimit(fd syscall.Handle, v int) error {
|
|
||||||
vv := int32(v)
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, ianaProtocolIPv6, sysSockoptUnicastHopLimit, (*byte)(unsafe.Pointer(&vv)), 4))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6Checksum(fd syscall.Handle) (bool, int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return false, 0, syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6MulticastHopLimit(fd syscall.Handle) (int, error) {
|
|
||||||
var v int32
|
|
||||||
l := int32(4)
|
|
||||||
if err := syscall.Getsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastHopLimit, (*byte)(unsafe.Pointer(&v)), &l); err != nil {
|
|
||||||
return 0, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return int(v), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6MulticastHopLimit(fd syscall.Handle, v int) error {
|
|
||||||
vv := int32(v)
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastHopLimit, (*byte)(unsafe.Pointer(&vv)), 4))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6MulticastInterface(fd syscall.Handle) (*net.Interface, error) {
|
|
||||||
var v int32
|
|
||||||
l := int32(4)
|
|
||||||
if err := syscall.Getsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastInterface, (*byte)(unsafe.Pointer(&v)), &l); err != nil {
|
|
||||||
return nil, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
if v == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
ifi, err := net.InterfaceByIndex(int(v))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return ifi, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6MulticastInterface(fd syscall.Handle, ifi *net.Interface) error {
|
|
||||||
var v int32
|
|
||||||
if ifi != nil {
|
|
||||||
v = int32(ifi.Index)
|
|
||||||
}
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastInterface, (*byte)(unsafe.Pointer(&v)), 4))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6MulticastLoopback(fd syscall.Handle) (bool, error) {
|
|
||||||
var v int32
|
|
||||||
l := int32(4)
|
|
||||||
if err := syscall.Getsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastLoopback, (*byte)(unsafe.Pointer(&v)), &l); err != nil {
|
|
||||||
return false, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return v == 1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6MulticastLoopback(fd syscall.Handle, v bool) error {
|
|
||||||
vv := int32(boolint(v))
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastLoopback, (*byte)(unsafe.Pointer(&vv)), 4))
|
|
||||||
}
|
|
||||||
|
|
||||||
func joinIPv6Group(fd syscall.Handle, ifi *net.Interface, grp net.IP) error {
|
|
||||||
mreq := sysMulticastReq{}
|
|
||||||
copy(mreq.IP[:], grp)
|
|
||||||
if ifi != nil {
|
|
||||||
mreq.IfIndex = uint32(ifi.Index)
|
|
||||||
}
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, ianaProtocolIPv6, sysSockoptJoinGroup, (*byte)(unsafe.Pointer(&mreq)), int32(sysSizeofMulticastReq)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func leaveIPv6Group(fd syscall.Handle, ifi *net.Interface, grp net.IP) error {
|
|
||||||
mreq := sysMulticastReq{}
|
|
||||||
copy(mreq.IP[:], grp)
|
|
||||||
if ifi != nil {
|
|
||||||
mreq.IfIndex = uint32(ifi.Index)
|
|
||||||
}
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd, ianaProtocolIPv6, sysSockoptLeaveGroup, (*byte)(unsafe.Pointer(&mreq)), int32(sysSizeofMulticastReq)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6Checksum(fd syscall.Handle, on bool, offset int) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return syscall.EWINDOWS
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
// Copyright 2013 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 nacl plan9 solaris
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
func ipv6PathMTU(fd int) (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, errOpNoSupport
|
|
||||||
}
|
|
|
@ -1,83 +0,0 @@
|
||||||
// Copyright 2013 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 dragonfly freebsd linux netbsd openbsd
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ipv6ReceiveTrafficClass(fd int) (bool, error) {
|
|
||||||
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceiveTrafficClass)
|
|
||||||
if err != nil {
|
|
||||||
return false, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return v == 1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ReceiveTrafficClass(fd int, v bool) error {
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceiveTrafficClass, boolint(v)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6ReceiveHopLimit(fd int) (bool, error) {
|
|
||||||
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceiveHopLimit)
|
|
||||||
if err != nil {
|
|
||||||
return false, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return v == 1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ReceiveHopLimit(fd int, v bool) error {
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceiveHopLimit, boolint(v)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6ReceivePacketInfo(fd int) (bool, error) {
|
|
||||||
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceivePacketInfo)
|
|
||||||
if err != nil {
|
|
||||||
return false, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return v == 1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ReceivePacketInfo(fd int, v bool) error {
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceivePacketInfo, boolint(v)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6PathMTU(fd int) (int, error) {
|
|
||||||
var v sysMTUInfo
|
|
||||||
l := sysSockoptLen(sysSizeofMTUInfo)
|
|
||||||
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptPathMTU, unsafe.Pointer(&v), &l); err != nil {
|
|
||||||
return 0, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return int(v.MTU), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6ReceivePathMTU(fd int) (bool, error) {
|
|
||||||
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceivePathMTU)
|
|
||||||
if err != nil {
|
|
||||||
return false, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return v == 1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ReceivePathMTU(fd int, v bool) error {
|
|
||||||
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceivePathMTU, boolint(v)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6ICMPFilter(fd int) (*ICMPFilter, error) {
|
|
||||||
var v ICMPFilter
|
|
||||||
l := sysSockoptLen(sysSizeofICMPFilter)
|
|
||||||
if err := getsockopt(fd, ianaProtocolIPv6ICMP, sysSockoptICMPFilter, unsafe.Pointer(&v.sysICMPFilter), &l); err != nil {
|
|
||||||
return nil, os.NewSyscallError("getsockopt", err)
|
|
||||||
}
|
|
||||||
return &v, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ICMPFilter(fd int, f *ICMPFilter) error {
|
|
||||||
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6ICMP, sysSockoptICMPFilter, unsafe.Pointer(&f.sysICMPFilter), sysSizeofICMPFilter))
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
func ipv6ReceiveTrafficClass(fd syscall.Handle) (bool, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return false, syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ReceiveTrafficClass(fd syscall.Handle, v bool) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6ReceiveHopLimit(fd syscall.Handle) (bool, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return false, syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ReceiveHopLimit(fd syscall.Handle, v bool) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6ReceivePacketInfo(fd syscall.Handle) (bool, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return false, syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ReceivePacketInfo(fd syscall.Handle, v bool) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6PathMTU(fd syscall.Handle) (int, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return 0, syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6ReceivePathMTU(fd syscall.Handle) (bool, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return false, syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ReceivePathMTU(fd syscall.Handle, v bool) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipv6ICMPFilter(fd syscall.Handle) (*ICMPFilter, error) {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return nil, syscall.EWINDOWS
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIPv6ICMPFilter(fd syscall.Handle, f *ICMPFilter) error {
|
|
||||||
// TODO(mikio): Implement this
|
|
||||||
return syscall.EWINDOWS
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
type sysSockoptLen uint32
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysSizeofPacketInfo = 0x14
|
|
||||||
sysSizeofMulticastReq = 0x14
|
|
||||||
sysSizeofICMPFilter = 0x20
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysPacketInfo struct {
|
|
||||||
IP [16]byte
|
|
||||||
IfIndex uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysMulticastReq struct {
|
|
||||||
IP [16]byte
|
|
||||||
IfIndex uint32
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
// Copyright 2013 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 dragonfly freebsd netbsd openbsd
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RFC 3542 options
|
|
||||||
const (
|
|
||||||
// See /usr/include/netinet6/in6.h.
|
|
||||||
sysSockoptReceiveTrafficClass = syscall.IPV6_RECVTCLASS
|
|
||||||
sysSockoptTrafficClass = syscall.IPV6_TCLASS
|
|
||||||
sysSockoptReceiveHopLimit = syscall.IPV6_RECVHOPLIMIT
|
|
||||||
sysSockoptHopLimit = syscall.IPV6_HOPLIMIT
|
|
||||||
sysSockoptReceivePacketInfo = syscall.IPV6_RECVPKTINFO
|
|
||||||
sysSockoptPacketInfo = syscall.IPV6_PKTINFO
|
|
||||||
sysSockoptReceivePathMTU = syscall.IPV6_RECVPATHMTU
|
|
||||||
sysSockoptPathMTU = syscall.IPV6_PATHMTU
|
|
||||||
sysSockoptNextHop = syscall.IPV6_NEXTHOP
|
|
||||||
sysSockoptChecksum = syscall.IPV6_CHECKSUM
|
|
||||||
|
|
||||||
// See /usr/include/netinet6/in6.h.
|
|
||||||
sysSockoptICMPFilter = 0x12 // syscall.ICMP6_FILTER
|
|
||||||
)
|
|
||||||
|
|
||||||
func setSockaddr(sa *syscall.RawSockaddrInet6, ip net.IP, ifindex int) {
|
|
||||||
sa.Len = syscall.SizeofSockaddrInet6
|
|
||||||
sa.Family = syscall.AF_INET6
|
|
||||||
copy(sa.Addr[:], ip)
|
|
||||||
sa.Scope_id = uint32(ifindex)
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RFC 2292 options
|
|
||||||
const (
|
|
||||||
// See /usr/include/netinet6/in6.h.
|
|
||||||
sysSockopt2292HopLimit = syscall.IPV6_2292HOPLIMIT
|
|
||||||
sysSockopt2292PacketInfo = syscall.IPV6_2292PKTINFO
|
|
||||||
sysSockopt2292NextHop = syscall.IPV6_2292NEXTHOP
|
|
||||||
)
|
|
||||||
|
|
||||||
// RFC 3542 options
|
|
||||||
const (
|
|
||||||
// See /usr/include/netinet6/in6.h.
|
|
||||||
sysSockoptReceiveTrafficClass = 0x23 // IPV6_RECVTCLASS
|
|
||||||
sysSockoptTrafficClass = 0x24 // IPV6_TCLASS
|
|
||||||
sysSockoptReceiveHopLimit = 0x25 // IPV6_RECVHOPLIMIT
|
|
||||||
sysSockoptHopLimit = 0x2f // IPV6_HOPLIMIT
|
|
||||||
sysSockoptReceivePacketInfo = 0x3d // IPV6_RECVPKTINFO
|
|
||||||
sysSockoptPacketInfo = 0x2e // IPV6_PKTINFO
|
|
||||||
sysSockoptReceivePathMTU = 0x2b // IPV6_RECVPATHMTU
|
|
||||||
sysSockoptPathMTU = 0x2c // IPV6_PATHMTU
|
|
||||||
sysSockoptNextHop = 0x30 // IPV6_NEXTHOP
|
|
||||||
sysSockoptChecksum = 0x1a // IPV6_CHECKSUM
|
|
||||||
|
|
||||||
// See /usr/include/netinet6/in6.h.
|
|
||||||
sysSockoptICMPFilter = 0x12 // ICMP6_FILTER
|
|
||||||
)
|
|
||||||
|
|
||||||
func setSockaddr(sa *syscall.RawSockaddrInet6, ip net.IP, ifindex int) {
|
|
||||||
sa.Len = syscall.SizeofSockaddrInet6
|
|
||||||
sa.Family = syscall.AF_INET6
|
|
||||||
copy(sa.Addr[:], ip)
|
|
||||||
sa.Scope_id = uint32(ifindex)
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RFC 3542 options
|
|
||||||
const (
|
|
||||||
// See /usr/include/linux/ipv6.h,in6.h.
|
|
||||||
sysSockoptReceiveTrafficClass = syscall.IPV6_RECVTCLASS
|
|
||||||
sysSockoptTrafficClass = syscall.IPV6_TCLASS
|
|
||||||
sysSockoptReceiveHopLimit = syscall.IPV6_RECVHOPLIMIT
|
|
||||||
sysSockoptHopLimit = syscall.IPV6_HOPLIMIT
|
|
||||||
sysSockoptReceivePacketInfo = syscall.IPV6_RECVPKTINFO
|
|
||||||
sysSockoptPacketInfo = syscall.IPV6_PKTINFO
|
|
||||||
sysSockoptReceivePathMTU = 0x3c // IPV6_RECVPATHMTU
|
|
||||||
sysSockoptPathMTU = 0x3d // IPV6_PATHMTU
|
|
||||||
sysSockoptNextHop = syscall.IPV6_NEXTHOP
|
|
||||||
sysSockoptChecksum = syscall.IPV6_CHECKSUM
|
|
||||||
|
|
||||||
// See /usr/include/linux/icmpv6.h.
|
|
||||||
sysSockoptICMPFilter = 0x1 // syscall.ICMPV6_FILTER
|
|
||||||
)
|
|
||||||
|
|
||||||
func setSockaddr(sa *syscall.RawSockaddrInet6, ip net.IP, ifindex int) {
|
|
||||||
sa.Family = syscall.AF_INET6
|
|
||||||
copy(sa.Addr[:], ip)
|
|
||||||
sa.Scope_id = uint32(ifindex)
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
// Copyright 2013 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 darwin dragonfly freebsd linux netbsd openbsd
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
// RFC 3493 options
|
|
||||||
const (
|
|
||||||
sysSockoptUnicastHopLimit = syscall.IPV6_UNICAST_HOPS
|
|
||||||
sysSockoptMulticastHopLimit = syscall.IPV6_MULTICAST_HOPS
|
|
||||||
sysSockoptMulticastInterface = syscall.IPV6_MULTICAST_IF
|
|
||||||
sysSockoptMulticastLoopback = syscall.IPV6_MULTICAST_LOOP
|
|
||||||
sysSockoptJoinGroup = syscall.IPV6_JOIN_GROUP
|
|
||||||
sysSockoptLeaveGroup = syscall.IPV6_LEAVE_GROUP
|
|
||||||
)
|
|
||||||
|
|
||||||
const sysSizeofMTUInfo = 0x20
|
|
||||||
|
|
||||||
type sysMTUInfo struct {
|
|
||||||
Addr syscall.RawSockaddrInet6
|
|
||||||
MTU uint32
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
// Copyright 2013 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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RFC 3493 options
|
|
||||||
const (
|
|
||||||
// See ws2tcpip.h.
|
|
||||||
sysSockoptUnicastHopLimit = syscall.IPV6_UNICAST_HOPS
|
|
||||||
sysSockoptMulticastHopLimit = syscall.IPV6_MULTICAST_HOPS
|
|
||||||
sysSockoptMulticastInterface = syscall.IPV6_MULTICAST_IF
|
|
||||||
sysSockoptMulticastLoopback = syscall.IPV6_MULTICAST_LOOP
|
|
||||||
sysSockoptJoinGroup = syscall.IPV6_JOIN_GROUP
|
|
||||||
sysSockoptLeaveGroup = syscall.IPV6_LEAVE_GROUP
|
|
||||||
)
|
|
||||||
|
|
||||||
// RFC 3542 options
|
|
||||||
const (
|
|
||||||
// See ws2tcpip.h.
|
|
||||||
sysSockoptPacketInfo = 0x13 // IPV6_PKTINFO
|
|
||||||
)
|
|
||||||
|
|
||||||
func setSockaddr(sa *syscall.RawSockaddrInet6, ip net.IP, ifindex int) {
|
|
||||||
sa.Family = syscall.AF_INET6
|
|
||||||
copy(sa.Addr[:], ip)
|
|
||||||
sa.Scope_id = uint32(ifindex)
|
|
||||||
}
|
|
|
@ -1,31 +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.
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysGETSOCKOPT = 0xf
|
|
||||||
sysSETSOCKOPT = 0xe
|
|
||||||
)
|
|
||||||
|
|
||||||
func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno)
|
|
||||||
|
|
||||||
func getsockopt(fd, level, name int, v unsafe.Pointer, l *sysSockoptLen) error {
|
|
||||||
if _, errno := socketcall(sysGETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
|
|
||||||
return error(errno)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setsockopt(fd, level, name int, v unsafe.Pointer, l sysSockoptLen) error {
|
|
||||||
if _, errno := socketcall(sysSETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
|
|
||||||
return error(errno)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
// Copyright 2013 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 darwin dragonfly freebsd linux,amd64 linux,arm netbsd openbsd
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getsockopt(fd, level, name int, v unsafe.Pointer, l *sysSockoptLen) error {
|
|
||||||
if _, _, errno := syscall.Syscall6(syscall.SYS_GETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
|
|
||||||
return error(errno)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setsockopt(fd, level, name int, v unsafe.Pointer, l sysSockoptLen) error {
|
|
||||||
if _, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
|
|
||||||
return error(errno)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,8 +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 go1.2
|
|
||||||
|
|
||||||
TEXT ·socketcall(SB),4,$0-36
|
|
||||||
JMP syscall·socketcall(SB)
|
|
|
@ -1,101 +0,0 @@
|
||||||
// Created by cgo -godefs - DO NOT EDIT
|
|
||||||
// cgo -godefs defs_darwin.go
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysIPV6_UNICAST_HOPS = 0x4
|
|
||||||
sysIPV6_MULTICAST_IF = 0x9
|
|
||||||
sysIPV6_MULTICAST_HOPS = 0xa
|
|
||||||
sysIPV6_MULTICAST_LOOP = 0xb
|
|
||||||
sysIPV6_JOIN_GROUP = 0xc
|
|
||||||
sysIPV6_LEAVE_GROUP = 0xd
|
|
||||||
|
|
||||||
sysIPV6_PORTRANGE = 0xe
|
|
||||||
sysICMP6_FILTER = 0x12
|
|
||||||
sysIPV6_2292PKTINFO = 0x13
|
|
||||||
sysIPV6_2292HOPLIMIT = 0x14
|
|
||||||
sysIPV6_2292NEXTHOP = 0x15
|
|
||||||
sysIPV6_2292HOPOPTS = 0x16
|
|
||||||
sysIPV6_2292DSTOPTS = 0x17
|
|
||||||
sysIPV6_2292RTHDR = 0x18
|
|
||||||
|
|
||||||
sysIPV6_2292PKTOPTIONS = 0x19
|
|
||||||
|
|
||||||
sysIPV6_CHECKSUM = 0x1a
|
|
||||||
sysIPV6_V6ONLY = 0x1b
|
|
||||||
|
|
||||||
sysIPV6_IPSEC_POLICY = 0x1c
|
|
||||||
|
|
||||||
sysIPV6_RECVTCLASS = 0x23
|
|
||||||
sysIPV6_TCLASS = 0x24
|
|
||||||
|
|
||||||
sysIPV6_RTHDRDSTOPTS = 0x39
|
|
||||||
|
|
||||||
sysIPV6_RECVPKTINFO = 0x3d
|
|
||||||
|
|
||||||
sysIPV6_RECVHOPLIMIT = 0x25
|
|
||||||
sysIPV6_RECVRTHDR = 0x26
|
|
||||||
sysIPV6_RECVHOPOPTS = 0x27
|
|
||||||
sysIPV6_RECVDSTOPTS = 0x28
|
|
||||||
|
|
||||||
sysIPV6_USE_MIN_MTU = 0x2a
|
|
||||||
sysIPV6_RECVPATHMTU = 0x2b
|
|
||||||
|
|
||||||
sysIPV6_PATHMTU = 0x2c
|
|
||||||
|
|
||||||
sysIPV6_PKTINFO = 0x2e
|
|
||||||
sysIPV6_HOPLIMIT = 0x2f
|
|
||||||
sysIPV6_NEXTHOP = 0x30
|
|
||||||
sysIPV6_HOPOPTS = 0x31
|
|
||||||
sysIPV6_DSTOPTS = 0x32
|
|
||||||
sysIPV6_RTHDR = 0x33
|
|
||||||
|
|
||||||
sysIPV6_AUTOFLOWLABEL = 0x3b
|
|
||||||
|
|
||||||
sysIPV6_DONTFRAG = 0x3e
|
|
||||||
|
|
||||||
sysIPV6_PREFER_TEMPADDR = 0x3f
|
|
||||||
|
|
||||||
sysIPV6_BOUND_IF = 0x7d
|
|
||||||
|
|
||||||
sysIPV6_PORTRANGE_DEFAULT = 0x0
|
|
||||||
sysIPV6_PORTRANGE_HIGH = 0x1
|
|
||||||
sysIPV6_PORTRANGE_LOW = 0x2
|
|
||||||
|
|
||||||
sysSizeofSockaddrInet6 = 0x1c
|
|
||||||
sysSizeofInet6Pktinfo = 0x14
|
|
||||||
sysSizeofIPv6Mtuinfo = 0x20
|
|
||||||
|
|
||||||
sysSizeofIPv6Mreq = 0x14
|
|
||||||
|
|
||||||
sysSizeofICMPv6Filter = 0x20
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysSockaddrInet6 struct {
|
|
||||||
Len uint8
|
|
||||||
Family uint8
|
|
||||||
Port uint16
|
|
||||||
Flowinfo uint32
|
|
||||||
Addr [16]byte /* in6_addr */
|
|
||||||
Scope_id uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysInet6Pktinfo struct {
|
|
||||||
Addr [16]byte /* in6_addr */
|
|
||||||
Ifindex uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPv6Mtuinfo struct {
|
|
||||||
Addr sysSockaddrInet6
|
|
||||||
Mtu uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPv6Mreq struct {
|
|
||||||
Multiaddr [16]byte /* in6_addr */
|
|
||||||
Interface uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysICMPv6Filter struct {
|
|
||||||
Filt [8]uint32
|
|
||||||
}
|
|
|
@ -1,90 +0,0 @@
|
||||||
// Created by cgo -godefs - DO NOT EDIT
|
|
||||||
// cgo -godefs defs_dragonfly.go
|
|
||||||
|
|
||||||
// +build dragonfly
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysIPV6_UNICAST_HOPS = 0x4
|
|
||||||
sysIPV6_MULTICAST_IF = 0x9
|
|
||||||
sysIPV6_MULTICAST_HOPS = 0xa
|
|
||||||
sysIPV6_MULTICAST_LOOP = 0xb
|
|
||||||
sysIPV6_JOIN_GROUP = 0xc
|
|
||||||
sysIPV6_LEAVE_GROUP = 0xd
|
|
||||||
sysIPV6_PORTRANGE = 0xe
|
|
||||||
sysICMP6_FILTER = 0x12
|
|
||||||
|
|
||||||
sysIPV6_CHECKSUM = 0x1a
|
|
||||||
sysIPV6_V6ONLY = 0x1b
|
|
||||||
|
|
||||||
sysIPV6_IPSEC_POLICY = 0x1c
|
|
||||||
|
|
||||||
sysIPV6_RTHDRDSTOPTS = 0x23
|
|
||||||
sysIPV6_RECVPKTINFO = 0x24
|
|
||||||
sysIPV6_RECVHOPLIMIT = 0x25
|
|
||||||
sysIPV6_RECVRTHDR = 0x26
|
|
||||||
sysIPV6_RECVHOPOPTS = 0x27
|
|
||||||
sysIPV6_RECVDSTOPTS = 0x28
|
|
||||||
|
|
||||||
sysIPV6_USE_MIN_MTU = 0x2a
|
|
||||||
sysIPV6_RECVPATHMTU = 0x2b
|
|
||||||
|
|
||||||
sysIPV6_PATHMTU = 0x2c
|
|
||||||
|
|
||||||
sysIPV6_PKTINFO = 0x2e
|
|
||||||
sysIPV6_HOPLIMIT = 0x2f
|
|
||||||
sysIPV6_NEXTHOP = 0x30
|
|
||||||
sysIPV6_HOPOPTS = 0x31
|
|
||||||
sysIPV6_DSTOPTS = 0x32
|
|
||||||
sysIPV6_RTHDR = 0x33
|
|
||||||
|
|
||||||
sysIPV6_RECVTCLASS = 0x39
|
|
||||||
|
|
||||||
sysIPV6_AUTOFLOWLABEL = 0x3b
|
|
||||||
|
|
||||||
sysIPV6_TCLASS = 0x3d
|
|
||||||
sysIPV6_DONTFRAG = 0x3e
|
|
||||||
|
|
||||||
sysIPV6_PREFER_TEMPADDR = 0x3f
|
|
||||||
|
|
||||||
sysIPV6_PORTRANGE_DEFAULT = 0x0
|
|
||||||
sysIPV6_PORTRANGE_HIGH = 0x1
|
|
||||||
sysIPV6_PORTRANGE_LOW = 0x2
|
|
||||||
|
|
||||||
sysSizeofSockaddrInet6 = 0x1c
|
|
||||||
sysSizeofInet6Pktinfo = 0x14
|
|
||||||
sysSizeofIPv6Mtuinfo = 0x20
|
|
||||||
|
|
||||||
sysSizeofIPv6Mreq = 0x14
|
|
||||||
|
|
||||||
sysSizeofICMPv6Filter = 0x20
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysSockaddrInet6 struct {
|
|
||||||
Len uint8
|
|
||||||
Family uint8
|
|
||||||
Port uint16
|
|
||||||
Flowinfo uint32
|
|
||||||
Addr [16]byte /* in6_addr */
|
|
||||||
Scope_id uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysInet6Pktinfo struct {
|
|
||||||
Addr [16]byte /* in6_addr */
|
|
||||||
Ifindex uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPv6Mtuinfo struct {
|
|
||||||
Addr sysSockaddrInet6
|
|
||||||
Mtu uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPv6Mreq struct {
|
|
||||||
Multiaddr [16]byte /* in6_addr */
|
|
||||||
Interface uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysICMPv6Filter struct {
|
|
||||||
Filt [8]uint32
|
|
||||||
}
|
|
|
@ -1,91 +0,0 @@
|
||||||
// Created by cgo -godefs - DO NOT EDIT
|
|
||||||
// cgo -godefs defs_freebsd.go
|
|
||||||
|
|
||||||
package ipv6
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysIPV6_UNICAST_HOPS = 0x4
|
|
||||||
sysIPV6_MULTICAST_IF = 0x9
|
|
||||||
sysIPV6_MULTICAST_HOPS = 0xa
|
|
||||||
sysIPV6_MULTICAST_LOOP = 0xb
|
|
||||||
sysIPV6_JOIN_GROUP = 0xc
|
|
||||||
sysIPV6_LEAVE_GROUP = 0xd
|
|
||||||
sysIPV6_PORTRANGE = 0xe
|
|
||||||
sysICMP6_FILTER = 0x12
|
|
||||||
|
|
||||||
sysIPV6_CHECKSUM = 0x1a
|
|
||||||
sysIPV6_V6ONLY = 0x1b
|
|
||||||
|
|
||||||
sysIPV6_IPSEC_POLICY = 0x1c
|
|
||||||
|
|
||||||
sysIPV6_RTHDRDSTOPTS = 0x23
|
|
||||||
|
|
||||||
sysIPV6_RECVPKTINFO = 0x24
|
|
||||||
sysIPV6_RECVHOPLIMIT = 0x25
|
|
||||||
sysIPV6_RECVRTHDR = 0x26
|
|
||||||
sysIPV6_RECVHOPOPTS = 0x27
|
|
||||||
sysIPV6_RECVDSTOPTS = 0x28
|
|
||||||
|
|
||||||
sysIPV6_USE_MIN_MTU = 0x2a
|
|
||||||
sysIPV6_RECVPATHMTU = 0x2b
|
|
||||||
|
|
||||||
sysIPV6_PATHMTU = 0x2c
|
|
||||||
|
|
||||||
sysIPV6_PKTINFO = 0x2e
|
|
||||||
sysIPV6_HOPLIMIT = 0x2f
|
|
||||||
sysIPV6_NEXTHOP = 0x30
|
|
||||||
sysIPV6_HOPOPTS = 0x31
|
|
||||||
sysIPV6_DSTOPTS = 0x32
|
|
||||||
sysIPV6_RTHDR = 0x33
|
|
||||||
|
|
||||||
sysIPV6_RECVTCLASS = 0x39
|
|
||||||
|
|
||||||
sysIPV6_AUTOFLOWLABEL = 0x3b
|
|
||||||
|
|
||||||
sysIPV6_TCLASS = 0x3d
|
|
||||||
sysIPV6_DONTFRAG = 0x3e
|
|
||||||
|
|
||||||
sysIPV6_PREFER_TEMPADDR = 0x3f
|
|
||||||
|
|
||||||
sysIPV6_BINDANY = 0x40
|
|
||||||
|
|
||||||
sysIPV6_PORTRANGE_DEFAULT = 0x0
|
|
||||||
sysIPV6_PORTRANGE_HIGH = 0x1
|
|
||||||
sysIPV6_PORTRANGE_LOW = 0x2
|
|
||||||
|
|
||||||
sysSizeofSockaddrInet6 = 0x1c
|
|
||||||
sysSizeofInet6Pktinfo = 0x14
|
|
||||||
sysSizeofIPv6Mtuinfo = 0x20
|
|
||||||
|
|
||||||
sysSizeofIPv6Mreq = 0x14
|
|
||||||
|
|
||||||
sysSizeofICMPv6Filter = 0x20
|
|
||||||
)
|
|
||||||
|
|
||||||
type sysSockaddrInet6 struct {
|
|
||||||
Len uint8
|
|
||||||
Family uint8
|
|
||||||
Port uint16
|
|
||||||
Flowinfo uint32
|
|
||||||
Addr [16]byte /* in6_addr */
|
|
||||||
Scope_id uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysInet6Pktinfo struct {
|
|
||||||
Addr [16]byte /* in6_addr */
|
|
||||||
Ifindex uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPv6Mtuinfo struct {
|
|
||||||
Addr sysSockaddrInet6
|
|
||||||
Mtu uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysIPv6Mreq struct {
|
|
||||||
Multiaddr [16]byte /* in6_addr */
|
|
||||||
Interface uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type sysICMPv6Filter struct {
|
|
||||||
Filt [8]uint32
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue