mirror of
https://github.com/bettercap/bettercap
synced 2025-08-13 02:06:57 -07:00
refact: refactored to use islazy and updated deps
This commit is contained in:
parent
a2b3ee79fb
commit
d070445225
238 changed files with 12662 additions and 1586 deletions
24
vendor/github.com/elazarl/goproxy/README.md
generated
vendored
24
vendor/github.com/elazarl/goproxy/README.md
generated
vendored
|
@ -8,8 +8,8 @@ Package goproxy provides a customizable HTTP proxy library for Go (golang),
|
|||
It supports regular HTTP proxy, HTTPS through CONNECT, and "hijacking" HTTPS
|
||||
connection using "Man in the Middle" style attack.
|
||||
|
||||
The intent of the proxy, is to be usable with reasonable amount of traffic
|
||||
yet, customizable and programmable.
|
||||
The intent of the proxy is to be usable with reasonable amount of traffic,
|
||||
yet customizable and programmable.
|
||||
|
||||
The proxy itself is simply a `net/http` handler.
|
||||
|
||||
|
@ -22,7 +22,7 @@ For example, the URL you should use as proxy when running `./bin/basic` is
|
|||
|
||||
## Mailing List
|
||||
|
||||
New features would be discussed on the [mailing list](https://groups.google.com/forum/#!forum/goproxy-dev)
|
||||
New features will be discussed on the [mailing list](https://groups.google.com/forum/#!forum/goproxy-dev)
|
||||
before their development.
|
||||
|
||||
## Latest Stable Release
|
||||
|
@ -32,13 +32,13 @@ Get the latest goproxy from `gopkg.in/elazarl/goproxy.v1`.
|
|||
# Why not Fiddler2?
|
||||
|
||||
Fiddler is an excellent software with similar intent. However, Fiddler is not
|
||||
as customizable as goproxy intend to be. The main difference is, Fiddler is not
|
||||
as customizable as goproxy intends to be. The main difference is, Fiddler is not
|
||||
intended to be used as a real proxy.
|
||||
|
||||
A possible use case that suits goproxy but
|
||||
not Fiddler, is, gathering statistics on page load times for a certain website over a week.
|
||||
not Fiddler, is gathering statistics on page load times for a certain website over a week.
|
||||
With goproxy you could ask all your users to set their proxy to a dedicated machine running a
|
||||
goproxy server. Fiddler is a GUI app not designed to be ran like a server for multiple users.
|
||||
goproxy server. Fiddler is a GUI app not designed to be run like a server for multiple users.
|
||||
|
||||
# A taste of goproxy
|
||||
|
||||
|
@ -90,12 +90,12 @@ proxy.OnRequest(goproxy.DstHostIs("www.reddit.com")).DoFunc(
|
|||
})
|
||||
```
|
||||
|
||||
`DstHostIs` returns a `ReqCondition`, that is a function receiving a `Request` and returning a boolean
|
||||
we will only process requests that matches the condition. `DstHostIs("www.reddit.com")` will return
|
||||
`DstHostIs` returns a `ReqCondition`, that is a function receiving a `Request` and returning a boolean.
|
||||
We will only process requests that match the condition. `DstHostIs("www.reddit.com")` will return
|
||||
a `ReqCondition` accepting only requests directed to "www.reddit.com".
|
||||
|
||||
`DoFunc` will receive a function that will preprocess the request. We can change the request, or
|
||||
return a response. If the time is between 8:00am and 17:00pm, we will neglect the request, and
|
||||
return a response. If the time is between 8:00am and 17:00pm, we will reject the request, and
|
||||
return a precanned text response saying "do not waste your time".
|
||||
|
||||
See additional examples in the examples directory.
|
||||
|
@ -108,14 +108,14 @@ See additional examples in the examples directory.
|
|||
|
||||
# License
|
||||
|
||||
I put the software temporarily under the Go-compatible BSD license,
|
||||
if this prevents someone from using the software, do let me know and I'll consider changing it.
|
||||
I put the software temporarily under the Go-compatible BSD license.
|
||||
If this prevents someone from using the software, do let me know and I'll consider changing it.
|
||||
|
||||
At any rate, user feedback is very important for me, so I'll be delighted to know if you're using this package.
|
||||
|
||||
# Beta Software
|
||||
|
||||
I've received a positive feedback from a few people who use goproxy in production settings.
|
||||
I've received positive feedback from a few people who use goproxy in production settings.
|
||||
I believe it is good enough for usage.
|
||||
|
||||
I'll try to keep reasonable backwards compatibility. In case of a major API change,
|
||||
|
|
596
vendor/github.com/evilsocket/islazy/LICENSE.md
generated
vendored
Normal file
596
vendor/github.com/evilsocket/islazy/LICENSE.md
generated
vendored
Normal file
|
@ -0,0 +1,596 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
==========================
|
||||
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright © 2007 Free Software Foundation, Inc. <<https://www.fsf.org/>>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license
|
||||
document, but changing it is not allowed.
|
||||
|
||||
## Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for software and other
|
||||
kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed to take away
|
||||
your freedom to share and change the works. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change all versions of a
|
||||
program--to make sure it remains free software for all its users. We, the Free
|
||||
Software Foundation, use the GNU General Public License for most of our software; it
|
||||
applies also to any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General
|
||||
Public Licenses are designed to make sure that you have the freedom to distribute
|
||||
copies of free software (and charge for them if you wish), that you receive source
|
||||
code or can get it if you want it, that you can change the software or use pieces of
|
||||
it in new free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you these rights or
|
||||
asking you to surrender the rights. Therefore, you have certain responsibilities if
|
||||
you distribute copies of the software, or if you modify it: responsibilities to
|
||||
respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee,
|
||||
you must pass on to the recipients the same freedoms that you received. You must make
|
||||
sure that they, too, receive or can get the source code. And you must show them these
|
||||
terms so they know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps: (1) assert
|
||||
copyright on the software, and (2) offer you this License giving you legal permission
|
||||
to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains that there is
|
||||
no warranty for this free software. For both users' and authors' sake, the GPL
|
||||
requires that modified versions be marked as changed, so that their problems will not
|
||||
be attributed erroneously to authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run modified versions of
|
||||
the software inside them, although the manufacturer can do so. This is fundamentally
|
||||
incompatible with the aim of protecting users' freedom to change the software. The
|
||||
systematic pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we have designed
|
||||
this version of the GPL to prohibit the practice for those products. If such problems
|
||||
arise substantially in other domains, we stand ready to extend this provision to
|
||||
those domains in future versions of the GPL, as needed to protect the freedom of
|
||||
users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents. States should
|
||||
not allow patents to restrict development and use of software on general-purpose
|
||||
computers, but in those that do, we wish to avoid the special danger that patents
|
||||
applied to a free program could make it effectively proprietary. To prevent this, the
|
||||
GPL assures that patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
## TERMS AND CONDITIONS
|
||||
|
||||
### 0. Definitions.
|
||||
|
||||
“This License” refers to version 3 of the GNU General Public License.
|
||||
|
||||
“Copyright” also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
“The Program” refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as “you”. “Licensees” and
|
||||
“recipients” may be individuals or organizations.
|
||||
|
||||
To “modify” a work means to copy from or adapt all or part of the work in
|
||||
a fashion requiring copyright permission, other than the making of an exact copy. The
|
||||
resulting work is called a “modified version” of the earlier work or a
|
||||
work “based on” the earlier work.
|
||||
|
||||
A “covered work” means either the unmodified Program or a work based on
|
||||
the Program.
|
||||
|
||||
To “propagate” a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for infringement under
|
||||
applicable copyright law, except executing it on a computer or modifying a private
|
||||
copy. Propagation includes copying, distribution (with or without modification),
|
||||
making available to the public, and in some countries other activities as well.
|
||||
|
||||
To “convey” a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through a computer
|
||||
network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays “Appropriate Legal Notices” to the
|
||||
extent that it includes a convenient and prominently visible feature that (1)
|
||||
displays an appropriate copyright notice, and (2) tells the user that there is no
|
||||
warranty for the work (except to the extent that warranties are provided), that
|
||||
licensees may convey the work under this License, and how to view a copy of this
|
||||
License. If the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
### 1. Source Code.
|
||||
|
||||
The “source code” for a work means the preferred form of the work for
|
||||
making modifications to it. “Object code” means any non-source form of a
|
||||
work.
|
||||
|
||||
A “Standard Interface” means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of interfaces
|
||||
specified for a particular programming language, one that is widely used among
|
||||
developers working in that language.
|
||||
|
||||
The “System Libraries” of an executable work include anything, other than
|
||||
the work as a whole, that (a) is included in the normal form of packaging a Major
|
||||
Component, but which is not part of that Major Component, and (b) serves only to
|
||||
enable use of the work with that Major Component, or to implement a Standard
|
||||
Interface for which an implementation is available to the public in source code form.
|
||||
A “Major Component”, in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system (if any) on which
|
||||
the executable work runs, or a compiler used to produce the work, or an object code
|
||||
interpreter used to run it.
|
||||
|
||||
The “Corresponding Source” for a work in object code form means all the
|
||||
source code needed to generate, install, and (for an executable work) run the object
|
||||
code and to modify the work, including scripts to control those activities. However,
|
||||
it does not include the work's System Libraries, or general-purpose tools or
|
||||
generally available free programs which are used unmodified in performing those
|
||||
activities but which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for the work, and
|
||||
the source code for shared libraries and dynamically linked subprograms that the work
|
||||
is specifically designed to require, such as by intimate data communication or
|
||||
control flow between those subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users can regenerate
|
||||
automatically from other parts of the Corresponding Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that same work.
|
||||
|
||||
### 2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of copyright on the
|
||||
Program, and are irrevocable provided the stated conditions are met. This License
|
||||
explicitly affirms your unlimited permission to run the unmodified Program. The
|
||||
output from running a covered work is covered by this License only if the output,
|
||||
given its content, constitutes a covered work. This License acknowledges your rights
|
||||
of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not convey, without
|
||||
conditions so long as your license otherwise remains in force. You may convey covered
|
||||
works to others for the sole purpose of having them make modifications exclusively
|
||||
for you, or provide you with facilities for running those works, provided that you
|
||||
comply with the terms of this License in conveying all material for which you do not
|
||||
control copyright. Those thus making or running the covered works for you must do so
|
||||
exclusively on your behalf, under your direction and control, on terms that prohibit
|
||||
them from making any copies of your copyrighted material outside their relationship
|
||||
with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under the conditions
|
||||
stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||
|
||||
### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological measure under any
|
||||
applicable law fulfilling obligations under article 11 of the WIPO copyright treaty
|
||||
adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention
|
||||
of such measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid circumvention of
|
||||
technological measures to the extent such circumvention is effected by exercising
|
||||
rights under this License with respect to the covered work, and you disclaim any
|
||||
intention to limit operation or modification of the work as a means of enforcing,
|
||||
against the work's users, your or third parties' legal rights to forbid circumvention
|
||||
of technological measures.
|
||||
|
||||
### 4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you receive it, in any
|
||||
medium, provided that you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice; keep intact all notices stating that this License and
|
||||
any non-permissive terms added in accord with section 7 apply to the code; keep
|
||||
intact all notices of the absence of any warranty; and give all recipients a copy of
|
||||
this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey, and you may offer
|
||||
support or warranty protection for a fee.
|
||||
|
||||
### 5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to produce it from
|
||||
the Program, in the form of source code under the terms of section 4, provided that
|
||||
you also meet all of these conditions:
|
||||
|
||||
* **a)** The work must carry prominent notices stating that you modified it, and giving a
|
||||
relevant date.
|
||||
* **b)** The work must carry prominent notices stating that it is released under this
|
||||
License and any conditions added under section 7. This requirement modifies the
|
||||
requirement in section 4 to “keep intact all notices”.
|
||||
* **c)** You must license the entire work, as a whole, under this License to anyone who
|
||||
comes into possession of a copy. This License will therefore apply, along with any
|
||||
applicable section 7 additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no permission to license the
|
||||
work in any other way, but it does not invalidate such permission if you have
|
||||
separately received it.
|
||||
* **d)** If the work has interactive user interfaces, each must display Appropriate Legal
|
||||
Notices; however, if the Program has interactive interfaces that do not display
|
||||
Appropriate Legal Notices, your work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent works, which are
|
||||
not by their nature extensions of the covered work, and which are not combined with
|
||||
it such as to form a larger program, in or on a volume of a storage or distribution
|
||||
medium, is called an “aggregate” if the compilation and its resulting
|
||||
copyright are not used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work in an aggregate
|
||||
does not cause this License to apply to the other parts of the aggregate.
|
||||
|
||||
### 6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms of sections 4 and
|
||||
5, provided that you also convey the machine-readable Corresponding Source under the
|
||||
terms of this License, in one of these ways:
|
||||
|
||||
* **a)** Convey the object code in, or embodied in, a physical product (including a
|
||||
physical distribution medium), accompanied by the Corresponding Source fixed on a
|
||||
durable physical medium customarily used for software interchange.
|
||||
* **b)** Convey the object code in, or embodied in, a physical product (including a
|
||||
physical distribution medium), accompanied by a written offer, valid for at least
|
||||
three years and valid for as long as you offer spare parts or customer support for
|
||||
that product model, to give anyone who possesses the object code either (1) a copy of
|
||||
the Corresponding Source for all the software in the product that is covered by this
|
||||
License, on a durable physical medium customarily used for software interchange, for
|
||||
a price no more than your reasonable cost of physically performing this conveying of
|
||||
source, or (2) access to copy the Corresponding Source from a network server at no
|
||||
charge.
|
||||
* **c)** Convey individual copies of the object code with a copy of the written offer to
|
||||
provide the Corresponding Source. This alternative is allowed only occasionally and
|
||||
noncommercially, and only if you received the object code with such an offer, in
|
||||
accord with subsection 6b.
|
||||
* **d)** Convey the object code by offering access from a designated place (gratis or for
|
||||
a charge), and offer equivalent access to the Corresponding Source in the same way
|
||||
through the same place at no further charge. You need not require recipients to copy
|
||||
the Corresponding Source along with the object code. If the place to copy the object
|
||||
code is a network server, the Corresponding Source may be on a different server
|
||||
(operated by you or a third party) that supports equivalent copying facilities,
|
||||
provided you maintain clear directions next to the object code saying where to find
|
||||
the Corresponding Source. Regardless of what server hosts the Corresponding Source,
|
||||
you remain obligated to ensure that it is available for as long as needed to satisfy
|
||||
these requirements.
|
||||
* **e)** Convey the object code using peer-to-peer transmission, provided you inform
|
||||
other peers where the object code and Corresponding Source of the work are being
|
||||
offered to the general public at no charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded from the
|
||||
Corresponding Source as a System Library, need not be included in conveying the
|
||||
object code work.
|
||||
|
||||
A “User Product” is either (1) a “consumer product”, which
|
||||
means any tangible personal property which is normally used for personal, family, or
|
||||
household purposes, or (2) anything designed or sold for incorporation into a
|
||||
dwelling. In determining whether a product is a consumer product, doubtful cases
|
||||
shall be resolved in favor of coverage. For a particular product received by a
|
||||
particular user, “normally used” refers to a typical or common use of
|
||||
that class of product, regardless of the status of the particular user or of the way
|
||||
in which the particular user actually uses, or expects or is expected to use, the
|
||||
product. A product is a consumer product regardless of whether the product has
|
||||
substantial commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
“Installation Information” for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install and execute
|
||||
modified versions of a covered work in that User Product from a modified version of
|
||||
its Corresponding Source. The information must suffice to ensure that the continued
|
||||
functioning of the modified object code is in no case prevented or interfered with
|
||||
solely because modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or specifically for
|
||||
use in, a User Product, and the conveying occurs as part of a transaction in which
|
||||
the right of possession and use of the User Product is transferred to the recipient
|
||||
in perpetuity or for a fixed term (regardless of how the transaction is
|
||||
characterized), the Corresponding Source conveyed under this section must be
|
||||
accompanied by the Installation Information. But this requirement does not apply if
|
||||
neither you nor any third party retains the ability to install modified object code
|
||||
on the User Product (for example, the work has been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a requirement to
|
||||
continue to provide support service, warranty, or updates for a work that has been
|
||||
modified or installed by the recipient, or for the User Product in which it has been
|
||||
modified or installed. Access to a network may be denied when the modification itself
|
||||
materially and adversely affects the operation of the network or violates the rules
|
||||
and protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided, in accord with
|
||||
this section must be in a format that is publicly documented (and with an
|
||||
implementation available to the public in source code form), and must require no
|
||||
special password or key for unpacking, reading or copying.
|
||||
|
||||
### 7. Additional Terms.
|
||||
|
||||
“Additional permissions” are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions. Additional
|
||||
permissions that are applicable to the entire Program shall be treated as though they
|
||||
were included in this License, to the extent that they are valid under applicable
|
||||
law. If additional permissions apply only to part of the Program, that part may be
|
||||
used separately under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option remove any
|
||||
additional permissions from that copy, or from any part of it. (Additional
|
||||
permissions may be written to require their own removal in certain cases when you
|
||||
modify the work.) You may place additional permissions on material, added by you to a
|
||||
covered work, for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you add to a
|
||||
covered work, you may (if authorized by the copyright holders of that material)
|
||||
supplement the terms of this License with terms:
|
||||
|
||||
* **a)** Disclaiming warranty or limiting liability differently from the terms of
|
||||
sections 15 and 16 of this License; or
|
||||
* **b)** Requiring preservation of specified reasonable legal notices or author
|
||||
attributions in that material or in the Appropriate Legal Notices displayed by works
|
||||
containing it; or
|
||||
* **c)** Prohibiting misrepresentation of the origin of that material, or requiring that
|
||||
modified versions of such material be marked in reasonable ways as different from the
|
||||
original version; or
|
||||
* **d)** Limiting the use for publicity purposes of names of licensors or authors of the
|
||||
material; or
|
||||
* **e)** Declining to grant rights under trademark law for use of some trade names,
|
||||
trademarks, or service marks; or
|
||||
* **f)** Requiring indemnification of licensors and authors of that material by anyone
|
||||
who conveys the material (or modified versions of it) with contractual assumptions of
|
||||
liability to the recipient, for any liability that these contractual assumptions
|
||||
directly impose on those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered “further
|
||||
restrictions” within the meaning of section 10. If the Program as you received
|
||||
it, or any part of it, contains a notice stating that it is governed by this License
|
||||
along with a term that is a further restriction, you may remove that term. If a
|
||||
license document contains a further restriction but permits relicensing or conveying
|
||||
under this License, you may add to a covered work material governed by the terms of
|
||||
that license document, provided that the further restriction does not survive such
|
||||
relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you must place, in
|
||||
the relevant source files, a statement of the additional terms that apply to those
|
||||
files, or a notice indicating where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the form of a
|
||||
separately written license, or stated as exceptions; the above requirements apply
|
||||
either way.
|
||||
|
||||
### 8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly provided under
|
||||
this License. Any attempt otherwise to propagate or modify it is void, and will
|
||||
automatically terminate your rights under this License (including any patent licenses
|
||||
granted under the third paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your license from a
|
||||
particular copyright holder is reinstated (a) provisionally, unless and until the
|
||||
copyright holder explicitly and finally terminates your license, and (b) permanently,
|
||||
if the copyright holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is reinstated permanently
|
||||
if the copyright holder notifies you of the violation by some reasonable means, this
|
||||
is the first time you have received notice of violation of this License (for any
|
||||
work) from that copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the licenses of
|
||||
parties who have received copies or rights from you under this License. If your
|
||||
rights have been terminated and not permanently reinstated, you do not qualify to
|
||||
receive new licenses for the same material under section 10.
|
||||
|
||||
### 9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or run a copy of the
|
||||
Program. Ancillary propagation of a covered work occurring solely as a consequence of
|
||||
using peer-to-peer transmission to receive a copy likewise does not require
|
||||
acceptance. However, nothing other than this License grants you permission to
|
||||
propagate or modify any covered work. These actions infringe copyright if you do not
|
||||
accept this License. Therefore, by modifying or propagating a covered work, you
|
||||
indicate your acceptance of this License to do so.
|
||||
|
||||
### 10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically receives a license
|
||||
from the original licensors, to run, modify and propagate that work, subject to this
|
||||
License. You are not responsible for enforcing compliance by third parties with this
|
||||
License.
|
||||
|
||||
An “entity transaction” is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an organization, or
|
||||
merging organizations. If propagation of a covered work results from an entity
|
||||
transaction, each party to that transaction who receives a copy of the work also
|
||||
receives whatever licenses to the work the party's predecessor in interest had or
|
||||
could give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if the predecessor
|
||||
has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the rights granted or
|
||||
affirmed under this License. For example, you may not impose a license fee, royalty,
|
||||
or other charge for exercise of rights granted under this License, and you may not
|
||||
initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging
|
||||
that any patent claim is infringed by making, using, selling, offering for sale, or
|
||||
importing the Program or any portion of it.
|
||||
|
||||
### 11. Patents.
|
||||
|
||||
A “contributor” is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The work thus
|
||||
licensed is called the contributor's “contributor version”.
|
||||
|
||||
A contributor's “essential patent claims” are all patent claims owned or
|
||||
controlled by the contributor, whether already acquired or hereafter acquired, that
|
||||
would be infringed by some manner, permitted by this License, of making, using, or
|
||||
selling its contributor version, but do not include claims that would be infringed
|
||||
only as a consequence of further modification of the contributor version. For
|
||||
purposes of this definition, “control” includes the right to grant patent
|
||||
sublicenses in a manner consistent with the requirements of this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license
|
||||
under the contributor's essential patent claims, to make, use, sell, offer for sale,
|
||||
import and otherwise run, modify and propagate the contents of its contributor
|
||||
version.
|
||||
|
||||
In the following three paragraphs, a “patent license” is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent (such as an
|
||||
express permission to practice a patent or covenant not to sue for patent
|
||||
infringement). To “grant” such a patent license to a party means to make
|
||||
such an agreement or commitment not to enforce a patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license, and the
|
||||
Corresponding Source of the work is not available for anyone to copy, free of charge
|
||||
and under the terms of this License, through a publicly available network server or
|
||||
other readily accessible means, then you must either (1) cause the Corresponding
|
||||
Source to be so available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner consistent with
|
||||
the requirements of this License, to extend the patent license to downstream
|
||||
recipients. “Knowingly relying” means you have actual knowledge that, but
|
||||
for the patent license, your conveying the covered work in a country, or your
|
||||
recipient's use of the covered work in a country, would infringe one or more
|
||||
identifiable patents in that country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or arrangement, you
|
||||
convey, or propagate by procuring conveyance of, a covered work, and grant a patent
|
||||
license to some of the parties receiving the covered work authorizing them to use,
|
||||
propagate, modify or convey a specific copy of the covered work, then the patent
|
||||
license you grant is automatically extended to all recipients of the covered work and
|
||||
works based on it.
|
||||
|
||||
A patent license is “discriminatory” if it does not include within the
|
||||
scope of its coverage, prohibits the exercise of, or is conditioned on the
|
||||
non-exercise of one or more of the rights that are specifically granted under this
|
||||
License. You may not convey a covered work if you are a party to an arrangement with
|
||||
a third party that is in the business of distributing software, under which you make
|
||||
payment to the third party based on the extent of your activity of conveying the
|
||||
work, and under which the third party grants, to any of the parties who would receive
|
||||
the covered work from you, a discriminatory patent license (a) in connection with
|
||||
copies of the covered work conveyed by you (or copies made from those copies), or (b)
|
||||
primarily for and in connection with specific products or compilations that contain
|
||||
the covered work, unless you entered into that arrangement, or that patent license
|
||||
was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting any implied
|
||||
license or other defenses to infringement that may otherwise be available to you
|
||||
under applicable patent law.
|
||||
|
||||
### 12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or otherwise)
|
||||
that contradict the conditions of this License, they do not excuse you from the
|
||||
conditions of this License. If you cannot convey a covered work so as to satisfy
|
||||
simultaneously your obligations under this License and any other pertinent
|
||||
obligations, then as a consequence you may not convey it at all. For example, if you
|
||||
agree to terms that obligate you to collect a royalty for further conveying from
|
||||
those to whom you convey the Program, the only way you could satisfy both those terms
|
||||
and this License would be to refrain entirely from conveying the Program.
|
||||
|
||||
### 13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have permission to link or
|
||||
combine any covered work with a work licensed under version 3 of the GNU Affero
|
||||
General Public License into a single combined work, and to convey the resulting work.
|
||||
The terms of this License will continue to apply to the part which is the covered
|
||||
work, but the special requirements of the GNU Affero General Public License, section
|
||||
13, concerning interaction through a network will apply to the combination as such.
|
||||
|
||||
### 14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of the GNU
|
||||
General Public License from time to time. Such new versions will be similar in spirit
|
||||
to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies that
|
||||
a certain numbered version of the GNU General Public License “or any later
|
||||
version” applies to it, you have the option of following the terms and
|
||||
conditions either of that numbered version or of any later version published by the
|
||||
Free Software Foundation. If the Program does not specify a version number of the GNU
|
||||
General Public License, you may choose any version ever published by the Free
|
||||
Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future versions of the GNU
|
||||
General Public License can be used, that proxy's public statement of acceptance of a
|
||||
version permanently authorizes you to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different permissions. However, no
|
||||
additional obligations are imposed on any author or copyright holder as a result of
|
||||
your choosing to follow a later version.
|
||||
|
||||
### 15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
|
||||
QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
|
||||
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
### 16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
|
||||
COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS
|
||||
PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
|
||||
INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE
|
||||
OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
|
||||
WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
### 17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided above cannot be
|
||||
given local legal effect according to their terms, reviewing courts shall apply local
|
||||
law that most closely approximates an absolute waiver of all civil liability in
|
||||
connection with the Program, unless a warranty or assumption of liability accompanies
|
||||
a copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
## How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible use to
|
||||
the public, the best way to achieve this is to make it free software which everyone
|
||||
can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them
|
||||
to the start of each source file to most effectively state the exclusion of warranty;
|
||||
and each file should have at least the “copyright” line and a pointer to
|
||||
where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type 'show c' for details.
|
||||
|
||||
The hypothetical commands 'show w' and 'show c' should show the appropriate parts of
|
||||
the General Public License. Of course, your program's commands might be different;
|
||||
for a GUI interface, you would use an “about box”.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school, if any, to
|
||||
sign a “copyright disclaimer” for the program, if necessary. For more
|
||||
information on this, and how to apply and follow the GNU GPL, see
|
||||
<<https://www.gnu.org/licenses/>>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may consider it
|
||||
more useful to permit linking proprietary applications with the library. If this is
|
||||
what you want to do, use the GNU Lesser General Public License instead of this
|
||||
License. But first, please read
|
||||
<<https://www.gnu.org/philosophy/why-not-lgpl.html>>.
|
2
vendor/github.com/evilsocket/islazy/fs/doc.go
generated
vendored
Normal file
2
vendor/github.com/evilsocket/islazy/fs/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
// Package fs contains helper functions for file system access and enumeration.
|
||||
package fs
|
20
vendor/github.com/evilsocket/islazy/fs/glob.go
generated
vendored
Normal file
20
vendor/github.com/evilsocket/islazy/fs/glob.go
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Glob enumerates files on a given path using a globbing expression and
|
||||
// execute a callback for each of the files. The callback can interrupt
|
||||
// the loop by returning an error other than nil.
|
||||
func Glob(path string, expr string, cb func(fileName string) error) (err error) {
|
||||
var files []string
|
||||
if files, err = filepath.Glob(filepath.Join(path, expr)); err == nil {
|
||||
for _, fileName := range files {
|
||||
if err = cb(fileName); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
31
vendor/github.com/evilsocket/islazy/fs/line_reader.go
generated
vendored
Normal file
31
vendor/github.com/evilsocket/islazy/fs/line_reader.go
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
)
|
||||
|
||||
// LineReader accepts the name of a file and offset as argument
|
||||
// and will return a channel from which lines can be read
|
||||
// one at a time.
|
||||
func LineReader(filename string) (chan string, error) {
|
||||
fp, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := make(chan string)
|
||||
go func() {
|
||||
defer fp.Close()
|
||||
// we need to close the out channel in order
|
||||
// to signal the end-of-data condition
|
||||
defer close(out)
|
||||
scanner := bufio.NewScanner(fp)
|
||||
scanner.Split(bufio.ScanLines)
|
||||
for scanner.Scan() {
|
||||
out <- scanner.Text()
|
||||
}
|
||||
}()
|
||||
|
||||
return out, nil
|
||||
}
|
25
vendor/github.com/evilsocket/islazy/fs/misc.go
generated
vendored
Normal file
25
vendor/github.com/evilsocket/islazy/fs/misc.go
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Expand will expand a path with ~ to a full path of the current user.
|
||||
func Expand(path string) (string, error) {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Abs(strings.Replace(path, "~", usr.HomeDir, 1))
|
||||
}
|
||||
|
||||
// Exists returns true if the path exists.
|
||||
func Exists(path string) bool {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
2
vendor/github.com/evilsocket/islazy/log/doc.go
generated
vendored
Normal file
2
vendor/github.com/evilsocket/islazy/log/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
// Package log provides access to log functions.
|
||||
package log
|
62
vendor/github.com/evilsocket/islazy/log/format.go
generated
vendored
Normal file
62
vendor/github.com/evilsocket/islazy/log/format.go
generated
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/evilsocket/islazy/tui"
|
||||
)
|
||||
|
||||
var (
|
||||
// Tokens is a map of the tokens that can be used in Format
|
||||
// to insert values returned by the execution of a callback.
|
||||
Tokens = map[string]func() string{
|
||||
"{date}": func() string {
|
||||
return time.Now().Format(DateFormat)
|
||||
},
|
||||
"{time}": func() string {
|
||||
return time.Now().Format(TimeFormat)
|
||||
},
|
||||
"{datetime}": func() string {
|
||||
return time.Now().Format(DateTimeFormat)
|
||||
},
|
||||
"{level:value}": func() string {
|
||||
return strconv.Itoa(int(currLevel))
|
||||
},
|
||||
"{level:name}": func() string {
|
||||
return LevelNames[currLevel]
|
||||
},
|
||||
"{level:color}": func() string {
|
||||
return LevelColors[currLevel]
|
||||
},
|
||||
"{message}": func() string {
|
||||
return currMessage
|
||||
},
|
||||
}
|
||||
// Effects is a map of the tokens that can be used in Format to
|
||||
// change the properties of the text.
|
||||
Effects = map[string]string{
|
||||
"{bold}": tui.BOLD,
|
||||
"{dim}": tui.DIM,
|
||||
"{red}": tui.RED,
|
||||
"{green}": tui.GREEN,
|
||||
"{blue}": tui.BLUE,
|
||||
"{yellow}": tui.YELLOW,
|
||||
"{f:black}": tui.FOREBLACK,
|
||||
"{f:white}": tui.FOREWHITE,
|
||||
"{b:darkgray}": tui.BACKDARKGRAY,
|
||||
"{b:red}": tui.BACKRED,
|
||||
"{b:green}": tui.BACKGREEN,
|
||||
"{b:yellow}": tui.BACKYELLOW,
|
||||
"{b:lightblue}": tui.BACKLIGHTBLUE,
|
||||
"{reset}": tui.RESET,
|
||||
}
|
||||
// DateFormat is the default date format being used when filling the {date} log token.
|
||||
DateFormat = "06-Jan-02"
|
||||
// TimeFormat is the default time format being used when filling the {time} or {datetime} log tokens.
|
||||
TimeFormat = "15:04:05"
|
||||
// DateTimeFormat is the default date and time format being used when filling the {datetime} log token.
|
||||
DateTimeFormat = "2006-01-02 15:04:05"
|
||||
// Format is the default format being used when logging.
|
||||
Format = "{datetime} {level:color}{level:name}{reset} {message}"
|
||||
)
|
44
vendor/github.com/evilsocket/islazy/log/level.go
generated
vendored
Normal file
44
vendor/github.com/evilsocket/islazy/log/level.go
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"github.com/evilsocket/islazy/tui"
|
||||
)
|
||||
|
||||
// Verbosity represents the verbosity level of the logger.
|
||||
type Verbosity int
|
||||
|
||||
const (
|
||||
// Debug messages.
|
||||
DEBUG Verbosity = iota
|
||||
// Informative messages.
|
||||
INFO
|
||||
// Informative messages that are important.
|
||||
IMPORTANT
|
||||
// Warning messages.
|
||||
WARNING
|
||||
// Recoverable error conditions.
|
||||
ERROR
|
||||
// Fatal error conditions.
|
||||
FATAL
|
||||
)
|
||||
|
||||
var (
|
||||
// LevelNames is a map of the names ( {level:name} ) of each verbosity level.
|
||||
LevelNames = map[Verbosity]string{
|
||||
DEBUG: "dbg",
|
||||
INFO: "inf",
|
||||
IMPORTANT: "imp",
|
||||
WARNING: "war",
|
||||
ERROR: "err",
|
||||
FATAL: "!!!",
|
||||
}
|
||||
// LevelColors is a map of the colors ( {level:color} ) of each verbosity level.
|
||||
LevelColors = map[Verbosity]string{
|
||||
DEBUG: tui.DIM + tui.FOREBLACK + tui.BACKDARKGRAY,
|
||||
INFO: tui.FOREWHITE + tui.BACKGREEN,
|
||||
IMPORTANT: tui.FOREWHITE + tui.BACKLIGHTBLUE,
|
||||
WARNING: tui.FOREWHITE + tui.BACKYELLOW,
|
||||
ERROR: tui.FOREWHITE + tui.BACKRED,
|
||||
FATAL: tui.FOREWHITE + tui.BACKRED + tui.BOLD,
|
||||
}
|
||||
)
|
127
vendor/github.com/evilsocket/islazy/log/log.go
generated
vendored
Normal file
127
vendor/github.com/evilsocket/islazy/log/log.go
generated
vendored
Normal file
|
@ -0,0 +1,127 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/evilsocket/islazy/tui"
|
||||
)
|
||||
|
||||
var (
|
||||
// Level represents the current verbosity level of the logging system.
|
||||
Level = INFO
|
||||
// Output represents the log output file path if filled or, if empty, stdout.
|
||||
Output = ""
|
||||
// NoEffects disables all effects and colors if set to true.
|
||||
NoEffects = false
|
||||
// OnFatal represents the callback/action to execute on Fatal messages.
|
||||
OnFatal = ExitOnFatal
|
||||
|
||||
lock = &sync.Mutex{}
|
||||
currMessage = ""
|
||||
currLevel = INFO
|
||||
writer = os.Stdout
|
||||
|
||||
reEffects = []*regexp.Regexp{
|
||||
regexp.MustCompile("\x033\\[\\d+m"),
|
||||
regexp.MustCompile("\\\\e\\[\\d+m"),
|
||||
regexp.MustCompile("\x1b\\[\\d+m"),
|
||||
}
|
||||
)
|
||||
|
||||
// Open initializes the logging system.
|
||||
func Open() (err error) {
|
||||
if Output != "" {
|
||||
writer, err = os.OpenFile(Output, os.O_APPEND|os.O_RDWR|os.O_CREATE, 0644)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Close finalizes the logging system.
|
||||
func Close() {
|
||||
if writer != os.Stdout {
|
||||
writer.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func emit(s string) {
|
||||
// remove all effects if found
|
||||
if NoEffects {
|
||||
for _, re := range reEffects {
|
||||
s = re.ReplaceAllString(s, "")
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(writer, s)
|
||||
fmt.Fprintf(writer, "\n")
|
||||
}
|
||||
|
||||
func do(v Verbosity, format string, args ...interface{}) {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
|
||||
if Level > v {
|
||||
return
|
||||
}
|
||||
|
||||
logLine := Format
|
||||
currLevel = v
|
||||
currMessage = fmt.Sprintf(format, args...)
|
||||
// process token -> callback
|
||||
for token, cb := range Tokens {
|
||||
logLine = strings.Replace(logLine, token, cb(), -1)
|
||||
}
|
||||
// process token -> effect
|
||||
for token, effect := range Effects {
|
||||
logLine = strings.Replace(logLine, token, effect, -1)
|
||||
}
|
||||
// make sure an user error does not screw the log
|
||||
if tui.HasEffect(logLine) && !strings.HasSuffix(logLine, tui.RESET) {
|
||||
logLine += tui.RESET
|
||||
}
|
||||
|
||||
emit(logLine)
|
||||
}
|
||||
|
||||
// Raw emits a message without format to the logs.
|
||||
func Raw(format string, args ...interface{}) {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
|
||||
currMessage = fmt.Sprintf(format, args...)
|
||||
emit(currMessage)
|
||||
}
|
||||
|
||||
// Debug emits a debug message.
|
||||
func Debug(format string, args ...interface{}) {
|
||||
do(DEBUG, format, args...)
|
||||
}
|
||||
|
||||
// Info emits an informative message.
|
||||
func Info(format string, args ...interface{}) {
|
||||
do(INFO, format, args...)
|
||||
}
|
||||
|
||||
// Important emits an important informative message.
|
||||
func Important(format string, args ...interface{}) {
|
||||
do(IMPORTANT, format, args...)
|
||||
}
|
||||
|
||||
// Warning emits a warning message.
|
||||
func Warning(format string, args ...interface{}) {
|
||||
do(WARNING, format, args...)
|
||||
}
|
||||
|
||||
// Error emits an error message.
|
||||
func Error(format string, args ...interface{}) {
|
||||
do(ERROR, format, args...)
|
||||
}
|
||||
|
||||
// Fata emits a fatal error message and calls the log.OnFatal callback.
|
||||
func Fatal(format string, args ...interface{}) {
|
||||
do(FATAL, format, args...)
|
||||
OnFatal()
|
||||
}
|
23
vendor/github.com/evilsocket/islazy/log/policy.go
generated
vendored
Normal file
23
vendor/github.com/evilsocket/islazy/log/policy.go
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// FatalPolicy represents a callback to be executed on Fatal messages.
|
||||
type FatalPolicy func()
|
||||
|
||||
// os.Exit(1) on Fatal messages.
|
||||
func ExitOnFatal() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// os.Exit(0) on Fatal messages.
|
||||
func ExitCleanOnFatal() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Do nothing on Fatal messages.
|
||||
func NoneOnFatal() {
|
||||
|
||||
}
|
2
vendor/github.com/evilsocket/islazy/str/doc.go
generated
vendored
Normal file
2
vendor/github.com/evilsocket/islazy/str/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
// Package str contains utilities for string manipulation.
|
||||
package str
|
24
vendor/github.com/evilsocket/islazy/str/split.go
generated
vendored
Normal file
24
vendor/github.com/evilsocket/islazy/str/split.go
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
package str
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// SplitBy splits by a separator a string and returns a
|
||||
// list of the non empty parts.
|
||||
func SplitBy(sv string, sep string) []string {
|
||||
filtered := make([]string, 0)
|
||||
for _, part := range strings.Split(sv, sep) {
|
||||
part = Trim(part)
|
||||
if part != "" {
|
||||
filtered = append(filtered, part)
|
||||
}
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
// Comma splits by comma a string and returns a
|
||||
// list of the non empty parts.
|
||||
func Comma(csv string) []string {
|
||||
return SplitBy(csv, ",")
|
||||
}
|
24
vendor/github.com/evilsocket/islazy/str/trim.go
generated
vendored
Normal file
24
vendor/github.com/evilsocket/islazy/str/trim.go
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
package str
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
whiteSpaceTrimSet = "\r\n\t "
|
||||
)
|
||||
|
||||
// Trim trims a string from white spaces.
|
||||
func Trim(s string) string {
|
||||
return strings.Trim(s, whiteSpaceTrimSet)
|
||||
}
|
||||
|
||||
// TrimRight trims the right part of a string from white spaces.
|
||||
func TrimRight(s string) string {
|
||||
return strings.TrimRight(s, whiteSpaceTrimSet)
|
||||
}
|
||||
|
||||
// TrimLeft trims the left part of a string from white spaces.
|
||||
func TrimLeft(s string) string {
|
||||
return strings.TrimLeft(s, whiteSpaceTrimSet)
|
||||
}
|
104
vendor/github.com/evilsocket/islazy/tui/colors.go
generated
vendored
Normal file
104
vendor/github.com/evilsocket/islazy/tui/colors.go
generated
vendored
Normal file
|
@ -0,0 +1,104 @@
|
|||
package tui
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// https://misc.flogisoft.com/bash/tip_colors_and_formatting
|
||||
var (
|
||||
// effects
|
||||
BOLD = "\033[1m"
|
||||
DIM = "\033[2m"
|
||||
RESET = "\033[0m"
|
||||
// colors
|
||||
RED = "\033[31m"
|
||||
GREEN = "\033[32m"
|
||||
BLUE = "\033[34m"
|
||||
YELLOW = "\033[33m"
|
||||
// foreground colors
|
||||
FOREBLACK = "\033[30m"
|
||||
FOREWHITE = "\033[97m"
|
||||
// background colors
|
||||
BACKDARKGRAY = "\033[100m"
|
||||
BACKRED = "\033[41m"
|
||||
BACKGREEN = "\033[42m"
|
||||
BACKYELLOW = "\033[43m"
|
||||
BACKLIGHTBLUE = "\033[104m"
|
||||
|
||||
ctrl = []string{"\x033", "\\e", "\x1b"}
|
||||
)
|
||||
|
||||
// Effects returns true if colors and effects are supported
|
||||
// on the current terminal.
|
||||
func Effects() bool {
|
||||
if term := os.Getenv("TERM"); term == "" {
|
||||
return false
|
||||
} else if term == "dumb" {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Disable will disable all colors and effects.
|
||||
func Disable() {
|
||||
BOLD = ""
|
||||
DIM = ""
|
||||
RESET = ""
|
||||
RED = ""
|
||||
GREEN = ""
|
||||
BLUE = ""
|
||||
YELLOW = ""
|
||||
FOREBLACK = ""
|
||||
FOREWHITE = ""
|
||||
BACKDARKGRAY = ""
|
||||
BACKRED = ""
|
||||
BACKGREEN = ""
|
||||
BACKYELLOW = ""
|
||||
BACKLIGHTBLUE = ""
|
||||
}
|
||||
|
||||
// HasEffect returns true if the string has any shell control codes in it.
|
||||
func HasEffect(s string) bool {
|
||||
for _, ch := range ctrl {
|
||||
if strings.Contains(s, ch) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Wrap wraps a string with an effect or color and appends a reset control code.
|
||||
func Wrap(e, s string) string {
|
||||
return e + s + RESET
|
||||
}
|
||||
|
||||
// Bold makes the string Bold.
|
||||
func Bold(s string) string {
|
||||
return Wrap(BOLD, s)
|
||||
}
|
||||
|
||||
// Dim makes the string Diminished.
|
||||
func Dim(s string) string {
|
||||
return Wrap(DIM, s)
|
||||
}
|
||||
|
||||
// Red makes the string Red.
|
||||
func Red(s string) string {
|
||||
return Wrap(RED, s)
|
||||
}
|
||||
|
||||
// Green makes the string Green.
|
||||
func Green(s string) string {
|
||||
return Wrap(GREEN, s)
|
||||
}
|
||||
|
||||
// Blue makes the string Green.
|
||||
func Blue(s string) string {
|
||||
return Wrap(BLUE, s)
|
||||
}
|
||||
|
||||
// Yellow makes the string Green.
|
||||
func Yellow(s string) string {
|
||||
return Wrap(YELLOW, s)
|
||||
}
|
3
vendor/github.com/evilsocket/islazy/tui/doc.go
generated
vendored
Normal file
3
vendor/github.com/evilsocket/islazy/tui/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
// Package tui contains a set of helper objects and functions for terminal
|
||||
// based user interfaces.
|
||||
package tui
|
110
vendor/github.com/evilsocket/islazy/tui/table.go
generated
vendored
Normal file
110
vendor/github.com/evilsocket/islazy/tui/table.go
generated
vendored
Normal file
|
@ -0,0 +1,110 @@
|
|||
package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
var ansi = regexp.MustCompile("\033\\[(?:[0-9]{1,3}(?:;[0-9]{1,3})*)?[m|K]")
|
||||
|
||||
func viewLen(s string) int {
|
||||
for _, m := range ansi.FindAllString(s, -1) {
|
||||
s = strings.Replace(s, m, "", -1)
|
||||
}
|
||||
return utf8.RuneCountInString(s)
|
||||
}
|
||||
|
||||
func maxLen(strings []string) int {
|
||||
maxLen := 0
|
||||
for _, s := range strings {
|
||||
len := viewLen(s)
|
||||
if len > maxLen {
|
||||
maxLen = len
|
||||
}
|
||||
}
|
||||
return maxLen
|
||||
}
|
||||
|
||||
type alignment int
|
||||
|
||||
const (
|
||||
alignLeft = alignment(0)
|
||||
alignCenter = alignment(1)
|
||||
alignRight = alignment(2)
|
||||
)
|
||||
|
||||
func getPads(s string, maxLen int, align alignment) (lPad int, rPad int) {
|
||||
len := viewLen(s)
|
||||
diff := maxLen - len
|
||||
|
||||
if align == alignLeft {
|
||||
lPad = 0
|
||||
rPad = diff - lPad + 1
|
||||
} else if align == alignCenter {
|
||||
lPad = diff / 2
|
||||
rPad = diff - lPad + 1
|
||||
} /* else {
|
||||
TODO
|
||||
} */
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func padded(s string, maxLen int, align alignment) string {
|
||||
lPad, rPad := getPads(s, maxLen, align)
|
||||
return fmt.Sprintf("%s%s%s", strings.Repeat(" ", lPad), s, strings.Repeat(" ", rPad))
|
||||
}
|
||||
|
||||
// Table accepts a slice of column labels and a 2d slice of rows
|
||||
// and prints on the writer an ASCII based datagrid of such
|
||||
// data.
|
||||
func Table(w io.Writer, columns []string, rows [][]string) {
|
||||
for i, col := range columns {
|
||||
columns[i] = fmt.Sprintf(" %s ", col)
|
||||
}
|
||||
|
||||
for i, row := range rows {
|
||||
for j, cell := range row {
|
||||
rows[i][j] = fmt.Sprintf(" %s ", cell)
|
||||
}
|
||||
}
|
||||
|
||||
colPaddings := make([]int, 0)
|
||||
lineSep := ""
|
||||
for colIndex, colHeader := range columns {
|
||||
column := []string{colHeader}
|
||||
for _, row := range rows {
|
||||
column = append(column, row[colIndex])
|
||||
}
|
||||
mLen := maxLen(column)
|
||||
colPaddings = append(colPaddings, mLen)
|
||||
lineSep += fmt.Sprintf("+%s", strings.Repeat("-", mLen+1))
|
||||
}
|
||||
lineSep += "+"
|
||||
|
||||
table := ""
|
||||
|
||||
// header
|
||||
table += fmt.Sprintf("%s\n", lineSep)
|
||||
for colIndex, colHeader := range columns {
|
||||
table += fmt.Sprintf("|%s", padded(colHeader, colPaddings[colIndex], alignCenter))
|
||||
}
|
||||
table += fmt.Sprintf("|\n")
|
||||
table += fmt.Sprintf("%s\n", lineSep)
|
||||
|
||||
// rows
|
||||
for _, row := range rows {
|
||||
for colIndex, cell := range row {
|
||||
table += fmt.Sprintf("|%s", padded(cell, colPaddings[colIndex], alignLeft))
|
||||
}
|
||||
table += fmt.Sprintf("|\n")
|
||||
}
|
||||
|
||||
// footer
|
||||
table += lineSep
|
||||
|
||||
fmt.Fprintf(w, "\n%s\n", table)
|
||||
}
|
2
vendor/github.com/evilsocket/islazy/zip/doc.go
generated
vendored
Normal file
2
vendor/github.com/evilsocket/islazy/zip/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
// Package zip contains zip and unzip utilities.
|
||||
package zip
|
55
vendor/github.com/evilsocket/islazy/zip/unzip.go
generated
vendored
Normal file
55
vendor/github.com/evilsocket/islazy/zip/unzip.go
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
package zip
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Unzip will decompress a zip archive, moving all files and folders
|
||||
// within the zip file (parameter 1) to an output directory (parameter 2).
|
||||
// Credits to https://golangcode.com/unzip-files-in-go/
|
||||
func Unzip(src string, dest string) ([]string, error) {
|
||||
var filenames []string
|
||||
|
||||
r, err := zip.OpenReader(src)
|
||||
if err != nil {
|
||||
return filenames, err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
for _, f := range r.File {
|
||||
rc, err := f.Open()
|
||||
if err != nil {
|
||||
return filenames, err
|
||||
}
|
||||
defer rc.Close()
|
||||
|
||||
// Store filename/path for returning and using later on
|
||||
fpath := filepath.Join(dest, f.Name)
|
||||
|
||||
// Check for ZipSlip. More Info: https://snyk.io/research/zip-slip-vulnerability#go
|
||||
if !strings.HasPrefix(fpath, filepath.Clean(dest)+string(os.PathSeparator)) {
|
||||
return filenames, fmt.Errorf("%s: illegal file path", fpath)
|
||||
}
|
||||
|
||||
filenames = append(filenames, fpath)
|
||||
if f.FileInfo().IsDir() {
|
||||
os.MkdirAll(fpath, os.ModePerm)
|
||||
} else if err = os.MkdirAll(filepath.Dir(fpath), os.ModePerm); err != nil {
|
||||
return filenames, err
|
||||
} else if outFile, err := os.OpenFile(fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()); err != nil {
|
||||
return filenames, err
|
||||
} else {
|
||||
defer outFile.Close()
|
||||
if _, err = io.Copy(outFile, rc); err != nil {
|
||||
return filenames, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filenames, nil
|
||||
}
|
10
vendor/github.com/gobwas/glob/readme.md
generated
vendored
10
vendor/github.com/gobwas/glob/readme.md
generated
vendored
|
@ -126,10 +126,10 @@ Pattern | Fixture | Match | Speed (ns/op)
|
|||
`^[a-z][^a-x].*cat.*[h][^b].*eyes.*$` | `my dog has very bright eyes` | `false` | 1383
|
||||
`^https:\/\/.*\.google\..*$` | `https://account.google.com` | `true` | 1205
|
||||
`^https:\/\/.*\.google\..*$` | `https://google.com` | `false` | 767
|
||||
`^(https:\/\/.*\.google\..*|.*yandex\..*|.*yahoo\..*|.*mail\.ru)$` | `http://yahoo.com` | `true` | 1435
|
||||
`^(https:\/\/.*\.google\..*|.*yandex\..*|.*yahoo\..*|.*mail\.ru)$` | `http://google.com` | `false` | 1674
|
||||
`^(https:\/\/.*gobwas\.com|http://exclude.gobwas.com)$` | `https://safe.gobwas.com` | `true` | 1039
|
||||
`^(https:\/\/.*gobwas\.com|http://exclude.gobwas.com)$` | `http://safe.gobwas.com` | `false` | 272
|
||||
`^(https:\/\/.*\.google\..*\|.*yandex\..*\|.*yahoo\..*\|.*mail\.ru)$` | `http://yahoo.com` | `true` | 1435
|
||||
`^(https:\/\/.*\.google\..*\|.*yandex\..*\|.*yahoo\..*\|.*mail\.ru)$` | `http://google.com` | `false` | 1674
|
||||
`^(https:\/\/.*gobwas\.com\|http://exclude.gobwas.com)$` | `https://safe.gobwas.com` | `true` | 1039
|
||||
`^(https:\/\/.*gobwas\.com\|http://exclude.gobwas.com)$` | `http://safe.gobwas.com` | `false` | 272
|
||||
`^abc.*$` | `abcdef` | `true` | 237
|
||||
`^abc.*$` | `af` | `false` | 100
|
||||
`^.*def$` | `abcdef` | `true` | 464
|
||||
|
@ -145,4 +145,4 @@ Pattern | Fixture | Match | Speed (ns/op)
|
|||
## Syntax
|
||||
|
||||
Syntax is inspired by [standard wildcards](http://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm),
|
||||
except that `**` is aka super-asterisk, that do not sensitive for separators.
|
||||
except that `**` is aka super-asterisk, that do not sensitive for separators.
|
||||
|
|
9
vendor/github.com/google/gopacket/.travis.golint.sh
generated
vendored
9
vendor/github.com/google/gopacket/.travis.golint.sh
generated
vendored
|
@ -3,7 +3,7 @@
|
|||
cd "$(dirname $0)"
|
||||
|
||||
go get github.com/golang/lint/golint
|
||||
DIRS=". tcpassembly tcpassembly/tcpreader ip4defrag reassembly macs pcapgo pcap afpacket pfring routing"
|
||||
DIRS=". tcpassembly tcpassembly/tcpreader ip4defrag reassembly macs pcapgo pcap afpacket pfring routing defrag/lcmdefrag"
|
||||
# Add subdirectories here as we clean up golint on each.
|
||||
for subdir in $DIRS; do
|
||||
pushd $subdir
|
||||
|
@ -17,8 +17,11 @@ for subdir in $DIRS; do
|
|||
done
|
||||
|
||||
pushd layers
|
||||
for file in $(cat .linted); do
|
||||
if golint $file | grep .; then
|
||||
for file in *.go; do
|
||||
if cat .lint_blacklist | grep -q $file; then
|
||||
echo "Skipping lint of $file due to .lint_blacklist"
|
||||
elif golint $file | grep .; then
|
||||
echo "Lint error in file $file"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
|
2
vendor/github.com/google/gopacket/.travis.govet.sh
generated
vendored
2
vendor/github.com/google/gopacket/.travis.govet.sh
generated
vendored
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd "$(dirname $0)"
|
||||
DIRS=". layers pcap pcapgo pfring tcpassembly tcpassembly/tcpreader routing ip4defrag bytediff macs"
|
||||
DIRS=". layers pcap pcapgo tcpassembly tcpassembly/tcpreader routing ip4defrag bytediff macs defrag/lcmdefrag"
|
||||
set -e
|
||||
for subdir in $DIRS; do
|
||||
pushd $subdir
|
||||
|
|
4
vendor/github.com/google/gopacket/.travis.yml
generated
vendored
4
vendor/github.com/google/gopacket/.travis.yml
generated
vendored
|
@ -1,12 +1,16 @@
|
|||
language: go
|
||||
before_install:
|
||||
- sudo apt-get install libpcap-dev
|
||||
install:
|
||||
- go get github.com/google/gopacket
|
||||
- go get github.com/google/gopacket/layers
|
||||
- go get github.com/google/gopacket/pcapgo
|
||||
- go get github.com/google/gopacket/tcpassembly
|
||||
- go get github.com/google/gopacket/reassembly
|
||||
script:
|
||||
- go test github.com/google/gopacket
|
||||
- go test github.com/google/gopacket/layers
|
||||
- go test github.com/google/gopacket/pcapgo
|
||||
- go test github.com/google/gopacket/tcpassembly
|
||||
- go test github.com/google/gopacket/reassembly
|
||||
- ./.travis.gofmt.sh
|
||||
|
|
2
vendor/github.com/google/gopacket/doc.go
generated
vendored
2
vendor/github.com/google/gopacket/doc.go
generated
vendored
|
@ -329,7 +329,7 @@ the following manner:
|
|||
}
|
||||
buf := gopacket.NewSerializeBuffer()
|
||||
opts := gopacket.SerializeOptions{} // See SerializeOptions for more details.
|
||||
err := ip.SerializeTo(&buf, opts)
|
||||
err := ip.SerializeTo(buf, opts)
|
||||
if err != nil { panic(err) }
|
||||
fmt.Println(buf.Bytes()) // prints out a byte slice containing the serialized IPv4 layer.
|
||||
|
||||
|
|
10
vendor/github.com/google/gopacket/gc
generated
vendored
10
vendor/github.com/google/gopacket/gc
generated
vendored
|
@ -106,6 +106,7 @@ if [ ! -z "$GEN" ]; then
|
|||
popd
|
||||
pushd layers
|
||||
go run gen.go | gofmt > iana_ports.go
|
||||
go run gen2.go | gofmt > enums_generated.go
|
||||
popd
|
||||
fi
|
||||
|
||||
|
@ -126,6 +127,9 @@ if [ -f /usr/include/pcap.h ]; then
|
|||
Root pcap_tester --mode=filtered
|
||||
Root pcap_tester --mode=timestamp || echo "You might not support timestamp sources"
|
||||
popd
|
||||
pushd examples/afpacket
|
||||
go build
|
||||
popd
|
||||
pushd examples/pcapdump
|
||||
go build
|
||||
popd
|
||||
|
@ -182,6 +186,12 @@ if [ -f /usr/include/pfring.h ]; then
|
|||
go build
|
||||
popd
|
||||
fi
|
||||
pushd ip4defrag
|
||||
go test ./...
|
||||
popd
|
||||
pushd defrag
|
||||
go test ./...
|
||||
popd
|
||||
|
||||
for travis_script in `ls .travis.*.sh`; do
|
||||
./$travis_script
|
||||
|
|
33
vendor/github.com/google/gopacket/layers/.lint_blacklist
generated
vendored
Normal file
33
vendor/github.com/google/gopacket/layers/.lint_blacklist
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
dot11.go
|
||||
eap.go
|
||||
endpoints.go
|
||||
enums_generated.go
|
||||
enums.go
|
||||
ethernet.go
|
||||
geneve.go
|
||||
icmp4.go
|
||||
icmp6.go
|
||||
igmp.go
|
||||
ip4.go
|
||||
ip6.go
|
||||
layertypes.go
|
||||
linux_sll.go
|
||||
llc.go
|
||||
lldp.go
|
||||
mpls.go
|
||||
ndp.go
|
||||
ntp.go
|
||||
ospf.go
|
||||
pflog.go
|
||||
pppoe.go
|
||||
prism.go
|
||||
radiotap.go
|
||||
rudp.go
|
||||
sctp.go
|
||||
sflow.go
|
||||
tcp.go
|
||||
tcpip.go
|
||||
udp.go
|
||||
udplite.go
|
||||
usb.go
|
||||
vrrp.go
|
40
vendor/github.com/google/gopacket/layers/.linted
generated
vendored
40
vendor/github.com/google/gopacket/layers/.linted
generated
vendored
|
@ -1,40 +0,0 @@
|
|||
arp.go
|
||||
base.go
|
||||
base_test.go
|
||||
cdp.go
|
||||
ctp.go
|
||||
decode_test.go
|
||||
dhcp_test.go
|
||||
dhcpv4.go
|
||||
dns.go
|
||||
dns_test.go
|
||||
doc.go
|
||||
dot11_test.go
|
||||
dot1q.go
|
||||
dot1q_test.go
|
||||
eapol.go
|
||||
etherip.go
|
||||
fddi.go
|
||||
gen.go
|
||||
gre.go
|
||||
gre_test.go
|
||||
iana_ports.go
|
||||
icmp6_test.go
|
||||
igmp_test.go
|
||||
ip4_test.go
|
||||
ipsec.go
|
||||
ipsec_test.go
|
||||
loopback.go
|
||||
mpls_test.go
|
||||
ntp_test.go
|
||||
ports.go
|
||||
ppp.go
|
||||
prism_test.go
|
||||
radiotap_test.go
|
||||
sflow_test.go
|
||||
tcp_test.go
|
||||
udp_test.go
|
||||
usb_test.go
|
||||
vrrp_test.go
|
||||
vxlan.go
|
||||
vxlan_test.go
|
481
vendor/github.com/google/gopacket/layers/bfd.go
generated
vendored
Normal file
481
vendor/github.com/google/gopacket/layers/bfd.go
generated
vendored
Normal file
|
@ -0,0 +1,481 @@
|
|||
// Copyright 2017 Google, Inc. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree.
|
||||
//
|
||||
|
||||
package layers
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
)
|
||||
|
||||
// BFD Control Packet Format
|
||||
// -------------------------
|
||||
// The current version of BFD's RFC (RFC 5880) contains the following
|
||||
// diagram for the BFD Control packet format:
|
||||
//
|
||||
// 0 1 2 3
|
||||
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// |Vers | Diag |Sta|P|F|C|A|D|M| Detect Mult | Length |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | My Discriminator |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | Your Discriminator |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | Desired Min TX Interval |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | Required Min RX Interval |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | Required Min Echo RX Interval |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
//
|
||||
// An optional Authentication Section MAY be present:
|
||||
//
|
||||
// 0 1 2 3
|
||||
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | Auth Type | Auth Len | Authentication Data... |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
//
|
||||
//
|
||||
// Simple Password Authentication Section Format
|
||||
// ---------------------------------------------
|
||||
// 0 1 2 3
|
||||
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | Auth Type | Auth Len | Auth Key ID | Password... |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | ... |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
//
|
||||
//
|
||||
// Keyed MD5 and Meticulous Keyed MD5 Authentication Section Format
|
||||
// ----------------------------------------------------------------
|
||||
// 0 1 2 3
|
||||
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | Auth Type | Auth Len | Auth Key ID | Reserved |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | Sequence Number |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | Auth Key/Digest... |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | ... |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
//
|
||||
//
|
||||
// Keyed SHA1 and Meticulous Keyed SHA1 Authentication Section Format
|
||||
// ------------------------------------------------------------------
|
||||
// 0 1 2 3
|
||||
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | Auth Type | Auth Len | Auth Key ID | Reserved |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | Sequence Number |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | Auth Key/Hash... |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | ... |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
//
|
||||
// From https://tools.ietf.org/rfc/rfc5880.txt
|
||||
const bfdMinimumRecordSizeInBytes int = 24
|
||||
|
||||
// BFDVersion represents the version as decoded from the BFD control message
|
||||
type BFDVersion uint8
|
||||
|
||||
// BFDDiagnostic represents diagnostic infomation about a BFD session
|
||||
type BFDDiagnostic uint8
|
||||
|
||||
// constants that define BFDDiagnostic flags
|
||||
const (
|
||||
BFDDiagnosticNone BFDDiagnostic = 0 // No Diagnostic
|
||||
BFDDiagnosticTimeExpired BFDDiagnostic = 1 // Control Detection Time Expired
|
||||
BFDDiagnosticEchoFailed BFDDiagnostic = 2 // Echo Function Failed
|
||||
BFDDiagnosticNeighborSignalDown BFDDiagnostic = 3 // Neighbor Signaled Session Down
|
||||
BFDDiagnosticForwardPlaneReset BFDDiagnostic = 4 // Forwarding Plane Reset
|
||||
BFDDiagnosticPathDown BFDDiagnostic = 5 // Path Down
|
||||
BFDDiagnosticConcatPathDown BFDDiagnostic = 6 // Concatenated Path Down
|
||||
BFDDiagnosticAdminDown BFDDiagnostic = 7 // Administratively Down
|
||||
BFDDiagnosticRevConcatPathDown BFDDiagnostic = 8 // Reverse Concatenated Path Dow
|
||||
)
|
||||
|
||||
// String returns a string version of BFDDiagnostic
|
||||
func (bd BFDDiagnostic) String() string {
|
||||
switch bd {
|
||||
default:
|
||||
return "Unknown"
|
||||
case BFDDiagnosticNone:
|
||||
return "None"
|
||||
case BFDDiagnosticTimeExpired:
|
||||
return "Control Detection Time Expired"
|
||||
case BFDDiagnosticEchoFailed:
|
||||
return "Echo Function Failed"
|
||||
case BFDDiagnosticNeighborSignalDown:
|
||||
return "Neighbor Signaled Session Down"
|
||||
case BFDDiagnosticForwardPlaneReset:
|
||||
return "Forwarding Plane Reset"
|
||||
case BFDDiagnosticPathDown:
|
||||
return "Path Down"
|
||||
case BFDDiagnosticConcatPathDown:
|
||||
return "Concatenated Path Down"
|
||||
case BFDDiagnosticAdminDown:
|
||||
return "Administratively Down"
|
||||
case BFDDiagnosticRevConcatPathDown:
|
||||
return "Reverse Concatenated Path Down"
|
||||
}
|
||||
}
|
||||
|
||||
// BFDState represents the state of a BFD session
|
||||
type BFDState uint8
|
||||
|
||||
// constants that define BFDState
|
||||
const (
|
||||
BFDStateAdminDown BFDState = 0
|
||||
BFDStateDown BFDState = 1
|
||||
BFDStateInit BFDState = 2
|
||||
BFDStateUp BFDState = 3
|
||||
)
|
||||
|
||||
// String returns a string version of BFDState
|
||||
func (s BFDState) String() string {
|
||||
switch s {
|
||||
default:
|
||||
return "Unknown"
|
||||
case BFDStateAdminDown:
|
||||
return "Admin Down"
|
||||
case BFDStateDown:
|
||||
return "Down"
|
||||
case BFDStateInit:
|
||||
return "Init"
|
||||
case BFDStateUp:
|
||||
return "Up"
|
||||
}
|
||||
}
|
||||
|
||||
// BFDDetectMultiplier represents the negotiated transmit interval,
|
||||
// multiplied by this value, provides the Detection Time for the
|
||||
// receiving system in Asynchronous mode.
|
||||
type BFDDetectMultiplier uint8
|
||||
|
||||
// BFDDiscriminator is a unique, nonzero discriminator value used
|
||||
// to demultiplex multiple BFD sessions between the same pair of systems.
|
||||
type BFDDiscriminator uint32
|
||||
|
||||
// BFDTimeInterval represents a time interval in microseconds
|
||||
type BFDTimeInterval uint32
|
||||
|
||||
// BFDAuthType represents the authentication used in the BFD session
|
||||
type BFDAuthType uint8
|
||||
|
||||
// constants that define the BFDAuthType
|
||||
const (
|
||||
BFDAuthTypeNone BFDAuthType = 0 // No Auth
|
||||
BFDAuthTypePassword BFDAuthType = 1 // Simple Password
|
||||
BFDAuthTypeKeyedMD5 BFDAuthType = 2 // Keyed MD5
|
||||
BFDAuthTypeMeticulousKeyedMD5 BFDAuthType = 3 // Meticulous Keyed MD5
|
||||
BFDAuthTypeKeyedSHA1 BFDAuthType = 4 // Keyed SHA1
|
||||
BFDAuthTypeMeticulousKeyedSHA1 BFDAuthType = 5 // Meticulous Keyed SHA1
|
||||
)
|
||||
|
||||
// String returns a string version of BFDAuthType
|
||||
func (at BFDAuthType) String() string {
|
||||
switch at {
|
||||
default:
|
||||
return "Unknown"
|
||||
case BFDAuthTypeNone:
|
||||
return "No Authentication"
|
||||
case BFDAuthTypePassword:
|
||||
return "Simple Password"
|
||||
case BFDAuthTypeKeyedMD5:
|
||||
return "Keyed MD5"
|
||||
case BFDAuthTypeMeticulousKeyedMD5:
|
||||
return "Meticulous Keyed MD5"
|
||||
case BFDAuthTypeKeyedSHA1:
|
||||
return "Keyed SHA1"
|
||||
case BFDAuthTypeMeticulousKeyedSHA1:
|
||||
return "Meticulous Keyed SHA1"
|
||||
}
|
||||
}
|
||||
|
||||
// BFDAuthKeyID represents the authentication key ID in use for
|
||||
// this packet. This allows multiple keys to be active simultaneously.
|
||||
type BFDAuthKeyID uint8
|
||||
|
||||
// BFDAuthSequenceNumber represents the sequence number for this packet.
|
||||
// For Keyed Authentication, this value is incremented occasionally. For
|
||||
// Meticulous Keyed Authentication, this value is incremented for each
|
||||
// successive packet transmitted for a session. This provides protection
|
||||
// against replay attacks.
|
||||
type BFDAuthSequenceNumber uint32
|
||||
|
||||
// BFDAuthData represents the authentication key or digest
|
||||
type BFDAuthData []byte
|
||||
|
||||
// BFDAuthHeader represents authentication data used in the BFD session
|
||||
type BFDAuthHeader struct {
|
||||
AuthType BFDAuthType
|
||||
KeyID BFDAuthKeyID
|
||||
SequenceNumber BFDAuthSequenceNumber
|
||||
Data BFDAuthData
|
||||
}
|
||||
|
||||
// Length returns the data length of the BFDAuthHeader based on the
|
||||
// authentication type
|
||||
func (h *BFDAuthHeader) Length() int {
|
||||
switch h.AuthType {
|
||||
case BFDAuthTypePassword:
|
||||
return 3 + len(h.Data)
|
||||
case BFDAuthTypeKeyedMD5, BFDAuthTypeMeticulousKeyedMD5:
|
||||
return 8 + len(h.Data)
|
||||
case BFDAuthTypeKeyedSHA1, BFDAuthTypeMeticulousKeyedSHA1:
|
||||
return 8 + len(h.Data)
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// BFD represents a BFD control message packet whose payload contains
|
||||
// the control information required to for a BFD session.
|
||||
//
|
||||
// References
|
||||
// ----------
|
||||
//
|
||||
// Wikipedia's BFD entry:
|
||||
// https://en.wikipedia.org/wiki/Bidirectional_Forwarding_Detection
|
||||
// This is the best place to get an overview of BFD.
|
||||
//
|
||||
// RFC 5880 "Bidirectional Forwarding Detection (BFD)" (2010)
|
||||
// https://tools.ietf.org/html/rfc5880
|
||||
// This is the original BFD specification.
|
||||
//
|
||||
// RFC 5881 "Bidirectional Forwarding Detection (BFD) for IPv4 and IPv6 (Single Hop)" (2010)
|
||||
// https://tools.ietf.org/html/rfc5881
|
||||
// Describes the use of the Bidirectional Forwarding Detection (BFD)
|
||||
// protocol over IPv4 and IPv6 for single IP hops.
|
||||
type BFD struct {
|
||||
BaseLayer // Stores the packet bytes and payload bytes.
|
||||
|
||||
Version BFDVersion // Version of the BFD protocol.
|
||||
Diagnostic BFDDiagnostic // Diagnostic code for last state change
|
||||
State BFDState // Current state
|
||||
Poll bool // Requesting verification
|
||||
Final bool // Responding to a received BFD Control packet that had the Poll (P) bit set.
|
||||
ControlPlaneIndependent bool // BFD implementation does not share fate with its control plane
|
||||
AuthPresent bool // Authentication Section is present and the session is to be authenticated
|
||||
Demand bool // Demand mode is active
|
||||
Multipoint bool // For future point-to-multipoint extensions. Must always be zero
|
||||
DetectMultiplier BFDDetectMultiplier // Detection time multiplier
|
||||
MyDiscriminator BFDDiscriminator // A unique, nonzero discriminator value
|
||||
YourDiscriminator BFDDiscriminator // discriminator received from the remote system.
|
||||
DesiredMinTxInterval BFDTimeInterval // Minimum interval, in microseconds, the local system would like to use when transmitting BFD Control packets
|
||||
RequiredMinRxInterval BFDTimeInterval // Minimum interval, in microseconds, between received BFD Control packets that this system is capable of supporting
|
||||
RequiredMinEchoRxInterval BFDTimeInterval // Minimum interval, in microseconds, between received BFD Echo packets that this system is capable of supporting
|
||||
AuthHeader *BFDAuthHeader // Authentication data, variable length.
|
||||
}
|
||||
|
||||
// Length returns the data length of a BFD Control message which
|
||||
// changes based on the presence and type of authentication
|
||||
// contained in the message
|
||||
func (d *BFD) Length() int {
|
||||
if d.AuthPresent && (d.AuthHeader != nil) {
|
||||
return bfdMinimumRecordSizeInBytes + d.AuthHeader.Length()
|
||||
}
|
||||
|
||||
return bfdMinimumRecordSizeInBytes
|
||||
}
|
||||
|
||||
// LayerType returns the layer type of the BFD object, which is LayerTypeBFD.
|
||||
func (d *BFD) LayerType() gopacket.LayerType {
|
||||
return LayerTypeBFD
|
||||
}
|
||||
|
||||
// decodeBFD analyses a byte slice and attempts to decode it as a BFD
|
||||
// control packet
|
||||
//
|
||||
// If it succeeds, it loads p with information about the packet and returns nil.
|
||||
// If it fails, it returns an error (non nil).
|
||||
//
|
||||
// This function is employed in layertypes.go to register the BFD layer.
|
||||
func decodeBFD(data []byte, p gopacket.PacketBuilder) error {
|
||||
|
||||
// Attempt to decode the byte slice.
|
||||
d := &BFD{}
|
||||
err := d.DecodeFromBytes(data, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If the decoding worked, add the layer to the packet and set it
|
||||
// as the application layer too, if there isn't already one.
|
||||
p.AddLayer(d)
|
||||
p.SetApplicationLayer(d)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DecodeFromBytes analyses a byte slice and attempts to decode it as a BFD
|
||||
// control packet.
|
||||
//
|
||||
// Upon succeeds, it loads the BFD object with information about the packet
|
||||
// and returns nil.
|
||||
// Upon failure, it returns an error (non nil).
|
||||
func (d *BFD) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
|
||||
// If the data block is too short to be a BFD record, then return an error.
|
||||
if len(data) < bfdMinimumRecordSizeInBytes {
|
||||
df.SetTruncated()
|
||||
return errors.New("BFD packet too short")
|
||||
}
|
||||
|
||||
pLen := uint8(data[3])
|
||||
if len(data) != int(pLen) {
|
||||
return errors.New("BFD packet length does not match")
|
||||
}
|
||||
|
||||
// BFD type embeds type BaseLayer which contains two fields:
|
||||
// Contents is supposed to contain the bytes of the data at this level.
|
||||
// Payload is supposed to contain the payload of this level.
|
||||
// Here we set the baselayer to be the bytes of the BFD record.
|
||||
d.BaseLayer = BaseLayer{Contents: data[:len(data)]}
|
||||
|
||||
// Extract the fields from the block of bytes.
|
||||
// To make sense of this, refer to the packet diagram
|
||||
// above and the section on endian conventions.
|
||||
|
||||
// The first few fields are all packed into the first 32 bits. Unpack them.
|
||||
d.Version = BFDVersion(((data[0] & 0xE0) >> 5))
|
||||
d.Diagnostic = BFDDiagnostic(data[0] & 0x1F)
|
||||
data = data[1:]
|
||||
|
||||
d.State = BFDState((data[0] & 0xC0) >> 6)
|
||||
d.Poll = data[0]&0x20 != 0
|
||||
d.Final = data[0]&0x10 != 0
|
||||
d.ControlPlaneIndependent = data[0]&0x08 != 0
|
||||
d.AuthPresent = data[0]&0x04 != 0
|
||||
d.Demand = data[0]&0x02 != 0
|
||||
d.Multipoint = data[0]&0x01 != 0
|
||||
data = data[1:]
|
||||
|
||||
data, d.DetectMultiplier = data[1:], BFDDetectMultiplier(data[0])
|
||||
data, _ = data[1:], uint8(data[0]) // Consume length
|
||||
|
||||
// The remaining fields can just be copied in big endian order.
|
||||
data, d.MyDiscriminator = data[4:], BFDDiscriminator(binary.BigEndian.Uint32(data[:4]))
|
||||
data, d.YourDiscriminator = data[4:], BFDDiscriminator(binary.BigEndian.Uint32(data[:4]))
|
||||
data, d.DesiredMinTxInterval = data[4:], BFDTimeInterval(binary.BigEndian.Uint32(data[:4]))
|
||||
data, d.RequiredMinRxInterval = data[4:], BFDTimeInterval(binary.BigEndian.Uint32(data[:4]))
|
||||
data, d.RequiredMinEchoRxInterval = data[4:], BFDTimeInterval(binary.BigEndian.Uint32(data[:4]))
|
||||
|
||||
if d.AuthPresent && (len(data) > 2) {
|
||||
d.AuthHeader = &BFDAuthHeader{}
|
||||
data, d.AuthHeader.AuthType = data[1:], BFDAuthType(data[0])
|
||||
data, _ = data[1:], uint8(data[0]) // Consume length
|
||||
data, d.AuthHeader.KeyID = data[1:], BFDAuthKeyID(data[0])
|
||||
|
||||
switch d.AuthHeader.AuthType {
|
||||
case BFDAuthTypePassword:
|
||||
d.AuthHeader.Data = BFDAuthData(data)
|
||||
case BFDAuthTypeKeyedMD5, BFDAuthTypeMeticulousKeyedMD5:
|
||||
// Skipped reserved byte
|
||||
data, d.AuthHeader.SequenceNumber = data[5:], BFDAuthSequenceNumber(binary.BigEndian.Uint32(data[1:5]))
|
||||
d.AuthHeader.Data = BFDAuthData(data)
|
||||
case BFDAuthTypeKeyedSHA1, BFDAuthTypeMeticulousKeyedSHA1:
|
||||
// Skipped reserved byte
|
||||
data, d.AuthHeader.SequenceNumber = data[5:], BFDAuthSequenceNumber(binary.BigEndian.Uint32(data[1:5]))
|
||||
d.AuthHeader.Data = BFDAuthData(data)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SerializeTo writes the serialized form of this layer into the
|
||||
// SerializationBuffer, implementing gopacket.SerializableLayer.
|
||||
// See the docs for gopacket.SerializableLayer for more info.
|
||||
func (d *BFD) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
data, err := b.PrependBytes(bfdMinimumRecordSizeInBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Pack the first few fields into the first 32 bits.
|
||||
data[0] = byte(byte(d.Version<<5) | byte(d.Diagnostic))
|
||||
h := uint8(0)
|
||||
h |= (uint8(d.State) << 6)
|
||||
h |= (uint8(bool2uint8(d.Poll)) << 5)
|
||||
h |= (uint8(bool2uint8(d.Final)) << 4)
|
||||
h |= (uint8(bool2uint8(d.ControlPlaneIndependent)) << 3)
|
||||
h |= (uint8(bool2uint8(d.AuthPresent)) << 2)
|
||||
h |= (uint8(bool2uint8(d.Demand)) << 1)
|
||||
h |= uint8(bool2uint8(d.Multipoint))
|
||||
data[1] = byte(h)
|
||||
data[2] = byte(d.DetectMultiplier)
|
||||
data[3] = byte(d.Length())
|
||||
|
||||
// The remaining fields can just be copied in big endian order.
|
||||
binary.BigEndian.PutUint32(data[4:], uint32(d.MyDiscriminator))
|
||||
binary.BigEndian.PutUint32(data[8:], uint32(d.YourDiscriminator))
|
||||
binary.BigEndian.PutUint32(data[12:], uint32(d.DesiredMinTxInterval))
|
||||
binary.BigEndian.PutUint32(data[16:], uint32(d.RequiredMinRxInterval))
|
||||
binary.BigEndian.PutUint32(data[20:], uint32(d.RequiredMinEchoRxInterval))
|
||||
|
||||
if d.AuthPresent && (d.AuthHeader != nil) {
|
||||
auth, err := b.AppendBytes(int(d.AuthHeader.Length()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
auth[0] = byte(d.AuthHeader.AuthType)
|
||||
auth[1] = byte(d.AuthHeader.Length())
|
||||
auth[2] = byte(d.AuthHeader.KeyID)
|
||||
|
||||
switch d.AuthHeader.AuthType {
|
||||
case BFDAuthTypePassword:
|
||||
copy(auth[3:], d.AuthHeader.Data)
|
||||
case BFDAuthTypeKeyedMD5, BFDAuthTypeMeticulousKeyedMD5:
|
||||
auth[3] = byte(0)
|
||||
binary.BigEndian.PutUint32(auth[4:], uint32(d.AuthHeader.SequenceNumber))
|
||||
copy(auth[8:], d.AuthHeader.Data)
|
||||
case BFDAuthTypeKeyedSHA1, BFDAuthTypeMeticulousKeyedSHA1:
|
||||
auth[3] = byte(0)
|
||||
binary.BigEndian.PutUint32(auth[4:], uint32(d.AuthHeader.SequenceNumber))
|
||||
copy(auth[8:], d.AuthHeader.Data)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CanDecode returns a set of layers that BFD objects can decode.
|
||||
// As BFD objects can only decide the BFD layer, we can return just that layer.
|
||||
// Apparently a single layer type implements LayerClass.
|
||||
func (d *BFD) CanDecode() gopacket.LayerClass {
|
||||
return LayerTypeBFD
|
||||
}
|
||||
|
||||
// NextLayerType specifies the next layer that GoPacket should attempt to
|
||||
// analyse after this (BFD) layer. As BFD packets do not contain any payload
|
||||
// bytes, there are no further layers to analyse.
|
||||
func (d *BFD) NextLayerType() gopacket.LayerType {
|
||||
return gopacket.LayerTypeZero
|
||||
}
|
||||
|
||||
// Payload returns an empty byte slice as BFD packets do not carry a payload
|
||||
func (d *BFD) Payload() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// bool2uint8 converts a bool to uint8
|
||||
func bool2uint8(b bool) uint8 {
|
||||
if b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
36
vendor/github.com/google/gopacket/layers/dhcpv4.go
generated
vendored
36
vendor/github.com/google/gopacket/layers/dhcpv4.go
generated
vendored
|
@ -9,7 +9,6 @@ package layers
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
|
@ -125,6 +124,7 @@ func (d *DHCPv4) LayerType() gopacket.LayerType { return LayerTypeDHCPv4 }
|
|||
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (d *DHCPv4) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
d.Options = d.Options[:0]
|
||||
d.Operation = DHCPOp(data[0])
|
||||
d.HardwareType = LinkType(data[1])
|
||||
d.HardwareLen = data[2]
|
||||
|
@ -140,7 +140,7 @@ func (d *DHCPv4) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
|
|||
d.ServerName = data[44:108]
|
||||
d.File = data[108:236]
|
||||
if binary.BigEndian.Uint32(data[236:240]) != DHCPMagic {
|
||||
return errors.New("Bad DHCP header")
|
||||
return InvalidMagicCookie
|
||||
}
|
||||
|
||||
if len(data) <= 240 {
|
||||
|
@ -538,9 +538,6 @@ func (o *DHCPOption) encode(b []byte) error {
|
|||
case DHCPOptPad, DHCPOptEnd:
|
||||
b[0] = byte(o.Type)
|
||||
default:
|
||||
if o.Length > 253 {
|
||||
return errors.New("data too long to encode")
|
||||
}
|
||||
b[0] = byte(o.Type)
|
||||
b[1] = o.Length
|
||||
copy(b[2:], o.Data)
|
||||
|
@ -551,21 +548,38 @@ func (o *DHCPOption) encode(b []byte) error {
|
|||
func (o *DHCPOption) decode(data []byte) error {
|
||||
if len(data) < 1 {
|
||||
// Pad/End have a length of 1
|
||||
return errors.New("Not enough data to decode")
|
||||
return DecOptionNotEnoughData
|
||||
}
|
||||
o.Type = DHCPOpt(data[0])
|
||||
switch o.Type {
|
||||
case DHCPOptPad, DHCPOptEnd:
|
||||
o.Data = nil
|
||||
default:
|
||||
if len(data) < 3 {
|
||||
return errors.New("Not enough data to decode")
|
||||
if len(data) < 2 {
|
||||
return DecOptionNotEnoughData
|
||||
}
|
||||
o.Length = data[1]
|
||||
if o.Length > 253 {
|
||||
return errors.New("data too long to decode")
|
||||
if int(o.Length) > len(data[2:]) {
|
||||
return DecOptionMalformed
|
||||
}
|
||||
o.Data = data[2 : 2+o.Length]
|
||||
o.Data = data[2 : 2+int(o.Length)]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DHCPv4Error is used for constant errors for DHCPv4. It is needed for test asserts.
|
||||
type DHCPv4Error string
|
||||
|
||||
// DHCPv4Error implements error interface.
|
||||
func (d DHCPv4Error) Error() string {
|
||||
return string(d)
|
||||
}
|
||||
|
||||
const (
|
||||
// DecOptionNotEnoughData is returned when there is not enough data during option's decode process
|
||||
DecOptionNotEnoughData = DHCPv4Error("Not enough data to decode")
|
||||
// DecOptionMalformed is returned when the option is malformed
|
||||
DecOptionMalformed = DHCPv4Error("Option is malformed")
|
||||
// InvalidMagicCookie is returned when Magic cookie is missing into BOOTP header
|
||||
InvalidMagicCookie = DHCPv4Error("Bad DHCP header")
|
||||
)
|
||||
|
|
495
vendor/github.com/google/gopacket/layers/dhcpv6.go
generated
vendored
Normal file
495
vendor/github.com/google/gopacket/layers/dhcpv6.go
generated
vendored
Normal file
|
@ -0,0 +1,495 @@
|
|||
// Copyright 2018 Google, Inc. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree.
|
||||
|
||||
package layers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
)
|
||||
|
||||
// DHCPv6MsgType represents a DHCPv6 operation
|
||||
type DHCPv6MsgType byte
|
||||
|
||||
// Constants that represent DHCP operations
|
||||
const (
|
||||
DHCPv6MsgTypeUnspecified DHCPv6MsgType = iota
|
||||
DHCPv6MsgTypeSolicit
|
||||
DHCPv6MsgTypeAdverstise
|
||||
DHCPv6MsgTypeRequest
|
||||
DHCPv6MsgTypeConfirm
|
||||
DHCPv6MsgTypeRenew
|
||||
DHCPv6MsgTypeRebind
|
||||
DHCPv6MsgTypeReply
|
||||
DHCPv6MsgTypeRelease
|
||||
DHCPv6MsgTypeDecline
|
||||
DHCPv6MsgTypeReconfigure
|
||||
DHCPv6MsgTypeInformationRequest
|
||||
DHCPv6MsgTypeRelayForward
|
||||
DHCPv6MsgTypeRelayReply
|
||||
)
|
||||
|
||||
// String returns a string version of a DHCPv6MsgType.
|
||||
func (o DHCPv6MsgType) String() string {
|
||||
switch o {
|
||||
case DHCPv6MsgTypeUnspecified:
|
||||
return "Unspecified"
|
||||
case DHCPv6MsgTypeSolicit:
|
||||
return "Solicit"
|
||||
case DHCPv6MsgTypeAdverstise:
|
||||
return "Adverstise"
|
||||
case DHCPv6MsgTypeRequest:
|
||||
return "Request"
|
||||
case DHCPv6MsgTypeConfirm:
|
||||
return "Confirm"
|
||||
case DHCPv6MsgTypeRenew:
|
||||
return "Renew"
|
||||
case DHCPv6MsgTypeRebind:
|
||||
return "Rebind"
|
||||
case DHCPv6MsgTypeReply:
|
||||
return "Reply"
|
||||
case DHCPv6MsgTypeRelease:
|
||||
return "Release"
|
||||
case DHCPv6MsgTypeDecline:
|
||||
return "Decline"
|
||||
case DHCPv6MsgTypeReconfigure:
|
||||
return "Reconfigure"
|
||||
case DHCPv6MsgTypeInformationRequest:
|
||||
return "InformationRequest"
|
||||
case DHCPv6MsgTypeRelayForward:
|
||||
return "RelayForward"
|
||||
case DHCPv6MsgTypeRelayReply:
|
||||
return "RelayReply"
|
||||
default:
|
||||
return "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// DHCPv6 contains data for a single DHCP packet.
|
||||
type DHCPv6 struct {
|
||||
BaseLayer
|
||||
MsgType DHCPv6MsgType
|
||||
HopCount uint8
|
||||
LinkAddr net.IP
|
||||
PeerAddr net.IP
|
||||
TransactionID []byte
|
||||
Options DHCPv6Options
|
||||
}
|
||||
|
||||
// LayerType returns gopacket.LayerTypeDHCPv6
|
||||
func (d *DHCPv6) LayerType() gopacket.LayerType { return LayerTypeDHCPv6 }
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (d *DHCPv6) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
d.BaseLayer = BaseLayer{Contents: data}
|
||||
d.Options = d.Options[:0]
|
||||
d.MsgType = DHCPv6MsgType(data[0])
|
||||
|
||||
offset := 0
|
||||
if d.MsgType == DHCPv6MsgTypeRelayForward || d.MsgType == DHCPv6MsgTypeRelayReply {
|
||||
d.HopCount = data[1]
|
||||
d.LinkAddr = net.IP(data[2:18])
|
||||
d.PeerAddr = net.IP(data[18:34])
|
||||
offset = 34
|
||||
} else {
|
||||
d.TransactionID = data[1:4]
|
||||
offset = 4
|
||||
}
|
||||
|
||||
stop := len(data)
|
||||
for offset < stop {
|
||||
o := DHCPv6Option{}
|
||||
if err := o.decode(data[offset:]); err != nil {
|
||||
return err
|
||||
}
|
||||
d.Options = append(d.Options, o)
|
||||
offset += int(o.Length) + 4 // 2 from option code, 2 from option length
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Len returns the length of a DHCPv6 packet.
|
||||
func (d *DHCPv6) Len() int {
|
||||
n := 1
|
||||
if d.MsgType == DHCPv6MsgTypeRelayForward || d.MsgType == DHCPv6MsgTypeRelayReply {
|
||||
n += 33
|
||||
} else {
|
||||
n += 3
|
||||
}
|
||||
|
||||
for _, o := range d.Options {
|
||||
n += int(o.Length) + 4 // 2 from option code, 2 from option length
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
// SerializeTo writes the serialized form of this layer into the
|
||||
// SerializationBuffer, implementing gopacket.SerializableLayer.
|
||||
// See the docs for gopacket.SerializableLayer for more info.
|
||||
func (d *DHCPv6) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
plen := int(d.Len())
|
||||
|
||||
data, err := b.PrependBytes(plen)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
offset := 0
|
||||
data[0] = byte(d.MsgType)
|
||||
if d.MsgType == DHCPv6MsgTypeRelayForward || d.MsgType == DHCPv6MsgTypeRelayReply {
|
||||
data[1] = byte(d.HopCount)
|
||||
copy(data[2:18], d.LinkAddr.To16())
|
||||
copy(data[18:34], d.PeerAddr.To16())
|
||||
offset = 34
|
||||
} else {
|
||||
copy(data[1:4], d.TransactionID)
|
||||
offset = 4
|
||||
}
|
||||
|
||||
if len(d.Options) > 0 {
|
||||
for _, o := range d.Options {
|
||||
if err := o.encode(data[offset:]); err != nil {
|
||||
return err
|
||||
}
|
||||
offset += int(o.Length) + 4 // 2 from option code, 2 from option length
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CanDecode returns the set of layer types that this DecodingLayer can decode.
|
||||
func (d *DHCPv6) CanDecode() gopacket.LayerClass {
|
||||
return LayerTypeDHCPv6
|
||||
}
|
||||
|
||||
// NextLayerType returns the layer type contained by this DecodingLayer.
|
||||
func (d *DHCPv6) NextLayerType() gopacket.LayerType {
|
||||
return gopacket.LayerTypePayload
|
||||
}
|
||||
|
||||
func decodeDHCPv6(data []byte, p gopacket.PacketBuilder) error {
|
||||
dhcp := &DHCPv6{}
|
||||
err := dhcp.DecodeFromBytes(data, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.AddLayer(dhcp)
|
||||
return p.NextDecoder(gopacket.LayerTypePayload)
|
||||
}
|
||||
|
||||
// DHCPv6StatusCode represents a DHCP status code - RFC-3315
|
||||
type DHCPv6StatusCode byte
|
||||
|
||||
// Constants for the DHCPv6StatusCode.
|
||||
const (
|
||||
DHCPv6StatusCodeSuccess DHCPv6StatusCode = iota
|
||||
DHCPv6StatusCodeUnspecFail
|
||||
DHCPv6StatusCodeNoAddrsAvail
|
||||
DHCPv6StatusCodeNoBinding
|
||||
DHCPv6StatusCodeNotOnLink
|
||||
DHCPv6StatusCodeUseMulticast
|
||||
)
|
||||
|
||||
// String returns a string version of a DHCPv6StatusCode.
|
||||
func (o DHCPv6StatusCode) String() string {
|
||||
switch o {
|
||||
case DHCPv6StatusCodeSuccess:
|
||||
return "Success"
|
||||
case DHCPv6StatusCodeUnspecFail:
|
||||
return "UnspecifiedFailure"
|
||||
case DHCPv6StatusCodeNoAddrsAvail:
|
||||
return "NoAddressAvailable"
|
||||
case DHCPv6StatusCodeNoBinding:
|
||||
return "NoBinding"
|
||||
case DHCPv6StatusCodeNotOnLink:
|
||||
return "NotOnLink"
|
||||
case DHCPv6StatusCodeUseMulticast:
|
||||
return "UseMulticast"
|
||||
default:
|
||||
return "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// DHCPv6Opt represents a DHCP option or parameter from RFC-3315
|
||||
type DHCPv6Opt uint16
|
||||
|
||||
// Constants for the DHCPv6Opt options.
|
||||
const (
|
||||
DHCPv6OptClientID DHCPv6Opt = 1
|
||||
DHCPv6OptServerID DHCPv6Opt = 2
|
||||
DHCPv6OptIANA DHCPv6Opt = 3
|
||||
DHCPv6OptIATA DHCPv6Opt = 4
|
||||
DHCPv6OptIAAddr DHCPv6Opt = 5
|
||||
DHCPv6OptOro DHCPv6Opt = 6
|
||||
DHCPv6OptPreference DHCPv6Opt = 7
|
||||
DHCPv6OptElapsedTime DHCPv6Opt = 8
|
||||
DHCPv6OptRelayMessage DHCPv6Opt = 9
|
||||
DHCPv6OptAuth DHCPv6Opt = 11
|
||||
DHCPv6OptUnicast DHCPv6Opt = 12
|
||||
DHCPv6OptStatusCode DHCPv6Opt = 13
|
||||
DHCPv6OptRapidCommit DHCPv6Opt = 14
|
||||
DHCPv6OptUserClass DHCPv6Opt = 15
|
||||
DHCPv6OptVendorClass DHCPv6Opt = 16
|
||||
DHCPv6OptVendorOpts DHCPv6Opt = 17
|
||||
DHCPv6OptInterfaceID DHCPv6Opt = 18
|
||||
DHCPv6OptReconfigureMessage DHCPv6Opt = 19
|
||||
DHCPv6OptReconfigureAccept DHCPv6Opt = 20
|
||||
)
|
||||
|
||||
// String returns a string version of a DHCPv6Opt.
|
||||
func (o DHCPv6Opt) String() string {
|
||||
switch o {
|
||||
case DHCPv6OptClientID:
|
||||
return "ClientID"
|
||||
case DHCPv6OptServerID:
|
||||
return "ServerID"
|
||||
case DHCPv6OptIANA:
|
||||
return "IA_NA"
|
||||
case DHCPv6OptIATA:
|
||||
return "IA_TA"
|
||||
case DHCPv6OptIAAddr:
|
||||
return "IAAddr"
|
||||
case DHCPv6OptOro:
|
||||
return "Oro"
|
||||
case DHCPv6OptPreference:
|
||||
return "Preference"
|
||||
case DHCPv6OptElapsedTime:
|
||||
return "ElapsedTime"
|
||||
case DHCPv6OptRelayMessage:
|
||||
return "RelayMessage"
|
||||
case DHCPv6OptAuth:
|
||||
return "Auth"
|
||||
case DHCPv6OptUnicast:
|
||||
return "Unicast"
|
||||
case DHCPv6OptStatusCode:
|
||||
return "StatusCode"
|
||||
case DHCPv6OptRapidCommit:
|
||||
return "RapidCommit"
|
||||
case DHCPv6OptUserClass:
|
||||
return "UserClass"
|
||||
case DHCPv6OptVendorClass:
|
||||
return "VendorClass"
|
||||
case DHCPv6OptVendorOpts:
|
||||
return "VendorOpts"
|
||||
case DHCPv6OptInterfaceID:
|
||||
return "InterfaceID"
|
||||
case DHCPv6OptReconfigureMessage:
|
||||
return "ReconfigureMessage"
|
||||
case DHCPv6OptReconfigureAccept:
|
||||
return "ReconfigureAccept"
|
||||
default:
|
||||
return "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// DHCPv6Options is used to get nicely printed option lists which would normally
|
||||
// be cut off after 5 options.
|
||||
type DHCPv6Options []DHCPv6Option
|
||||
|
||||
// String returns a string version of the options list.
|
||||
func (o DHCPv6Options) String() string {
|
||||
buf := &bytes.Buffer{}
|
||||
buf.WriteByte('[')
|
||||
for i, opt := range o {
|
||||
buf.WriteString(opt.String())
|
||||
if i+1 != len(o) {
|
||||
buf.WriteString(", ")
|
||||
}
|
||||
}
|
||||
buf.WriteByte(']')
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// DHCPv6Option rerpresents a DHCP option.
|
||||
type DHCPv6Option struct {
|
||||
Code DHCPv6Opt
|
||||
Length uint16
|
||||
Data []byte
|
||||
}
|
||||
|
||||
// String returns a string version of a DHCP Option.
|
||||
func (o DHCPv6Option) String() string {
|
||||
switch o.Code {
|
||||
case DHCPv6OptClientID, DHCPv6OptServerID:
|
||||
duid, err := decodeDHCPv6DUID(o.Data)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("Option(%s:INVALID)", o.Code)
|
||||
}
|
||||
return fmt.Sprintf("Option(%s:[%s])", o.Code, duid.String())
|
||||
case DHCPv6OptOro:
|
||||
options := ""
|
||||
for i := 0; i < int(o.Length); i += 2 {
|
||||
if options != "" {
|
||||
options += ","
|
||||
}
|
||||
option := DHCPv6Opt(binary.BigEndian.Uint16(o.Data[i : i+2]))
|
||||
options += option.String()
|
||||
}
|
||||
return fmt.Sprintf("Option(%s:[%s])", o.Code, options)
|
||||
default:
|
||||
return fmt.Sprintf("Option(%s:%v)", o.Code, o.Data)
|
||||
}
|
||||
}
|
||||
|
||||
// NewDHCPv6Option constructs a new DHCPv6Option with a given type and data.
|
||||
func NewDHCPv6Option(code DHCPv6Opt, data []byte) DHCPv6Option {
|
||||
o := DHCPv6Option{Code: code}
|
||||
if data != nil {
|
||||
o.Data = data
|
||||
o.Length = uint16(len(data))
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *DHCPv6Option) encode(b []byte) error {
|
||||
binary.BigEndian.PutUint16(b[0:2], uint16(o.Code))
|
||||
binary.BigEndian.PutUint16(b[2:4], o.Length)
|
||||
copy(b[4:], o.Data)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *DHCPv6Option) decode(data []byte) error {
|
||||
if len(data) < 2 {
|
||||
return errors.New("Not enough data to decode")
|
||||
}
|
||||
o.Code = DHCPv6Opt(binary.BigEndian.Uint16(data[0:2]))
|
||||
if len(data) < 3 {
|
||||
return errors.New("Not enough data to decode")
|
||||
}
|
||||
o.Length = binary.BigEndian.Uint16(data[2:4])
|
||||
o.Data = data[4 : 4+o.Length]
|
||||
return nil
|
||||
}
|
||||
|
||||
// DHCPv6DUIDType represents a DHCP DUID - RFC-3315
|
||||
type DHCPv6DUIDType uint16
|
||||
|
||||
// Constants for the DHCPv6DUIDType.
|
||||
const (
|
||||
DHCPv6DUIDTypeLLT DHCPv6DUIDType = iota + 1
|
||||
DHCPv6DUIDTypeEN
|
||||
DHCPv6DUIDTypeLL
|
||||
)
|
||||
|
||||
// String returns a string version of a DHCPv6DUIDType.
|
||||
func (o DHCPv6DUIDType) String() string {
|
||||
switch o {
|
||||
case DHCPv6DUIDTypeLLT:
|
||||
return "LLT"
|
||||
case DHCPv6DUIDTypeEN:
|
||||
return "EN"
|
||||
case DHCPv6DUIDTypeLL:
|
||||
return "LL"
|
||||
default:
|
||||
return "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// DHCPv6DUID means DHCP Unique Identifier as stated in RFC 3315, section 9 (https://tools.ietf.org/html/rfc3315#page-19)
|
||||
type DHCPv6DUID struct {
|
||||
Type DHCPv6DUIDType
|
||||
// LLT, LL
|
||||
HardwareType []byte
|
||||
// EN
|
||||
EnterpriseNumber []byte
|
||||
// LLT
|
||||
Time []byte
|
||||
// LLT, LL
|
||||
LinkLayerAddress net.HardwareAddr
|
||||
// EN
|
||||
Identifier []byte
|
||||
}
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into a DHCPv6DUID
|
||||
func (d *DHCPv6DUID) DecodeFromBytes(data []byte) error {
|
||||
if len(data) < 2 {
|
||||
return errors.New("Not enough bytes to decode: " + string(len(data)))
|
||||
}
|
||||
|
||||
d.Type = DHCPv6DUIDType(binary.BigEndian.Uint16(data[:2]))
|
||||
if d.Type == DHCPv6DUIDTypeLLT || d.Type == DHCPv6DUIDTypeLL {
|
||||
d.HardwareType = data[2:4]
|
||||
}
|
||||
|
||||
if d.Type == DHCPv6DUIDTypeLLT {
|
||||
d.Time = data[4:8]
|
||||
d.LinkLayerAddress = net.HardwareAddr(data[8:])
|
||||
} else if d.Type == DHCPv6DUIDTypeEN {
|
||||
d.EnterpriseNumber = data[2:6]
|
||||
d.Identifier = data[6:]
|
||||
} else { // DHCPv6DUIDTypeLL
|
||||
d.LinkLayerAddress = net.HardwareAddr(data[4:])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode encodes the DHCPv6DUID in a slice of bytes
|
||||
func (d *DHCPv6DUID) Encode() []byte {
|
||||
length := d.Len()
|
||||
data := make([]byte, length)
|
||||
binary.BigEndian.PutUint16(data[0:2], uint16(d.Type))
|
||||
|
||||
if d.Type == DHCPv6DUIDTypeLLT || d.Type == DHCPv6DUIDTypeLL {
|
||||
copy(data[2:4], d.HardwareType)
|
||||
}
|
||||
|
||||
if d.Type == DHCPv6DUIDTypeLLT {
|
||||
copy(data[4:8], d.Time)
|
||||
copy(data[8:], d.LinkLayerAddress)
|
||||
} else if d.Type == DHCPv6DUIDTypeEN {
|
||||
copy(data[2:6], d.EnterpriseNumber)
|
||||
copy(data[6:], d.Identifier)
|
||||
} else {
|
||||
copy(data[4:], d.LinkLayerAddress)
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
// Len returns the length of the DHCPv6DUID, respecting the type
|
||||
func (d *DHCPv6DUID) Len() int {
|
||||
length := 2 // d.Type
|
||||
if d.Type == DHCPv6DUIDTypeLLT {
|
||||
length += 2 /*HardwareType*/ + 4 /*d.Time*/ + len(d.LinkLayerAddress)
|
||||
} else if d.Type == DHCPv6DUIDTypeEN {
|
||||
length += 4 /*d.EnterpriseNumber*/ + len(d.Identifier)
|
||||
} else { // LL
|
||||
length += 2 /*d.HardwareType*/ + len(d.LinkLayerAddress)
|
||||
}
|
||||
|
||||
return length
|
||||
}
|
||||
|
||||
func (d *DHCPv6DUID) String() string {
|
||||
duid := "Type: " + d.Type.String() + ", "
|
||||
if d.Type == DHCPv6DUIDTypeLLT {
|
||||
duid += fmt.Sprintf("HardwareType: %v, Time: %v, LinkLayerAddress: %v", d.HardwareType, d.Time, d.LinkLayerAddress)
|
||||
} else if d.Type == DHCPv6DUIDTypeEN {
|
||||
duid += fmt.Sprintf("EnterpriseNumber: %v, Identifier: %v", d.EnterpriseNumber, d.Identifier)
|
||||
} else { // DHCPv6DUIDTypeLL
|
||||
duid += fmt.Sprintf("HardwareType: %v, LinkLayerAddress: %v", d.HardwareType, d.LinkLayerAddress)
|
||||
}
|
||||
return duid
|
||||
}
|
||||
|
||||
func decodeDHCPv6DUID(data []byte) (*DHCPv6DUID, error) {
|
||||
duid := &DHCPv6DUID{}
|
||||
err := duid.DecodeFromBytes(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return duid, nil
|
||||
}
|
4
vendor/github.com/google/gopacket/layers/dns.go
generated
vendored
4
vendor/github.com/google/gopacket/layers/dns.go
generated
vendored
|
@ -254,7 +254,7 @@ type DNS struct {
|
|||
TC bool // Truncated
|
||||
RD bool // Recursion desired
|
||||
RA bool // Recursion available
|
||||
Z uint8 // Resrved for future use
|
||||
Z uint8 // Reserved for future use
|
||||
|
||||
ResponseCode DNSResponseCode
|
||||
QDCount uint16 // Number of questions to expect
|
||||
|
@ -431,7 +431,7 @@ func recSize(rr *DNSResourceRecord) int {
|
|||
func computeSize(recs []DNSResourceRecord) int {
|
||||
sz := 0
|
||||
for _, rr := range recs {
|
||||
sz += len(rr.Name) + 14
|
||||
sz += len(rr.Name) + 12
|
||||
sz += recSize(&rr)
|
||||
}
|
||||
return sz
|
||||
|
|
771
vendor/github.com/google/gopacket/layers/dot11.go
generated
vendored
771
vendor/github.com/google/gopacket/layers/dot11.go
generated
vendored
|
@ -240,24 +240,172 @@ func (a Dot11Algorithm) String() string {
|
|||
|
||||
type Dot11InformationElementID uint8
|
||||
|
||||
// TODO: Verify these element ids, and append more ids if more.
|
||||
|
||||
const (
|
||||
Dot11InformationElementIDSSID Dot11InformationElementID = 0
|
||||
Dot11InformationElementIDRates Dot11InformationElementID = 1
|
||||
Dot11InformationElementIDFHSet Dot11InformationElementID = 2
|
||||
Dot11InformationElementIDDSSet Dot11InformationElementID = 3
|
||||
Dot11InformationElementIDCFSet Dot11InformationElementID = 4
|
||||
Dot11InformationElementIDTIM Dot11InformationElementID = 5
|
||||
Dot11InformationElementIDIBSSSet Dot11InformationElementID = 6
|
||||
Dot11InformationElementIDChallenge Dot11InformationElementID = 16
|
||||
Dot11InformationElementIDERPInfo Dot11InformationElementID = 42
|
||||
Dot11InformationElementIDQOSCapability Dot11InformationElementID = 46
|
||||
Dot11InformationElementIDERPInfo2 Dot11InformationElementID = 47
|
||||
Dot11InformationElementIDRSNInfo Dot11InformationElementID = 48
|
||||
Dot11InformationElementIDESRates Dot11InformationElementID = 50
|
||||
Dot11InformationElementIDVendor Dot11InformationElementID = 221
|
||||
Dot11InformationElementIDReserved Dot11InformationElementID = 68
|
||||
Dot11InformationElementIDSSID Dot11InformationElementID = 0
|
||||
Dot11InformationElementIDRates Dot11InformationElementID = 1
|
||||
Dot11InformationElementIDFHSet Dot11InformationElementID = 2
|
||||
Dot11InformationElementIDDSSet Dot11InformationElementID = 3
|
||||
Dot11InformationElementIDCFSet Dot11InformationElementID = 4
|
||||
Dot11InformationElementIDTIM Dot11InformationElementID = 5
|
||||
Dot11InformationElementIDIBSSSet Dot11InformationElementID = 6
|
||||
Dot11InformationElementIDCountryInfo Dot11InformationElementID = 7
|
||||
Dot11InformationElementIDHoppingPatternParam Dot11InformationElementID = 8
|
||||
Dot11InformationElementIDHoppingPatternTable Dot11InformationElementID = 9
|
||||
Dot11InformationElementIDRequest Dot11InformationElementID = 10
|
||||
Dot11InformationElementIDQBSSLoadElem Dot11InformationElementID = 11
|
||||
Dot11InformationElementIDEDCAParamSet Dot11InformationElementID = 12
|
||||
Dot11InformationElementIDTrafficSpec Dot11InformationElementID = 13
|
||||
Dot11InformationElementIDTrafficClass Dot11InformationElementID = 14
|
||||
Dot11InformationElementIDSchedule Dot11InformationElementID = 15
|
||||
Dot11InformationElementIDChallenge Dot11InformationElementID = 16
|
||||
Dot11InformationElementIDPowerConst Dot11InformationElementID = 32
|
||||
Dot11InformationElementIDPowerCapability Dot11InformationElementID = 33
|
||||
Dot11InformationElementIDTPCRequest Dot11InformationElementID = 34
|
||||
Dot11InformationElementIDTPCReport Dot11InformationElementID = 35
|
||||
Dot11InformationElementIDSupportedChannels Dot11InformationElementID = 36
|
||||
Dot11InformationElementIDSwitchChannelAnnounce Dot11InformationElementID = 37
|
||||
Dot11InformationElementIDMeasureRequest Dot11InformationElementID = 38
|
||||
Dot11InformationElementIDMeasureReport Dot11InformationElementID = 39
|
||||
Dot11InformationElementIDQuiet Dot11InformationElementID = 40
|
||||
Dot11InformationElementIDIBSSDFS Dot11InformationElementID = 41
|
||||
Dot11InformationElementIDERPInfo Dot11InformationElementID = 42
|
||||
Dot11InformationElementIDTSDelay Dot11InformationElementID = 43
|
||||
Dot11InformationElementIDTCLASProcessing Dot11InformationElementID = 44
|
||||
Dot11InformationElementIDHTCapabilities Dot11InformationElementID = 45
|
||||
Dot11InformationElementIDQOSCapability Dot11InformationElementID = 46
|
||||
Dot11InformationElementIDERPInfo2 Dot11InformationElementID = 47
|
||||
Dot11InformationElementIDRSNInfo Dot11InformationElementID = 48
|
||||
Dot11InformationElementIDESRates Dot11InformationElementID = 50
|
||||
Dot11InformationElementIDAPChannelReport Dot11InformationElementID = 51
|
||||
Dot11InformationElementIDNeighborReport Dot11InformationElementID = 52
|
||||
Dot11InformationElementIDRCPI Dot11InformationElementID = 53
|
||||
Dot11InformationElementIDMobilityDomain Dot11InformationElementID = 54
|
||||
Dot11InformationElementIDFastBSSTrans Dot11InformationElementID = 55
|
||||
Dot11InformationElementIDTimeoutInt Dot11InformationElementID = 56
|
||||
Dot11InformationElementIDRICData Dot11InformationElementID = 57
|
||||
Dot11InformationElementIDDSERegisteredLoc Dot11InformationElementID = 58
|
||||
Dot11InformationElementIDSuppOperatingClass Dot11InformationElementID = 59
|
||||
Dot11InformationElementIDExtChanSwitchAnnounce Dot11InformationElementID = 60
|
||||
Dot11InformationElementIDHTInfo Dot11InformationElementID = 61
|
||||
Dot11InformationElementIDSecChanOffset Dot11InformationElementID = 62
|
||||
Dot11InformationElementIDBSSAverageAccessDelay Dot11InformationElementID = 63
|
||||
Dot11InformationElementIDAntenna Dot11InformationElementID = 64
|
||||
Dot11InformationElementIDRSNI Dot11InformationElementID = 65
|
||||
Dot11InformationElementIDMeasurePilotTrans Dot11InformationElementID = 66
|
||||
Dot11InformationElementIDBSSAvailAdmCapacity Dot11InformationElementID = 67
|
||||
Dot11InformationElementIDBSSACAccDelayWAPIParam Dot11InformationElementID = 68
|
||||
Dot11InformationElementIDTimeAdvertisement Dot11InformationElementID = 69
|
||||
Dot11InformationElementIDRMEnabledCapabilities Dot11InformationElementID = 70
|
||||
Dot11InformationElementIDMultipleBSSID Dot11InformationElementID = 71
|
||||
Dot11InformationElementID2040BSSCoExist Dot11InformationElementID = 72
|
||||
Dot11InformationElementID2040BSSIntChanReport Dot11InformationElementID = 73
|
||||
Dot11InformationElementIDOverlapBSSScanParam Dot11InformationElementID = 74
|
||||
Dot11InformationElementIDRICDescriptor Dot11InformationElementID = 75
|
||||
Dot11InformationElementIDManagementMIC Dot11InformationElementID = 76
|
||||
Dot11InformationElementIDEventRequest Dot11InformationElementID = 78
|
||||
Dot11InformationElementIDEventReport Dot11InformationElementID = 79
|
||||
Dot11InformationElementIDDiagnosticRequest Dot11InformationElementID = 80
|
||||
Dot11InformationElementIDDiagnosticReport Dot11InformationElementID = 81
|
||||
Dot11InformationElementIDLocationParam Dot11InformationElementID = 82
|
||||
Dot11InformationElementIDNonTransBSSIDCapability Dot11InformationElementID = 83
|
||||
Dot11InformationElementIDSSIDList Dot11InformationElementID = 84
|
||||
Dot11InformationElementIDMultipleBSSIDIndex Dot11InformationElementID = 85
|
||||
Dot11InformationElementIDFMSDescriptor Dot11InformationElementID = 86
|
||||
Dot11InformationElementIDFMSRequest Dot11InformationElementID = 87
|
||||
Dot11InformationElementIDFMSResponse Dot11InformationElementID = 88
|
||||
Dot11InformationElementIDQOSTrafficCapability Dot11InformationElementID = 89
|
||||
Dot11InformationElementIDBSSMaxIdlePeriod Dot11InformationElementID = 90
|
||||
Dot11InformationElementIDTFSRequest Dot11InformationElementID = 91
|
||||
Dot11InformationElementIDTFSResponse Dot11InformationElementID = 92
|
||||
Dot11InformationElementIDWNMSleepMode Dot11InformationElementID = 93
|
||||
Dot11InformationElementIDTIMBroadcastRequest Dot11InformationElementID = 94
|
||||
Dot11InformationElementIDTIMBroadcastResponse Dot11InformationElementID = 95
|
||||
Dot11InformationElementIDCollInterferenceReport Dot11InformationElementID = 96
|
||||
Dot11InformationElementIDChannelUsage Dot11InformationElementID = 97
|
||||
Dot11InformationElementIDTimeZone Dot11InformationElementID = 98
|
||||
Dot11InformationElementIDDMSRequest Dot11InformationElementID = 99
|
||||
Dot11InformationElementIDDMSResponse Dot11InformationElementID = 100
|
||||
Dot11InformationElementIDLinkIdentifier Dot11InformationElementID = 101
|
||||
Dot11InformationElementIDWakeupSchedule Dot11InformationElementID = 102
|
||||
Dot11InformationElementIDChannelSwitchTiming Dot11InformationElementID = 104
|
||||
Dot11InformationElementIDPTIControl Dot11InformationElementID = 105
|
||||
Dot11InformationElementIDPUBufferStatus Dot11InformationElementID = 106
|
||||
Dot11InformationElementIDInterworking Dot11InformationElementID = 107
|
||||
Dot11InformationElementIDAdvertisementProtocol Dot11InformationElementID = 108
|
||||
Dot11InformationElementIDExpBWRequest Dot11InformationElementID = 109
|
||||
Dot11InformationElementIDQOSMapSet Dot11InformationElementID = 110
|
||||
Dot11InformationElementIDRoamingConsortium Dot11InformationElementID = 111
|
||||
Dot11InformationElementIDEmergencyAlertIdentifier Dot11InformationElementID = 112
|
||||
Dot11InformationElementIDMeshConfiguration Dot11InformationElementID = 113
|
||||
Dot11InformationElementIDMeshID Dot11InformationElementID = 114
|
||||
Dot11InformationElementIDMeshLinkMetricReport Dot11InformationElementID = 115
|
||||
Dot11InformationElementIDCongestionNotification Dot11InformationElementID = 116
|
||||
Dot11InformationElementIDMeshPeeringManagement Dot11InformationElementID = 117
|
||||
Dot11InformationElementIDMeshChannelSwitchParam Dot11InformationElementID = 118
|
||||
Dot11InformationElementIDMeshAwakeWindows Dot11InformationElementID = 119
|
||||
Dot11InformationElementIDBeaconTiming Dot11InformationElementID = 120
|
||||
Dot11InformationElementIDMCCAOPSetupRequest Dot11InformationElementID = 121
|
||||
Dot11InformationElementIDMCCAOPSetupReply Dot11InformationElementID = 122
|
||||
Dot11InformationElementIDMCCAOPAdvertisement Dot11InformationElementID = 123
|
||||
Dot11InformationElementIDMCCAOPTeardown Dot11InformationElementID = 124
|
||||
Dot11InformationElementIDGateAnnouncement Dot11InformationElementID = 125
|
||||
Dot11InformationElementIDRootAnnouncement Dot11InformationElementID = 126
|
||||
Dot11InformationElementIDExtCapability Dot11InformationElementID = 127
|
||||
Dot11InformationElementIDAgereProprietary Dot11InformationElementID = 128
|
||||
Dot11InformationElementIDPathRequest Dot11InformationElementID = 130
|
||||
Dot11InformationElementIDPathReply Dot11InformationElementID = 131
|
||||
Dot11InformationElementIDPathError Dot11InformationElementID = 132
|
||||
Dot11InformationElementIDCiscoCCX1CKIPDeviceName Dot11InformationElementID = 133
|
||||
Dot11InformationElementIDCiscoCCX2 Dot11InformationElementID = 136
|
||||
Dot11InformationElementIDProxyUpdate Dot11InformationElementID = 137
|
||||
Dot11InformationElementIDProxyUpdateConfirmation Dot11InformationElementID = 138
|
||||
Dot11InformationElementIDAuthMeshPerringExch Dot11InformationElementID = 139
|
||||
Dot11InformationElementIDMIC Dot11InformationElementID = 140
|
||||
Dot11InformationElementIDDestinationURI Dot11InformationElementID = 141
|
||||
Dot11InformationElementIDUAPSDCoexistence Dot11InformationElementID = 142
|
||||
Dot11InformationElementIDWakeupSchedule80211ad Dot11InformationElementID = 143
|
||||
Dot11InformationElementIDExtendedSchedule Dot11InformationElementID = 144
|
||||
Dot11InformationElementIDSTAAvailability Dot11InformationElementID = 145
|
||||
Dot11InformationElementIDDMGTSPEC Dot11InformationElementID = 146
|
||||
Dot11InformationElementIDNextDMGATI Dot11InformationElementID = 147
|
||||
Dot11InformationElementIDDMSCapabilities Dot11InformationElementID = 148
|
||||
Dot11InformationElementIDCiscoUnknown95 Dot11InformationElementID = 149
|
||||
Dot11InformationElementIDVendor2 Dot11InformationElementID = 150
|
||||
Dot11InformationElementIDDMGOperating Dot11InformationElementID = 151
|
||||
Dot11InformationElementIDDMGBSSParamChange Dot11InformationElementID = 152
|
||||
Dot11InformationElementIDDMGBeamRefinement Dot11InformationElementID = 153
|
||||
Dot11InformationElementIDChannelMeasFeedback Dot11InformationElementID = 154
|
||||
Dot11InformationElementIDAwakeWindow Dot11InformationElementID = 157
|
||||
Dot11InformationElementIDMultiBand Dot11InformationElementID = 158
|
||||
Dot11InformationElementIDADDBAExtension Dot11InformationElementID = 159
|
||||
Dot11InformationElementIDNEXTPCPList Dot11InformationElementID = 160
|
||||
Dot11InformationElementIDPCPHandover Dot11InformationElementID = 161
|
||||
Dot11InformationElementIDDMGLinkMargin Dot11InformationElementID = 162
|
||||
Dot11InformationElementIDSwitchingStream Dot11InformationElementID = 163
|
||||
Dot11InformationElementIDSessionTransmission Dot11InformationElementID = 164
|
||||
Dot11InformationElementIDDynamicTonePairReport Dot11InformationElementID = 165
|
||||
Dot11InformationElementIDClusterReport Dot11InformationElementID = 166
|
||||
Dot11InformationElementIDRelayCapabilities Dot11InformationElementID = 167
|
||||
Dot11InformationElementIDRelayTransferParameter Dot11InformationElementID = 168
|
||||
Dot11InformationElementIDBeamlinkMaintenance Dot11InformationElementID = 169
|
||||
Dot11InformationElementIDMultipleMacSublayers Dot11InformationElementID = 170
|
||||
Dot11InformationElementIDUPID Dot11InformationElementID = 171
|
||||
Dot11InformationElementIDDMGLinkAdaptionAck Dot11InformationElementID = 172
|
||||
Dot11InformationElementIDSymbolProprietary Dot11InformationElementID = 173
|
||||
Dot11InformationElementIDMCCAOPAdvertOverview Dot11InformationElementID = 174
|
||||
Dot11InformationElementIDQuietPeriodRequest Dot11InformationElementID = 175
|
||||
Dot11InformationElementIDQuietPeriodResponse Dot11InformationElementID = 177
|
||||
Dot11InformationElementIDECPACPolicy Dot11InformationElementID = 182
|
||||
Dot11InformationElementIDClusterTimeOffset Dot11InformationElementID = 183
|
||||
Dot11InformationElementIDAntennaSectorID Dot11InformationElementID = 190
|
||||
Dot11InformationElementIDVHTCapabilities Dot11InformationElementID = 191
|
||||
Dot11InformationElementIDVHTOperation Dot11InformationElementID = 192
|
||||
Dot11InformationElementIDExtendedBSSLoad Dot11InformationElementID = 193
|
||||
Dot11InformationElementIDWideBWChannelSwitch Dot11InformationElementID = 194
|
||||
Dot11InformationElementIDVHTTxPowerEnvelope Dot11InformationElementID = 195
|
||||
Dot11InformationElementIDChannelSwitchWrapper Dot11InformationElementID = 196
|
||||
Dot11InformationElementIDOperatingModeNotification Dot11InformationElementID = 199
|
||||
Dot11InformationElementIDVendor Dot11InformationElementID = 221
|
||||
)
|
||||
|
||||
// String provides a human readable string for Dot11InformationElementID.
|
||||
|
@ -267,35 +415,335 @@ const (
|
|||
func (a Dot11InformationElementID) String() string {
|
||||
switch a {
|
||||
case Dot11InformationElementIDSSID:
|
||||
return "SSID"
|
||||
return "SSID parameter set"
|
||||
case Dot11InformationElementIDRates:
|
||||
return "Rates"
|
||||
return "Supported Rates"
|
||||
case Dot11InformationElementIDFHSet:
|
||||
return "FHset"
|
||||
return "FH Parameter set"
|
||||
case Dot11InformationElementIDDSSet:
|
||||
return "DSset"
|
||||
return "DS Parameter set"
|
||||
case Dot11InformationElementIDCFSet:
|
||||
return "CFset"
|
||||
return "CF Parameter set"
|
||||
case Dot11InformationElementIDTIM:
|
||||
return "TIM"
|
||||
return "Traffic Indication Map (TIM)"
|
||||
case Dot11InformationElementIDIBSSSet:
|
||||
return "IBSSset"
|
||||
return "IBSS Parameter set"
|
||||
case Dot11InformationElementIDCountryInfo:
|
||||
return "Country Information"
|
||||
case Dot11InformationElementIDHoppingPatternParam:
|
||||
return "Hopping Pattern Parameters"
|
||||
case Dot11InformationElementIDHoppingPatternTable:
|
||||
return "Hopping Pattern Table"
|
||||
case Dot11InformationElementIDRequest:
|
||||
return "Request"
|
||||
case Dot11InformationElementIDQBSSLoadElem:
|
||||
return "QBSS Load Element"
|
||||
case Dot11InformationElementIDEDCAParamSet:
|
||||
return "EDCA Parameter Set"
|
||||
case Dot11InformationElementIDTrafficSpec:
|
||||
return "Traffic Specification"
|
||||
case Dot11InformationElementIDTrafficClass:
|
||||
return "Traffic Classification"
|
||||
case Dot11InformationElementIDSchedule:
|
||||
return "Schedule"
|
||||
case Dot11InformationElementIDChallenge:
|
||||
return "Challenge"
|
||||
return "Challenge text"
|
||||
case Dot11InformationElementIDPowerConst:
|
||||
return "Power Constraint"
|
||||
case Dot11InformationElementIDPowerCapability:
|
||||
return "Power Capability"
|
||||
case Dot11InformationElementIDTPCRequest:
|
||||
return "TPC Request"
|
||||
case Dot11InformationElementIDTPCReport:
|
||||
return "TPC Report"
|
||||
case Dot11InformationElementIDSupportedChannels:
|
||||
return "Supported Channels"
|
||||
case Dot11InformationElementIDSwitchChannelAnnounce:
|
||||
return "Channel Switch Announcement"
|
||||
case Dot11InformationElementIDMeasureRequest:
|
||||
return "Measurement Request"
|
||||
case Dot11InformationElementIDMeasureReport:
|
||||
return "Measurement Report"
|
||||
case Dot11InformationElementIDQuiet:
|
||||
return "Quiet"
|
||||
case Dot11InformationElementIDIBSSDFS:
|
||||
return "IBSS DFS"
|
||||
case Dot11InformationElementIDERPInfo:
|
||||
return "ERPinfo"
|
||||
return "ERP Information"
|
||||
case Dot11InformationElementIDTSDelay:
|
||||
return "TS Delay"
|
||||
case Dot11InformationElementIDTCLASProcessing:
|
||||
return "TCLAS Processing"
|
||||
case Dot11InformationElementIDHTCapabilities:
|
||||
return "HT Capabilities (802.11n D1.10)"
|
||||
case Dot11InformationElementIDQOSCapability:
|
||||
return "QOS capability"
|
||||
return "QOS Capability"
|
||||
case Dot11InformationElementIDERPInfo2:
|
||||
return "ERPinfo2"
|
||||
return "ERP Information-2"
|
||||
case Dot11InformationElementIDRSNInfo:
|
||||
return "RSNinfo"
|
||||
return "RSN Information"
|
||||
case Dot11InformationElementIDESRates:
|
||||
return "ESrates"
|
||||
return "Extended Supported Rates"
|
||||
case Dot11InformationElementIDAPChannelReport:
|
||||
return "AP Channel Report"
|
||||
case Dot11InformationElementIDNeighborReport:
|
||||
return "Neighbor Report"
|
||||
case Dot11InformationElementIDRCPI:
|
||||
return "RCPI"
|
||||
case Dot11InformationElementIDMobilityDomain:
|
||||
return "Mobility Domain"
|
||||
case Dot11InformationElementIDFastBSSTrans:
|
||||
return "Fast BSS Transition"
|
||||
case Dot11InformationElementIDTimeoutInt:
|
||||
return "Timeout Interval"
|
||||
case Dot11InformationElementIDRICData:
|
||||
return "RIC Data"
|
||||
case Dot11InformationElementIDDSERegisteredLoc:
|
||||
return "DSE Registered Location"
|
||||
case Dot11InformationElementIDSuppOperatingClass:
|
||||
return "Supported Operating Classes"
|
||||
case Dot11InformationElementIDExtChanSwitchAnnounce:
|
||||
return "Extended Channel Switch Announcement"
|
||||
case Dot11InformationElementIDHTInfo:
|
||||
return "HT Information (802.11n D1.10)"
|
||||
case Dot11InformationElementIDSecChanOffset:
|
||||
return "Secondary Channel Offset (802.11n D1.10)"
|
||||
case Dot11InformationElementIDBSSAverageAccessDelay:
|
||||
return "BSS Average Access Delay"
|
||||
case Dot11InformationElementIDAntenna:
|
||||
return "Antenna"
|
||||
case Dot11InformationElementIDRSNI:
|
||||
return "RSNI"
|
||||
case Dot11InformationElementIDMeasurePilotTrans:
|
||||
return "Measurement Pilot Transmission"
|
||||
case Dot11InformationElementIDBSSAvailAdmCapacity:
|
||||
return "BSS Available Admission Capacity"
|
||||
case Dot11InformationElementIDBSSACAccDelayWAPIParam:
|
||||
return "BSS AC Access Delay/WAPI Parameter Set"
|
||||
case Dot11InformationElementIDTimeAdvertisement:
|
||||
return "Time Advertisement"
|
||||
case Dot11InformationElementIDRMEnabledCapabilities:
|
||||
return "RM Enabled Capabilities"
|
||||
case Dot11InformationElementIDMultipleBSSID:
|
||||
return "Multiple BSSID"
|
||||
case Dot11InformationElementID2040BSSCoExist:
|
||||
return "20/40 BSS Coexistence"
|
||||
case Dot11InformationElementID2040BSSIntChanReport:
|
||||
return "20/40 BSS Intolerant Channel Report"
|
||||
case Dot11InformationElementIDOverlapBSSScanParam:
|
||||
return "Overlapping BSS Scan Parameters"
|
||||
case Dot11InformationElementIDRICDescriptor:
|
||||
return "RIC Descriptor"
|
||||
case Dot11InformationElementIDManagementMIC:
|
||||
return "Management MIC"
|
||||
case Dot11InformationElementIDEventRequest:
|
||||
return "Event Request"
|
||||
case Dot11InformationElementIDEventReport:
|
||||
return "Event Report"
|
||||
case Dot11InformationElementIDDiagnosticRequest:
|
||||
return "Diagnostic Request"
|
||||
case Dot11InformationElementIDDiagnosticReport:
|
||||
return "Diagnostic Report"
|
||||
case Dot11InformationElementIDLocationParam:
|
||||
return "Location Parameters"
|
||||
case Dot11InformationElementIDNonTransBSSIDCapability:
|
||||
return "Non Transmitted BSSID Capability"
|
||||
case Dot11InformationElementIDSSIDList:
|
||||
return "SSID List"
|
||||
case Dot11InformationElementIDMultipleBSSIDIndex:
|
||||
return "Multiple BSSID Index"
|
||||
case Dot11InformationElementIDFMSDescriptor:
|
||||
return "FMS Descriptor"
|
||||
case Dot11InformationElementIDFMSRequest:
|
||||
return "FMS Request"
|
||||
case Dot11InformationElementIDFMSResponse:
|
||||
return "FMS Response"
|
||||
case Dot11InformationElementIDQOSTrafficCapability:
|
||||
return "QoS Traffic Capability"
|
||||
case Dot11InformationElementIDBSSMaxIdlePeriod:
|
||||
return "BSS Max Idle Period"
|
||||
case Dot11InformationElementIDTFSRequest:
|
||||
return "TFS Request"
|
||||
case Dot11InformationElementIDTFSResponse:
|
||||
return "TFS Response"
|
||||
case Dot11InformationElementIDWNMSleepMode:
|
||||
return "WNM-Sleep Mode"
|
||||
case Dot11InformationElementIDTIMBroadcastRequest:
|
||||
return "TIM Broadcast Request"
|
||||
case Dot11InformationElementIDTIMBroadcastResponse:
|
||||
return "TIM Broadcast Response"
|
||||
case Dot11InformationElementIDCollInterferenceReport:
|
||||
return "Collocated Interference Report"
|
||||
case Dot11InformationElementIDChannelUsage:
|
||||
return "Channel Usage"
|
||||
case Dot11InformationElementIDTimeZone:
|
||||
return "Time Zone"
|
||||
case Dot11InformationElementIDDMSRequest:
|
||||
return "DMS Request"
|
||||
case Dot11InformationElementIDDMSResponse:
|
||||
return "DMS Response"
|
||||
case Dot11InformationElementIDLinkIdentifier:
|
||||
return "Link Identifier"
|
||||
case Dot11InformationElementIDWakeupSchedule:
|
||||
return "Wakeup Schedule"
|
||||
case Dot11InformationElementIDChannelSwitchTiming:
|
||||
return "Channel Switch Timing"
|
||||
case Dot11InformationElementIDPTIControl:
|
||||
return "PTI Control"
|
||||
case Dot11InformationElementIDPUBufferStatus:
|
||||
return "PU Buffer Status"
|
||||
case Dot11InformationElementIDInterworking:
|
||||
return "Interworking"
|
||||
case Dot11InformationElementIDAdvertisementProtocol:
|
||||
return "Advertisement Protocol"
|
||||
case Dot11InformationElementIDExpBWRequest:
|
||||
return "Expedited Bandwidth Request"
|
||||
case Dot11InformationElementIDQOSMapSet:
|
||||
return "QoS Map Set"
|
||||
case Dot11InformationElementIDRoamingConsortium:
|
||||
return "Roaming Consortium"
|
||||
case Dot11InformationElementIDEmergencyAlertIdentifier:
|
||||
return "Emergency Alert Identifier"
|
||||
case Dot11InformationElementIDMeshConfiguration:
|
||||
return "Mesh Configuration"
|
||||
case Dot11InformationElementIDMeshID:
|
||||
return "Mesh ID"
|
||||
case Dot11InformationElementIDMeshLinkMetricReport:
|
||||
return "Mesh Link Metric Report"
|
||||
case Dot11InformationElementIDCongestionNotification:
|
||||
return "Congestion Notification"
|
||||
case Dot11InformationElementIDMeshPeeringManagement:
|
||||
return "Mesh Peering Management"
|
||||
case Dot11InformationElementIDMeshChannelSwitchParam:
|
||||
return "Mesh Channel Switch Parameters"
|
||||
case Dot11InformationElementIDMeshAwakeWindows:
|
||||
return "Mesh Awake Windows"
|
||||
case Dot11InformationElementIDBeaconTiming:
|
||||
return "Beacon Timing"
|
||||
case Dot11InformationElementIDMCCAOPSetupRequest:
|
||||
return "MCCAOP Setup Request"
|
||||
case Dot11InformationElementIDMCCAOPSetupReply:
|
||||
return "MCCAOP SETUP Reply"
|
||||
case Dot11InformationElementIDMCCAOPAdvertisement:
|
||||
return "MCCAOP Advertisement"
|
||||
case Dot11InformationElementIDMCCAOPTeardown:
|
||||
return "MCCAOP Teardown"
|
||||
case Dot11InformationElementIDGateAnnouncement:
|
||||
return "Gate Announcement"
|
||||
case Dot11InformationElementIDRootAnnouncement:
|
||||
return "Root Announcement"
|
||||
case Dot11InformationElementIDExtCapability:
|
||||
return "Extended Capabilities"
|
||||
case Dot11InformationElementIDAgereProprietary:
|
||||
return "Agere Proprietary"
|
||||
case Dot11InformationElementIDPathRequest:
|
||||
return "Path Request"
|
||||
case Dot11InformationElementIDPathReply:
|
||||
return "Path Reply"
|
||||
case Dot11InformationElementIDPathError:
|
||||
return "Path Error"
|
||||
case Dot11InformationElementIDCiscoCCX1CKIPDeviceName:
|
||||
return "Cisco CCX1 CKIP + Device Name"
|
||||
case Dot11InformationElementIDCiscoCCX2:
|
||||
return "Cisco CCX2"
|
||||
case Dot11InformationElementIDProxyUpdate:
|
||||
return "Proxy Update"
|
||||
case Dot11InformationElementIDProxyUpdateConfirmation:
|
||||
return "Proxy Update Confirmation"
|
||||
case Dot11InformationElementIDAuthMeshPerringExch:
|
||||
return "Auhenticated Mesh Perring Exchange"
|
||||
case Dot11InformationElementIDMIC:
|
||||
return "MIC (Message Integrity Code)"
|
||||
case Dot11InformationElementIDDestinationURI:
|
||||
return "Destination URI"
|
||||
case Dot11InformationElementIDUAPSDCoexistence:
|
||||
return "U-APSD Coexistence"
|
||||
case Dot11InformationElementIDWakeupSchedule80211ad:
|
||||
return "Wakeup Schedule 802.11ad"
|
||||
case Dot11InformationElementIDExtendedSchedule:
|
||||
return "Extended Schedule"
|
||||
case Dot11InformationElementIDSTAAvailability:
|
||||
return "STA Availability"
|
||||
case Dot11InformationElementIDDMGTSPEC:
|
||||
return "DMG TSPEC"
|
||||
case Dot11InformationElementIDNextDMGATI:
|
||||
return "Next DMG ATI"
|
||||
case Dot11InformationElementIDDMSCapabilities:
|
||||
return "DMG Capabilities"
|
||||
case Dot11InformationElementIDCiscoUnknown95:
|
||||
return "Cisco Unknown 95"
|
||||
case Dot11InformationElementIDVendor2:
|
||||
return "Vendor Specific"
|
||||
case Dot11InformationElementIDDMGOperating:
|
||||
return "DMG Operating"
|
||||
case Dot11InformationElementIDDMGBSSParamChange:
|
||||
return "DMG BSS Parameter Change"
|
||||
case Dot11InformationElementIDDMGBeamRefinement:
|
||||
return "DMG Beam Refinement"
|
||||
case Dot11InformationElementIDChannelMeasFeedback:
|
||||
return "Channel Measurement Feedback"
|
||||
case Dot11InformationElementIDAwakeWindow:
|
||||
return "Awake Window"
|
||||
case Dot11InformationElementIDMultiBand:
|
||||
return "Multi Band"
|
||||
case Dot11InformationElementIDADDBAExtension:
|
||||
return "ADDBA Extension"
|
||||
case Dot11InformationElementIDNEXTPCPList:
|
||||
return "NEXTPCP List"
|
||||
case Dot11InformationElementIDPCPHandover:
|
||||
return "PCP Handover"
|
||||
case Dot11InformationElementIDDMGLinkMargin:
|
||||
return "DMG Link Margin"
|
||||
case Dot11InformationElementIDSwitchingStream:
|
||||
return "Switching Stream"
|
||||
case Dot11InformationElementIDSessionTransmission:
|
||||
return "Session Transmission"
|
||||
case Dot11InformationElementIDDynamicTonePairReport:
|
||||
return "Dynamic Tone Pairing Report"
|
||||
case Dot11InformationElementIDClusterReport:
|
||||
return "Cluster Report"
|
||||
case Dot11InformationElementIDRelayCapabilities:
|
||||
return "Relay Capabilities"
|
||||
case Dot11InformationElementIDRelayTransferParameter:
|
||||
return "Relay Transfer Parameter"
|
||||
case Dot11InformationElementIDBeamlinkMaintenance:
|
||||
return "Beamlink Maintenance"
|
||||
case Dot11InformationElementIDMultipleMacSublayers:
|
||||
return "Multiple MAC Sublayers"
|
||||
case Dot11InformationElementIDUPID:
|
||||
return "U-PID"
|
||||
case Dot11InformationElementIDDMGLinkAdaptionAck:
|
||||
return "DMG Link Adaption Acknowledgment"
|
||||
case Dot11InformationElementIDSymbolProprietary:
|
||||
return "Symbol Proprietary"
|
||||
case Dot11InformationElementIDMCCAOPAdvertOverview:
|
||||
return "MCCAOP Advertisement Overview"
|
||||
case Dot11InformationElementIDQuietPeriodRequest:
|
||||
return "Quiet Period Request"
|
||||
case Dot11InformationElementIDQuietPeriodResponse:
|
||||
return "Quiet Period Response"
|
||||
case Dot11InformationElementIDECPACPolicy:
|
||||
return "ECPAC Policy"
|
||||
case Dot11InformationElementIDClusterTimeOffset:
|
||||
return "Cluster Time Offset"
|
||||
case Dot11InformationElementIDAntennaSectorID:
|
||||
return "Antenna Sector ID"
|
||||
case Dot11InformationElementIDVHTCapabilities:
|
||||
return "VHT Capabilities (IEEE Std 802.11ac/D3.1)"
|
||||
case Dot11InformationElementIDVHTOperation:
|
||||
return "VHT Operation (IEEE Std 802.11ac/D3.1)"
|
||||
case Dot11InformationElementIDExtendedBSSLoad:
|
||||
return "Extended BSS Load"
|
||||
case Dot11InformationElementIDWideBWChannelSwitch:
|
||||
return "Wide Bandwidth Channel Switch"
|
||||
case Dot11InformationElementIDVHTTxPowerEnvelope:
|
||||
return "VHT Tx Power Envelope (IEEE Std 802.11ac/D5.0)"
|
||||
case Dot11InformationElementIDChannelSwitchWrapper:
|
||||
return "Channel Switch Wrapper"
|
||||
case Dot11InformationElementIDOperatingModeNotification:
|
||||
return "Operating Mode Notification"
|
||||
case Dot11InformationElementIDVendor:
|
||||
return "Vendor"
|
||||
case Dot11InformationElementIDReserved:
|
||||
return "Reserved"
|
||||
default:
|
||||
return "Unknown information element id"
|
||||
}
|
||||
|
@ -303,7 +751,7 @@ func (a Dot11InformationElementID) String() string {
|
|||
|
||||
// Dot11 provides an IEEE 802.11 base packet header.
|
||||
// See http://standards.ieee.org/findstds/standard/802.11-2012.html
|
||||
// for excrutiating detail.
|
||||
// for excruciating detail.
|
||||
type Dot11 struct {
|
||||
BaseLayer
|
||||
Type Dot11Type
|
||||
|
@ -317,23 +765,138 @@ type Dot11 struct {
|
|||
SequenceNumber uint16
|
||||
FragmentNumber uint16
|
||||
Checksum uint32
|
||||
QOS *Dot11QOS
|
||||
HTControl *Dot11HTControl
|
||||
DataLayer gopacket.Layer
|
||||
}
|
||||
|
||||
type Dot11QOS struct {
|
||||
TID uint8 /* Traffic IDentifier */
|
||||
EOSP bool /* End of service period */
|
||||
AckPolicy Dot11AckPolicy
|
||||
TXOP uint8
|
||||
}
|
||||
|
||||
type Dot11HTControl struct {
|
||||
ACConstraint bool
|
||||
RDGMorePPDU bool
|
||||
|
||||
VHT *Dot11HTControlVHT
|
||||
HT *Dot11HTControlHT
|
||||
}
|
||||
|
||||
type Dot11HTControlHT struct {
|
||||
LinkAdapationControl *Dot11LinkAdapationControl
|
||||
CalibrationPosition uint8
|
||||
CalibrationSequence uint8
|
||||
CSISteering uint8
|
||||
NDPAnnouncement bool
|
||||
DEI bool
|
||||
}
|
||||
|
||||
type Dot11HTControlVHT struct {
|
||||
MRQ bool
|
||||
UnsolicitedMFB bool
|
||||
MSI *uint8
|
||||
MFB Dot11HTControlMFB
|
||||
CompressedMSI *uint8
|
||||
STBCIndication bool
|
||||
MFSI *uint8
|
||||
GID *uint8
|
||||
CodingType *Dot11CodingType
|
||||
FbTXBeamformed bool
|
||||
}
|
||||
|
||||
type Dot11HTControlMFB struct {
|
||||
NumSTS uint8
|
||||
VHTMCS uint8
|
||||
BW uint8
|
||||
SNR int8
|
||||
}
|
||||
|
||||
type Dot11LinkAdapationControl struct {
|
||||
TRQ bool
|
||||
MRQ bool
|
||||
MSI uint8
|
||||
MFSI uint8
|
||||
ASEL *Dot11ASEL
|
||||
MFB *uint8
|
||||
}
|
||||
|
||||
type Dot11ASEL struct {
|
||||
Command uint8
|
||||
Data uint8
|
||||
}
|
||||
|
||||
type Dot11CodingType uint8
|
||||
|
||||
const (
|
||||
Dot11CodingTypeBCC = 0
|
||||
Dot11CodingTypeLDPC = 1
|
||||
)
|
||||
|
||||
func (a Dot11CodingType) String() string {
|
||||
switch a {
|
||||
case Dot11CodingTypeBCC:
|
||||
return "BCC"
|
||||
case Dot11CodingTypeLDPC:
|
||||
return "LDPC"
|
||||
default:
|
||||
return "Unknown coding type"
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Dot11HTControlMFB) NoFeedBackPresent() bool {
|
||||
return m.VHTMCS == 15 && m.NumSTS == 7
|
||||
}
|
||||
|
||||
func decodeDot11(data []byte, p gopacket.PacketBuilder) error {
|
||||
d := &Dot11{}
|
||||
return decodingLayerDecoder(d, data, p)
|
||||
err := d.DecodeFromBytes(data, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.AddLayer(d)
|
||||
if d.DataLayer != nil {
|
||||
p.AddLayer(d.DataLayer)
|
||||
}
|
||||
return p.NextDecoder(d.NextLayerType())
|
||||
}
|
||||
|
||||
func (m *Dot11) LayerType() gopacket.LayerType { return LayerTypeDot11 }
|
||||
func (m *Dot11) CanDecode() gopacket.LayerClass { return LayerTypeDot11 }
|
||||
func (m *Dot11) NextLayerType() gopacket.LayerType {
|
||||
if m.Flags.WEP() {
|
||||
return (LayerTypeDot11WEP)
|
||||
if m.DataLayer != nil {
|
||||
if m.Flags.WEP() {
|
||||
return LayerTypeDot11WEP
|
||||
}
|
||||
return m.DataLayer.(gopacket.DecodingLayer).NextLayerType()
|
||||
}
|
||||
|
||||
return m.Type.LayerType()
|
||||
}
|
||||
|
||||
func createU8(x uint8) *uint8 {
|
||||
return &x
|
||||
}
|
||||
|
||||
var dataDecodeMap = map[Dot11Type]func() gopacket.DecodingLayer{
|
||||
Dot11TypeData: func() gopacket.DecodingLayer { return &Dot11Data{} },
|
||||
Dot11TypeDataCFAck: func() gopacket.DecodingLayer { return &Dot11DataCFAck{} },
|
||||
Dot11TypeDataCFPoll: func() gopacket.DecodingLayer { return &Dot11DataCFPoll{} },
|
||||
Dot11TypeDataCFAckPoll: func() gopacket.DecodingLayer { return &Dot11DataCFAckPoll{} },
|
||||
Dot11TypeDataNull: func() gopacket.DecodingLayer { return &Dot11DataNull{} },
|
||||
Dot11TypeDataCFAckNoData: func() gopacket.DecodingLayer { return &Dot11DataCFAckNoData{} },
|
||||
Dot11TypeDataCFPollNoData: func() gopacket.DecodingLayer { return &Dot11DataCFPollNoData{} },
|
||||
Dot11TypeDataCFAckPollNoData: func() gopacket.DecodingLayer { return &Dot11DataCFAckPollNoData{} },
|
||||
Dot11TypeDataQOSData: func() gopacket.DecodingLayer { return &Dot11DataQOSData{} },
|
||||
Dot11TypeDataQOSDataCFAck: func() gopacket.DecodingLayer { return &Dot11DataQOSDataCFAck{} },
|
||||
Dot11TypeDataQOSDataCFPoll: func() gopacket.DecodingLayer { return &Dot11DataQOSDataCFPoll{} },
|
||||
Dot11TypeDataQOSDataCFAckPoll: func() gopacket.DecodingLayer { return &Dot11DataQOSDataCFAckPoll{} },
|
||||
Dot11TypeDataQOSNull: func() gopacket.DecodingLayer { return &Dot11DataQOSNull{} },
|
||||
Dot11TypeDataQOSCFPollNoData: func() gopacket.DecodingLayer { return &Dot11DataQOSCFPollNoData{} },
|
||||
Dot11TypeDataQOSCFAckPollNoData: func() gopacket.DecodingLayer { return &Dot11DataQOSCFAckPollNoData{} },
|
||||
}
|
||||
|
||||
func (m *Dot11) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
if len(data) < 10 {
|
||||
df.SetTruncated()
|
||||
|
@ -385,7 +948,112 @@ func (m *Dot11) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
|||
offset += 6
|
||||
}
|
||||
|
||||
m.BaseLayer = BaseLayer{Contents: data[0:offset], Payload: data[offset : len(data)-4]}
|
||||
if m.Type.QOS() {
|
||||
if len(data) < offset+2 {
|
||||
df.SetTruncated()
|
||||
return fmt.Errorf("Dot11 length %v too short, %v required", len(data), offset+6)
|
||||
}
|
||||
m.QOS = &Dot11QOS{
|
||||
TID: (uint8(data[offset]) & 0x0F),
|
||||
EOSP: (uint8(data[offset]) & 0x10) == 0x10,
|
||||
AckPolicy: Dot11AckPolicy((uint8(data[offset]) & 0x60) >> 5),
|
||||
TXOP: uint8(data[offset+1]),
|
||||
}
|
||||
offset += 2
|
||||
}
|
||||
if m.Flags.Order() && (m.Type.QOS() || mainType == Dot11TypeMgmt) {
|
||||
if len(data) < offset+4 {
|
||||
df.SetTruncated()
|
||||
return fmt.Errorf("Dot11 length %v too short, %v required", len(data), offset+6)
|
||||
}
|
||||
|
||||
htc := &Dot11HTControl{
|
||||
ACConstraint: data[offset+3]&0x40 != 0,
|
||||
RDGMorePPDU: data[offset+3]&0x80 != 0,
|
||||
}
|
||||
m.HTControl = htc
|
||||
|
||||
if data[offset]&0x1 != 0 { // VHT Variant
|
||||
vht := &Dot11HTControlVHT{}
|
||||
htc.VHT = vht
|
||||
vht.MRQ = data[offset]&0x4 != 0
|
||||
vht.UnsolicitedMFB = data[offset+3]&0x20 != 0
|
||||
vht.MFB = Dot11HTControlMFB{
|
||||
NumSTS: uint8(data[offset+1] >> 1 & 0x7),
|
||||
VHTMCS: uint8(data[offset+1] >> 4 & 0xF),
|
||||
BW: uint8(data[offset+2] & 0x3),
|
||||
SNR: int8((-(data[offset+2] >> 2 & 0x20))+data[offset+2]>>2&0x1F) + 22,
|
||||
}
|
||||
|
||||
if vht.UnsolicitedMFB {
|
||||
if !vht.MFB.NoFeedBackPresent() {
|
||||
vht.CompressedMSI = createU8(data[offset] >> 3 & 0x3)
|
||||
vht.STBCIndication = data[offset]&0x20 != 0
|
||||
vht.CodingType = (*Dot11CodingType)(createU8(data[offset+3] >> 3 & 0x1))
|
||||
vht.FbTXBeamformed = data[offset+3]&0x10 != 0
|
||||
vht.GID = createU8(
|
||||
data[offset]>>6 +
|
||||
(data[offset+1] & 0x1 << 2) +
|
||||
data[offset+3]&0x7<<3)
|
||||
}
|
||||
} else {
|
||||
if vht.MRQ {
|
||||
vht.MSI = createU8((data[offset] >> 3) & 0x07)
|
||||
}
|
||||
vht.MFSI = createU8(data[offset]>>6 + (data[offset+1] & 0x1 << 2))
|
||||
}
|
||||
|
||||
} else { // HT Variant
|
||||
ht := &Dot11HTControlHT{}
|
||||
htc.HT = ht
|
||||
|
||||
lac := &Dot11LinkAdapationControl{}
|
||||
ht.LinkAdapationControl = lac
|
||||
lac.TRQ = data[offset]&0x2 != 0
|
||||
lac.MFSI = data[offset]>>6&0x3 + data[offset+1]&0x1<<3
|
||||
if data[offset]&0x3C == 0x38 { // ASEL
|
||||
lac.ASEL = &Dot11ASEL{
|
||||
Command: data[offset+1] >> 1 & 0x7,
|
||||
Data: data[offset+1] >> 4 & 0xF,
|
||||
}
|
||||
} else {
|
||||
lac.MRQ = data[offset]&0x4 != 0
|
||||
if lac.MRQ {
|
||||
lac.MSI = data[offset] >> 3 & 0x7
|
||||
}
|
||||
lac.MFB = createU8(data[offset+1] >> 1)
|
||||
}
|
||||
ht.CalibrationPosition = data[offset+2] & 0x3
|
||||
ht.CalibrationSequence = data[offset+2] >> 2 & 0x3
|
||||
ht.CSISteering = data[offset+2] >> 6 & 0x3
|
||||
ht.NDPAnnouncement = data[offset+3]&0x1 != 0
|
||||
if mainType != Dot11TypeMgmt {
|
||||
ht.DEI = data[offset+3]&0x20 != 0
|
||||
}
|
||||
}
|
||||
|
||||
offset += 4
|
||||
}
|
||||
|
||||
if len(data) < offset+4 {
|
||||
df.SetTruncated()
|
||||
return fmt.Errorf("Dot11 length %v too short, %v required", len(data), offset+4)
|
||||
}
|
||||
|
||||
m.BaseLayer = BaseLayer{
|
||||
Contents: data[0:offset],
|
||||
Payload: data[offset : len(data)-4],
|
||||
}
|
||||
|
||||
if mainType == Dot11TypeData {
|
||||
l := dataDecodeMap[m.Type]()
|
||||
err := l.DecodeFromBytes(m.BaseLayer.Payload, df)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.DataLayer = l.(gopacket.Layer)
|
||||
}
|
||||
|
||||
m.Checksum = binary.LittleEndian.Uint32(data[len(data)-4 : len(data)])
|
||||
return nil
|
||||
}
|
||||
|
@ -474,7 +1142,7 @@ type Dot11WEP struct {
|
|||
BaseLayer
|
||||
}
|
||||
|
||||
func (m *Dot11WEP) NextLayerType() gopacket.LayerType { return LayerTypeLLC }
|
||||
func (m *Dot11WEP) NextLayerType() gopacket.LayerType { return gopacket.LayerTypePayload }
|
||||
|
||||
func (m *Dot11WEP) LayerType() gopacket.LayerType { return LayerTypeDot11WEP }
|
||||
func (m *Dot11WEP) CanDecode() gopacket.LayerClass { return LayerTypeDot11WEP }
|
||||
|
@ -493,7 +1161,9 @@ type Dot11Data struct {
|
|||
BaseLayer
|
||||
}
|
||||
|
||||
func (m *Dot11Data) NextLayerType() gopacket.LayerType { return LayerTypeLLC }
|
||||
func (m *Dot11Data) NextLayerType() gopacket.LayerType {
|
||||
return LayerTypeLLC
|
||||
}
|
||||
|
||||
func (m *Dot11Data) LayerType() gopacket.LayerType { return LayerTypeDot11Data }
|
||||
func (m *Dot11Data) CanDecode() gopacket.LayerClass { return LayerTypeDot11Data }
|
||||
|
@ -618,23 +1288,10 @@ func (m *Dot11DataCFAckPollNoData) DecodeFromBytes(data []byte, df gopacket.Deco
|
|||
|
||||
type Dot11DataQOS struct {
|
||||
Dot11Ctrl
|
||||
TID uint8 /* Traffic IDentifier */
|
||||
EOSP bool /* End of service period */
|
||||
AckPolicy Dot11AckPolicy
|
||||
TXOP uint8
|
||||
}
|
||||
|
||||
func (m *Dot11DataQOS) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
if len(data) < 4 {
|
||||
df.SetTruncated()
|
||||
return fmt.Errorf("Dot11DataQOS length %v too short, %v required", len(data), 4)
|
||||
}
|
||||
m.TID = (uint8(data[0]) & 0x0F)
|
||||
m.EOSP = (uint8(data[0]) & 0x10) == 0x10
|
||||
m.AckPolicy = Dot11AckPolicy((uint8(data[0]) & 0x60) >> 5)
|
||||
m.TXOP = uint8(data[1])
|
||||
// TODO: Mesh Control bytes 2:4
|
||||
m.BaseLayer = BaseLayer{Contents: data[0:4], Payload: data[4:]}
|
||||
m.BaseLayer = BaseLayer{Payload: data}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -802,7 +1459,7 @@ func (m *Dot11InformationElement) DecodeFromBytes(data []byte, df gopacket.Decod
|
|||
|
||||
func (d *Dot11InformationElement) String() string {
|
||||
if d.ID == 0 {
|
||||
return fmt.Sprintf("802.11 Information Element (SSID: %v)", string(d.Info))
|
||||
return fmt.Sprintf("802.11 Information Element (ID: %v, Length: %v, SSID: %v)", d.ID, d.Length, string(d.Info))
|
||||
} else if d.ID == 1 {
|
||||
rates := ""
|
||||
for i := 0; i < len(d.Info); i++ {
|
||||
|
@ -812,9 +1469,9 @@ func (d *Dot11InformationElement) String() string {
|
|||
rates += fmt.Sprintf("%.1f* ", float32(d.Info[i]&0x7F)*0.5)
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("802.11 Information Element (Rates: %s Mbit)", rates)
|
||||
return fmt.Sprintf("802.11 Information Element (ID: %v, Length: %v, Rates: %s Mbit)", d.ID, d.Length, rates)
|
||||
} else if d.ID == 221 {
|
||||
return fmt.Sprintf("802.11 Information Element (Vendor: ID: %v, Length: %v, OUI: %X, Info: %X)", d.ID, d.Length, d.OUI, d.Info)
|
||||
return fmt.Sprintf("802.11 Information Element (ID: %v, Length: %v, OUI: %X, Info: %X)", d.ID, d.Length, d.OUI, d.Info)
|
||||
} else {
|
||||
return fmt.Sprintf("802.11 Information Element (ID: %v, Length: %v, Info: %X)", d.ID, d.Length, d.Info)
|
||||
}
|
||||
|
|
236
vendor/github.com/google/gopacket/layers/eapol.go
generated
vendored
236
vendor/github.com/google/gopacket/layers/eapol.go
generated
vendored
|
@ -8,6 +8,7 @@ package layers
|
|||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/google/gopacket"
|
||||
)
|
||||
|
||||
|
@ -55,3 +56,238 @@ func decodeEAPOL(data []byte, p gopacket.PacketBuilder) error {
|
|||
e := &EAPOL{}
|
||||
return decodingLayerDecoder(e, data, p)
|
||||
}
|
||||
|
||||
// EAPOLKeyDescriptorType is an enumeration of key descriptor types
|
||||
// as specified by 802.1x in the EAPOL-Key frame
|
||||
type EAPOLKeyDescriptorType uint8
|
||||
|
||||
// Enumeration of EAPOLKeyDescriptorType
|
||||
const (
|
||||
EAPOLKeyDescriptorTypeRC4 EAPOLKeyDescriptorType = 1
|
||||
EAPOLKeyDescriptorTypeDot11 EAPOLKeyDescriptorType = 2
|
||||
EAPOLKeyDescriptorTypeWPA EAPOLKeyDescriptorType = 254
|
||||
)
|
||||
|
||||
func (kdt EAPOLKeyDescriptorType) String() string {
|
||||
switch kdt {
|
||||
case EAPOLKeyDescriptorTypeRC4:
|
||||
return "RC4"
|
||||
case EAPOLKeyDescriptorTypeDot11:
|
||||
return "802.11"
|
||||
case EAPOLKeyDescriptorTypeWPA:
|
||||
return "WPA"
|
||||
default:
|
||||
return fmt.Sprintf("unknown descriptor type %d", kdt)
|
||||
}
|
||||
}
|
||||
|
||||
// EAPOLKeyDescriptorVersion is an enumeration of versions specifying the
|
||||
// encryption algorithm for the key data and the authentication for the
|
||||
// message integrity code (MIC)
|
||||
type EAPOLKeyDescriptorVersion uint8
|
||||
|
||||
// Enumeration of EAPOLKeyDescriptorVersion
|
||||
const (
|
||||
EAPOLKeyDescriptorVersionOther EAPOLKeyDescriptorVersion = 0
|
||||
EAPOLKeyDescriptorVersionRC4HMACMD5 EAPOLKeyDescriptorVersion = 1
|
||||
EAPOLKeyDescriptorVersionAESHMACSHA1 EAPOLKeyDescriptorVersion = 2
|
||||
EAPOLKeyDescriptorVersionAES128CMAC EAPOLKeyDescriptorVersion = 3
|
||||
)
|
||||
|
||||
func (v EAPOLKeyDescriptorVersion) String() string {
|
||||
switch v {
|
||||
case EAPOLKeyDescriptorVersionOther:
|
||||
return "Other"
|
||||
case EAPOLKeyDescriptorVersionRC4HMACMD5:
|
||||
return "RC4-HMAC-MD5"
|
||||
case EAPOLKeyDescriptorVersionAESHMACSHA1:
|
||||
return "AES-HMAC-SHA1-128"
|
||||
case EAPOLKeyDescriptorVersionAES128CMAC:
|
||||
return "AES-128-CMAC"
|
||||
default:
|
||||
return fmt.Sprintf("unknown version %d", v)
|
||||
}
|
||||
}
|
||||
|
||||
// EAPOLKeyType is an enumeration of key derivation types describing
|
||||
// the purpose of the keys being derived.
|
||||
type EAPOLKeyType uint8
|
||||
|
||||
// Enumeration of EAPOLKeyType
|
||||
const (
|
||||
EAPOLKeyTypeGroupSMK EAPOLKeyType = 0
|
||||
EAPOLKeyTypePairwise EAPOLKeyType = 1
|
||||
)
|
||||
|
||||
func (kt EAPOLKeyType) String() string {
|
||||
switch kt {
|
||||
case EAPOLKeyTypeGroupSMK:
|
||||
return "Group/SMK"
|
||||
case EAPOLKeyTypePairwise:
|
||||
return "Pairwise"
|
||||
default:
|
||||
return fmt.Sprintf("unknown key type %d", kt)
|
||||
}
|
||||
}
|
||||
|
||||
// EAPOLKey defines an EAPOL-Key frame for 802.1x authentication
|
||||
type EAPOLKey struct {
|
||||
BaseLayer
|
||||
KeyDescriptorType EAPOLKeyDescriptorType
|
||||
KeyDescriptorVersion EAPOLKeyDescriptorVersion
|
||||
KeyType EAPOLKeyType
|
||||
KeyIndex uint8
|
||||
Install bool
|
||||
KeyACK bool
|
||||
KeyMIC bool
|
||||
Secure bool
|
||||
MICError bool
|
||||
Request bool
|
||||
HasEncryptedKeyData bool
|
||||
SMKMessage bool
|
||||
KeyLength uint16
|
||||
ReplayCounter uint64
|
||||
Nonce []byte
|
||||
IV []byte
|
||||
RSC uint64
|
||||
ID uint64
|
||||
MIC []byte
|
||||
KeyDataLength uint16
|
||||
EncryptedKeyData []byte
|
||||
}
|
||||
|
||||
// LayerType returns LayerTypeEAPOLKey.
|
||||
func (ek *EAPOLKey) LayerType() gopacket.LayerType {
|
||||
return LayerTypeEAPOLKey
|
||||
}
|
||||
|
||||
// NextLayerType returns layers.LayerTypeDot11InformationElement if the key
|
||||
// data exists and is unencrypted, otherwise it does not expect a next layer.
|
||||
func (ek *EAPOLKey) NextLayerType() gopacket.LayerType {
|
||||
if !ek.HasEncryptedKeyData && ek.KeyDataLength > 0 {
|
||||
return LayerTypeDot11InformationElement
|
||||
}
|
||||
return gopacket.LayerTypePayload
|
||||
}
|
||||
|
||||
const eapolKeyFrameLen = 95
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (ek *EAPOLKey) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
if len(data) < eapolKeyFrameLen {
|
||||
df.SetTruncated()
|
||||
return fmt.Errorf("EAPOLKey length %v too short, %v required",
|
||||
len(data), eapolKeyFrameLen)
|
||||
}
|
||||
|
||||
ek.KeyDescriptorType = EAPOLKeyDescriptorType(data[0])
|
||||
|
||||
info := binary.BigEndian.Uint16(data[1:3])
|
||||
ek.KeyDescriptorVersion = EAPOLKeyDescriptorVersion(info & 0x0007)
|
||||
ek.KeyType = EAPOLKeyType((info & 0x0008) >> 3)
|
||||
ek.KeyIndex = uint8((info & 0x0030) >> 4)
|
||||
ek.Install = (info & 0x0040) != 0
|
||||
ek.KeyACK = (info & 0x0080) != 0
|
||||
ek.KeyMIC = (info & 0x0100) != 0
|
||||
ek.Secure = (info & 0x0200) != 0
|
||||
ek.MICError = (info & 0x0400) != 0
|
||||
ek.Request = (info & 0x0800) != 0
|
||||
ek.HasEncryptedKeyData = (info & 0x1000) != 0
|
||||
ek.SMKMessage = (info & 0x2000) != 0
|
||||
|
||||
ek.KeyLength = binary.BigEndian.Uint16(data[3:5])
|
||||
ek.ReplayCounter = binary.BigEndian.Uint64(data[5:13])
|
||||
|
||||
ek.Nonce = data[13:45]
|
||||
ek.IV = data[45:61]
|
||||
ek.RSC = binary.BigEndian.Uint64(data[61:69])
|
||||
ek.ID = binary.BigEndian.Uint64(data[69:77])
|
||||
ek.MIC = data[77:93]
|
||||
|
||||
ek.KeyDataLength = binary.BigEndian.Uint16(data[93:95])
|
||||
|
||||
totalLength := eapolKeyFrameLen + int(ek.KeyDataLength)
|
||||
if len(data) < totalLength {
|
||||
df.SetTruncated()
|
||||
return fmt.Errorf("EAPOLKey data length %d too short, %d required",
|
||||
len(data)-eapolKeyFrameLen, ek.KeyDataLength)
|
||||
}
|
||||
|
||||
if ek.HasEncryptedKeyData {
|
||||
ek.EncryptedKeyData = data[eapolKeyFrameLen:totalLength]
|
||||
ek.BaseLayer = BaseLayer{
|
||||
Contents: data[:totalLength],
|
||||
Payload: data[totalLength:],
|
||||
}
|
||||
} else {
|
||||
ek.BaseLayer = BaseLayer{
|
||||
Contents: data[:eapolKeyFrameLen],
|
||||
Payload: data[eapolKeyFrameLen:],
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SerializeTo writes the serialized form of this layer into the
|
||||
// SerializationBuffer, implementing gopacket.SerializableLayer.
|
||||
// See the docs for gopacket.SerializableLayer for more info.
|
||||
func (ek *EAPOLKey) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
buf, err := b.PrependBytes(eapolKeyFrameLen + len(ek.EncryptedKeyData))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf[0] = byte(ek.KeyDescriptorType)
|
||||
|
||||
var info uint16
|
||||
info |= uint16(ek.KeyDescriptorVersion)
|
||||
info |= uint16(ek.KeyType) << 3
|
||||
info |= uint16(ek.KeyIndex) << 4
|
||||
if ek.Install {
|
||||
info |= 0x0040
|
||||
}
|
||||
if ek.KeyACK {
|
||||
info |= 0x0080
|
||||
}
|
||||
if ek.KeyMIC {
|
||||
info |= 0x0100
|
||||
}
|
||||
if ek.Secure {
|
||||
info |= 0x0200
|
||||
}
|
||||
if ek.MICError {
|
||||
info |= 0x0400
|
||||
}
|
||||
if ek.Request {
|
||||
info |= 0x0800
|
||||
}
|
||||
if ek.HasEncryptedKeyData {
|
||||
info |= 0x1000
|
||||
}
|
||||
if ek.SMKMessage {
|
||||
info |= 0x2000
|
||||
}
|
||||
binary.BigEndian.PutUint16(buf[1:3], info)
|
||||
|
||||
binary.BigEndian.PutUint16(buf[3:5], ek.KeyLength)
|
||||
binary.BigEndian.PutUint64(buf[5:13], ek.ReplayCounter)
|
||||
|
||||
copy(buf[13:45], ek.Nonce)
|
||||
copy(buf[45:61], ek.IV)
|
||||
binary.BigEndian.PutUint64(buf[61:69], ek.RSC)
|
||||
binary.BigEndian.PutUint64(buf[69:77], ek.ID)
|
||||
copy(buf[77:93], ek.MIC)
|
||||
|
||||
binary.BigEndian.PutUint16(buf[93:95], ek.KeyDataLength)
|
||||
if len(ek.EncryptedKeyData) > 0 {
|
||||
copy(buf[95:95+len(ek.EncryptedKeyData)], ek.EncryptedKeyData)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func decodeEAPOLKey(data []byte, p gopacket.PacketBuilder) error {
|
||||
ek := &EAPOLKey{}
|
||||
return decodingLayerDecoder(ek, data, p)
|
||||
}
|
||||
|
|
176
vendor/github.com/google/gopacket/layers/enums.go
generated
vendored
176
vendor/github.com/google/gopacket/layers/enums.go
generated
vendored
|
@ -80,6 +80,7 @@ const (
|
|||
IPProtocolICMPv6 IPProtocol = 58
|
||||
IPProtocolNoNextHeader IPProtocol = 59
|
||||
IPProtocolIPv6Destination IPProtocol = 60
|
||||
IPProtocolOSPF IPProtocol = 89
|
||||
IPProtocolIPIP IPProtocol = 94
|
||||
IPProtocolEtherIP IPProtocol = 97
|
||||
IPProtocolVRRP IPProtocol = 112
|
||||
|
@ -218,12 +219,17 @@ func (d Dot11Type) MainType() Dot11Type {
|
|||
return d & dot11TypeMask
|
||||
}
|
||||
|
||||
func (d Dot11Type) QOS() bool {
|
||||
return d&dot11QOSMask == Dot11TypeDataQOSData
|
||||
}
|
||||
|
||||
const (
|
||||
Dot11TypeMgmt Dot11Type = 0x00
|
||||
Dot11TypeCtrl Dot11Type = 0x01
|
||||
Dot11TypeData Dot11Type = 0x02
|
||||
Dot11TypeReserved Dot11Type = 0x03
|
||||
dot11TypeMask = 0x03
|
||||
dot11QOSMask = 0x23
|
||||
|
||||
// The following are type/subtype conglomerations.
|
||||
|
||||
|
@ -271,107 +277,6 @@ const (
|
|||
Dot11TypeDataQOSCFAckPollNoData Dot11Type = 0x3e
|
||||
)
|
||||
|
||||
var (
|
||||
// Each of the following arrays contains mappings of how to handle enum
|
||||
// values for various enum types in gopacket/layers.
|
||||
//
|
||||
// So, EthernetTypeMetadata[2] contains information on how to handle EthernetType
|
||||
// 2, including which name to give it and which decoder to use to decode
|
||||
// packet data of that type. These arrays are filled by default with all of the
|
||||
// protocols gopacket/layers knows how to handle, but users of the library can
|
||||
// add new decoders or override existing ones. For example, if you write a better
|
||||
// TCP decoder, you can override IPProtocolMetadata[IPProtocolTCP].DecodeWith
|
||||
// with your new decoder, and all gopacket/layers decoding will use your new
|
||||
// decoder whenever they encounter that IPProtocol.
|
||||
EthernetTypeMetadata [65536]EnumMetadata
|
||||
IPProtocolMetadata [256]EnumMetadata
|
||||
SCTPChunkTypeMetadata [256]EnumMetadata
|
||||
PPPTypeMetadata [65536]EnumMetadata
|
||||
PPPoECodeMetadata [256]EnumMetadata
|
||||
LinkTypeMetadata [256]EnumMetadata
|
||||
FDDIFrameControlMetadata [256]EnumMetadata
|
||||
EAPOLTypeMetadata [256]EnumMetadata
|
||||
ProtocolFamilyMetadata [256]EnumMetadata
|
||||
Dot11TypeMetadata [256]EnumMetadata
|
||||
USBTypeMetadata [256]EnumMetadata
|
||||
)
|
||||
|
||||
func (a EthernetType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return EthernetTypeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
func (a EthernetType) String() string {
|
||||
return EthernetTypeMetadata[a].Name
|
||||
}
|
||||
func (a EthernetType) LayerType() gopacket.LayerType {
|
||||
return EthernetTypeMetadata[a].LayerType
|
||||
}
|
||||
func (a IPProtocol) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return IPProtocolMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
func (a IPProtocol) String() string {
|
||||
return IPProtocolMetadata[a].Name
|
||||
}
|
||||
func (a IPProtocol) LayerType() gopacket.LayerType {
|
||||
return IPProtocolMetadata[a].LayerType
|
||||
}
|
||||
func (a SCTPChunkType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return SCTPChunkTypeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
func (a SCTPChunkType) String() string {
|
||||
return SCTPChunkTypeMetadata[a].Name
|
||||
}
|
||||
func (a PPPType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return PPPTypeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
func (a PPPType) String() string {
|
||||
return PPPTypeMetadata[a].Name
|
||||
}
|
||||
func (a LinkType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return LinkTypeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
func (a LinkType) String() string {
|
||||
return LinkTypeMetadata[a].Name
|
||||
}
|
||||
func (a PPPoECode) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return PPPoECodeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
func (a PPPoECode) String() string {
|
||||
return PPPoECodeMetadata[a].Name
|
||||
}
|
||||
func (a FDDIFrameControl) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return FDDIFrameControlMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
func (a FDDIFrameControl) String() string {
|
||||
return FDDIFrameControlMetadata[a].Name
|
||||
}
|
||||
func (a EAPOLType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return EAPOLTypeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
func (a EAPOLType) String() string {
|
||||
return EAPOLTypeMetadata[a].Name
|
||||
}
|
||||
func (a EAPOLType) LayerType() gopacket.LayerType {
|
||||
return EAPOLTypeMetadata[a].LayerType
|
||||
}
|
||||
func (a ProtocolFamily) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return ProtocolFamilyMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
func (a ProtocolFamily) String() string {
|
||||
return ProtocolFamilyMetadata[a].Name
|
||||
}
|
||||
func (a ProtocolFamily) LayerType() gopacket.LayerType {
|
||||
return ProtocolFamilyMetadata[a].LayerType
|
||||
}
|
||||
func (a Dot11Type) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return Dot11TypeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
func (a Dot11Type) String() string {
|
||||
return Dot11TypeMetadata[a].Name
|
||||
}
|
||||
func (a Dot11Type) LayerType() gopacket.LayerType {
|
||||
return Dot11TypeMetadata[a].LayerType
|
||||
}
|
||||
|
||||
// Decode a raw v4 or v6 IP packet.
|
||||
func decodeIPv4or6(data []byte, p gopacket.PacketBuilder) error {
|
||||
version := data[0] >> 4
|
||||
|
@ -384,53 +289,22 @@ func decodeIPv4or6(data []byte, p gopacket.PacketBuilder) error {
|
|||
return fmt.Errorf("Invalid IP packet version %v", version)
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Here we link up all enumerations with their respective names and decoders.
|
||||
for i := 0; i < 65536; i++ {
|
||||
EthernetTypeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: errorFunc(fmt.Sprintf("Unable to decode ethernet type %d", i)),
|
||||
Name: fmt.Sprintf("UnknownEthernetType(%d)", i),
|
||||
}
|
||||
PPPTypeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: errorFunc(fmt.Sprintf("Unable to decode PPP type %d", i)),
|
||||
Name: fmt.Sprintf("UnknownPPPType(%d)", i),
|
||||
}
|
||||
}
|
||||
for i := 0; i < 256; i++ {
|
||||
IPProtocolMetadata[i] = EnumMetadata{
|
||||
DecodeWith: errorFunc(fmt.Sprintf("Unable to decode IP protocol %d", i)),
|
||||
Name: fmt.Sprintf("UnknownIPProtocol(%d)", i),
|
||||
}
|
||||
SCTPChunkTypeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: errorFunc(fmt.Sprintf("Unable to decode SCTP chunk type %d", i)),
|
||||
Name: fmt.Sprintf("UnknownSCTPChunkType(%d)", i),
|
||||
}
|
||||
PPPoECodeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: errorFunc(fmt.Sprintf("Unable to decode PPPoE code %d", i)),
|
||||
Name: fmt.Sprintf("UnknownPPPoECode(%d)", i),
|
||||
}
|
||||
LinkTypeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: errorFunc(fmt.Sprintf("Unable to decode link type %d", i)),
|
||||
Name: fmt.Sprintf("UnknownLinkType(%d)", i),
|
||||
}
|
||||
FDDIFrameControlMetadata[i] = EnumMetadata{
|
||||
DecodeWith: errorFunc(fmt.Sprintf("Unable to decode FDDI frame control %d", i)),
|
||||
Name: fmt.Sprintf("UnknownFDDIFrameControl(%d)", i),
|
||||
}
|
||||
EAPOLTypeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: errorFunc(fmt.Sprintf("Unable to decode EAPOL type %d", i)),
|
||||
Name: fmt.Sprintf("UnknownEAPOLType(%d)", i),
|
||||
}
|
||||
ProtocolFamilyMetadata[i] = EnumMetadata{
|
||||
DecodeWith: errorFunc(fmt.Sprintf("Unable to decode protocol family %d", i)),
|
||||
Name: fmt.Sprintf("UnknownProtocolFamily(%d)", i),
|
||||
}
|
||||
Dot11TypeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: errorFunc(fmt.Sprintf("Unable to decode Dot11 type %d", i)),
|
||||
Name: fmt.Sprintf("UnknownDot11Type(%d)", i),
|
||||
}
|
||||
}
|
||||
func initActualTypeData() {
|
||||
// Each of the XXXTypeMetadata arrays contains mappings of how to handle enum
|
||||
// values for various enum types in gopacket/layers.
|
||||
// These arrays are actually created by gen2.go and stored in
|
||||
// enums_generated.go.
|
||||
//
|
||||
// So, EthernetTypeMetadata[2] contains information on how to handle EthernetType
|
||||
// 2, including which name to give it and which decoder to use to decode
|
||||
// packet data of that type. These arrays are filled by default with all of the
|
||||
// protocols gopacket/layers knows how to handle, but users of the library can
|
||||
// add new decoders or override existing ones. For example, if you write a better
|
||||
// TCP decoder, you can override IPProtocolMetadata[IPProtocolTCP].DecodeWith
|
||||
// with your new decoder, and all gopacket/layers decoding will use your new
|
||||
// decoder whenever they encounter that IPProtocol.
|
||||
|
||||
// Here we link up all enumerations with their respective names and decoders.
|
||||
EthernetTypeMetadata[EthernetTypeLLC] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeLLC), Name: "LLC", LayerType: LayerTypeLLC}
|
||||
EthernetTypeMetadata[EthernetTypeIPv4] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeIPv4), Name: "IPv4", LayerType: LayerTypeIPv4}
|
||||
EthernetTypeMetadata[EthernetTypeIPv6] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeIPv6), Name: "IPv6", LayerType: LayerTypeIPv6}
|
||||
|
@ -463,6 +337,7 @@ func init() {
|
|||
IPProtocolMetadata[IPProtocolIPv6Routing] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeIPv6Routing), Name: "IPv6Routing", LayerType: LayerTypeIPv6Routing}
|
||||
IPProtocolMetadata[IPProtocolIPv6Fragment] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeIPv6Fragment), Name: "IPv6Fragment", LayerType: LayerTypeIPv6Fragment}
|
||||
IPProtocolMetadata[IPProtocolIPv6Destination] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeIPv6Destination), Name: "IPv6Destination", LayerType: LayerTypeIPv6Destination}
|
||||
IPProtocolMetadata[IPProtocolOSPF] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeOSPF), Name: "OSPF", LayerType: LayerTypeOSPF}
|
||||
IPProtocolMetadata[IPProtocolAH] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeIPSecAH), Name: "IPSecAH", LayerType: LayerTypeIPSecAH}
|
||||
IPProtocolMetadata[IPProtocolESP] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeIPSecESP), Name: "IPSecESP", LayerType: LayerTypeIPSecESP}
|
||||
IPProtocolMetadata[IPProtocolUDPLite] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeUDPLite), Name: "UDPLite", LayerType: LayerTypeUDPLite}
|
||||
|
@ -509,6 +384,7 @@ func init() {
|
|||
FDDIFrameControlMetadata[FDDIFrameControlLLC] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeLLC), Name: "LLC"}
|
||||
|
||||
EAPOLTypeMetadata[EAPOLTypeEAP] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeEAP), Name: "EAP", LayerType: LayerTypeEAP}
|
||||
EAPOLTypeMetadata[EAPOLTypeKey] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeEAPOLKey), Name: "EAPOLKey", LayerType: LayerTypeEAPOLKey}
|
||||
|
||||
ProtocolFamilyMetadata[ProtocolFamilyIPv4] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeIPv4), Name: "IPv4", LayerType: LayerTypeIPv4}
|
||||
ProtocolFamilyMetadata[ProtocolFamilyIPv6BSD] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeIPv6), Name: "IPv6", LayerType: LayerTypeIPv6}
|
||||
|
@ -556,7 +432,7 @@ func init() {
|
|||
Dot11TypeMetadata[Dot11TypeDataQOSCFPollNoData] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeDot11DataQOSCFPollNoData), Name: "DataQOSCFPollNoData", LayerType: LayerTypeDot11DataQOSCFPollNoData}
|
||||
Dot11TypeMetadata[Dot11TypeDataQOSCFAckPollNoData] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeDot11DataQOSCFAckPollNoData), Name: "DataQOSCFAckPollNoData", LayerType: LayerTypeDot11DataQOSCFAckPollNoData}
|
||||
|
||||
USBTypeMetadata[USBTransportTypeInterrupt] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeUSBInterrupt), Name: "Interrupt", LayerType: LayerTypeUSBInterrupt}
|
||||
USBTypeMetadata[USBTransportTypeControl] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeUSBControl), Name: "Control", LayerType: LayerTypeUSBControl}
|
||||
USBTypeMetadata[USBTransportTypeBulk] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeUSBBulk), Name: "Bulk", LayerType: LayerTypeUSBBulk}
|
||||
USBTransportTypeMetadata[USBTransportTypeInterrupt] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeUSBInterrupt), Name: "Interrupt", LayerType: LayerTypeUSBInterrupt}
|
||||
USBTransportTypeMetadata[USBTransportTypeControl] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeUSBControl), Name: "Control", LayerType: LayerTypeUSBControl}
|
||||
USBTransportTypeMetadata[USBTransportTypeBulk] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeUSBBulk), Name: "Bulk", LayerType: LayerTypeUSBBulk}
|
||||
}
|
||||
|
|
434
vendor/github.com/google/gopacket/layers/enums_generated.go
generated
vendored
Normal file
434
vendor/github.com/google/gopacket/layers/enums_generated.go
generated
vendored
Normal file
|
@ -0,0 +1,434 @@
|
|||
// Copyright 2012 Google, Inc. All rights reserved.
|
||||
|
||||
package layers
|
||||
|
||||
// Created by gen2.go, don't edit manually
|
||||
// Generated at 2017-10-23 10:20:24.458771856 -0600 MDT m=+0.001159033
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
)
|
||||
|
||||
func init() {
|
||||
initUnknownTypesForLinkType()
|
||||
initUnknownTypesForEthernetType()
|
||||
initUnknownTypesForPPPType()
|
||||
initUnknownTypesForIPProtocol()
|
||||
initUnknownTypesForSCTPChunkType()
|
||||
initUnknownTypesForPPPoECode()
|
||||
initUnknownTypesForFDDIFrameControl()
|
||||
initUnknownTypesForEAPOLType()
|
||||
initUnknownTypesForProtocolFamily()
|
||||
initUnknownTypesForDot11Type()
|
||||
initUnknownTypesForUSBTransportType()
|
||||
initActualTypeData()
|
||||
}
|
||||
|
||||
// Decoder calls LinkTypeMetadata.DecodeWith's decoder.
|
||||
func (a LinkType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return LinkTypeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
|
||||
// String returns LinkTypeMetadata.Name.
|
||||
func (a LinkType) String() string {
|
||||
return LinkTypeMetadata[a].Name
|
||||
}
|
||||
|
||||
// LayerType returns LinkTypeMetadata.LayerType.
|
||||
func (a LinkType) LayerType() gopacket.LayerType {
|
||||
return LinkTypeMetadata[a].LayerType
|
||||
}
|
||||
|
||||
type errorDecoderForLinkType int
|
||||
|
||||
func (a *errorDecoderForLinkType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return a
|
||||
}
|
||||
func (a *errorDecoderForLinkType) Error() string {
|
||||
return fmt.Sprintf("Unable to decode LinkType %d", int(*a))
|
||||
}
|
||||
|
||||
var errorDecodersForLinkType [256]errorDecoderForLinkType
|
||||
var LinkTypeMetadata [256]EnumMetadata
|
||||
|
||||
func initUnknownTypesForLinkType() {
|
||||
for i := 0; i < 256; i++ {
|
||||
errorDecodersForLinkType[i] = errorDecoderForLinkType(i)
|
||||
LinkTypeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: &errorDecodersForLinkType[i],
|
||||
Name: "UnknownLinkType",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decoder calls EthernetTypeMetadata.DecodeWith's decoder.
|
||||
func (a EthernetType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return EthernetTypeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
|
||||
// String returns EthernetTypeMetadata.Name.
|
||||
func (a EthernetType) String() string {
|
||||
return EthernetTypeMetadata[a].Name
|
||||
}
|
||||
|
||||
// LayerType returns EthernetTypeMetadata.LayerType.
|
||||
func (a EthernetType) LayerType() gopacket.LayerType {
|
||||
return EthernetTypeMetadata[a].LayerType
|
||||
}
|
||||
|
||||
type errorDecoderForEthernetType int
|
||||
|
||||
func (a *errorDecoderForEthernetType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return a
|
||||
}
|
||||
func (a *errorDecoderForEthernetType) Error() string {
|
||||
return fmt.Sprintf("Unable to decode EthernetType %d", int(*a))
|
||||
}
|
||||
|
||||
var errorDecodersForEthernetType [65536]errorDecoderForEthernetType
|
||||
var EthernetTypeMetadata [65536]EnumMetadata
|
||||
|
||||
func initUnknownTypesForEthernetType() {
|
||||
for i := 0; i < 65536; i++ {
|
||||
errorDecodersForEthernetType[i] = errorDecoderForEthernetType(i)
|
||||
EthernetTypeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: &errorDecodersForEthernetType[i],
|
||||
Name: "UnknownEthernetType",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decoder calls PPPTypeMetadata.DecodeWith's decoder.
|
||||
func (a PPPType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return PPPTypeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
|
||||
// String returns PPPTypeMetadata.Name.
|
||||
func (a PPPType) String() string {
|
||||
return PPPTypeMetadata[a].Name
|
||||
}
|
||||
|
||||
// LayerType returns PPPTypeMetadata.LayerType.
|
||||
func (a PPPType) LayerType() gopacket.LayerType {
|
||||
return PPPTypeMetadata[a].LayerType
|
||||
}
|
||||
|
||||
type errorDecoderForPPPType int
|
||||
|
||||
func (a *errorDecoderForPPPType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return a
|
||||
}
|
||||
func (a *errorDecoderForPPPType) Error() string {
|
||||
return fmt.Sprintf("Unable to decode PPPType %d", int(*a))
|
||||
}
|
||||
|
||||
var errorDecodersForPPPType [65536]errorDecoderForPPPType
|
||||
var PPPTypeMetadata [65536]EnumMetadata
|
||||
|
||||
func initUnknownTypesForPPPType() {
|
||||
for i := 0; i < 65536; i++ {
|
||||
errorDecodersForPPPType[i] = errorDecoderForPPPType(i)
|
||||
PPPTypeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: &errorDecodersForPPPType[i],
|
||||
Name: "UnknownPPPType",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decoder calls IPProtocolMetadata.DecodeWith's decoder.
|
||||
func (a IPProtocol) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return IPProtocolMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
|
||||
// String returns IPProtocolMetadata.Name.
|
||||
func (a IPProtocol) String() string {
|
||||
return IPProtocolMetadata[a].Name
|
||||
}
|
||||
|
||||
// LayerType returns IPProtocolMetadata.LayerType.
|
||||
func (a IPProtocol) LayerType() gopacket.LayerType {
|
||||
return IPProtocolMetadata[a].LayerType
|
||||
}
|
||||
|
||||
type errorDecoderForIPProtocol int
|
||||
|
||||
func (a *errorDecoderForIPProtocol) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return a
|
||||
}
|
||||
func (a *errorDecoderForIPProtocol) Error() string {
|
||||
return fmt.Sprintf("Unable to decode IPProtocol %d", int(*a))
|
||||
}
|
||||
|
||||
var errorDecodersForIPProtocol [256]errorDecoderForIPProtocol
|
||||
var IPProtocolMetadata [256]EnumMetadata
|
||||
|
||||
func initUnknownTypesForIPProtocol() {
|
||||
for i := 0; i < 256; i++ {
|
||||
errorDecodersForIPProtocol[i] = errorDecoderForIPProtocol(i)
|
||||
IPProtocolMetadata[i] = EnumMetadata{
|
||||
DecodeWith: &errorDecodersForIPProtocol[i],
|
||||
Name: "UnknownIPProtocol",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decoder calls SCTPChunkTypeMetadata.DecodeWith's decoder.
|
||||
func (a SCTPChunkType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return SCTPChunkTypeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
|
||||
// String returns SCTPChunkTypeMetadata.Name.
|
||||
func (a SCTPChunkType) String() string {
|
||||
return SCTPChunkTypeMetadata[a].Name
|
||||
}
|
||||
|
||||
// LayerType returns SCTPChunkTypeMetadata.LayerType.
|
||||
func (a SCTPChunkType) LayerType() gopacket.LayerType {
|
||||
return SCTPChunkTypeMetadata[a].LayerType
|
||||
}
|
||||
|
||||
type errorDecoderForSCTPChunkType int
|
||||
|
||||
func (a *errorDecoderForSCTPChunkType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return a
|
||||
}
|
||||
func (a *errorDecoderForSCTPChunkType) Error() string {
|
||||
return fmt.Sprintf("Unable to decode SCTPChunkType %d", int(*a))
|
||||
}
|
||||
|
||||
var errorDecodersForSCTPChunkType [256]errorDecoderForSCTPChunkType
|
||||
var SCTPChunkTypeMetadata [256]EnumMetadata
|
||||
|
||||
func initUnknownTypesForSCTPChunkType() {
|
||||
for i := 0; i < 256; i++ {
|
||||
errorDecodersForSCTPChunkType[i] = errorDecoderForSCTPChunkType(i)
|
||||
SCTPChunkTypeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: &errorDecodersForSCTPChunkType[i],
|
||||
Name: "UnknownSCTPChunkType",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decoder calls PPPoECodeMetadata.DecodeWith's decoder.
|
||||
func (a PPPoECode) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return PPPoECodeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
|
||||
// String returns PPPoECodeMetadata.Name.
|
||||
func (a PPPoECode) String() string {
|
||||
return PPPoECodeMetadata[a].Name
|
||||
}
|
||||
|
||||
// LayerType returns PPPoECodeMetadata.LayerType.
|
||||
func (a PPPoECode) LayerType() gopacket.LayerType {
|
||||
return PPPoECodeMetadata[a].LayerType
|
||||
}
|
||||
|
||||
type errorDecoderForPPPoECode int
|
||||
|
||||
func (a *errorDecoderForPPPoECode) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return a
|
||||
}
|
||||
func (a *errorDecoderForPPPoECode) Error() string {
|
||||
return fmt.Sprintf("Unable to decode PPPoECode %d", int(*a))
|
||||
}
|
||||
|
||||
var errorDecodersForPPPoECode [256]errorDecoderForPPPoECode
|
||||
var PPPoECodeMetadata [256]EnumMetadata
|
||||
|
||||
func initUnknownTypesForPPPoECode() {
|
||||
for i := 0; i < 256; i++ {
|
||||
errorDecodersForPPPoECode[i] = errorDecoderForPPPoECode(i)
|
||||
PPPoECodeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: &errorDecodersForPPPoECode[i],
|
||||
Name: "UnknownPPPoECode",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decoder calls FDDIFrameControlMetadata.DecodeWith's decoder.
|
||||
func (a FDDIFrameControl) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return FDDIFrameControlMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
|
||||
// String returns FDDIFrameControlMetadata.Name.
|
||||
func (a FDDIFrameControl) String() string {
|
||||
return FDDIFrameControlMetadata[a].Name
|
||||
}
|
||||
|
||||
// LayerType returns FDDIFrameControlMetadata.LayerType.
|
||||
func (a FDDIFrameControl) LayerType() gopacket.LayerType {
|
||||
return FDDIFrameControlMetadata[a].LayerType
|
||||
}
|
||||
|
||||
type errorDecoderForFDDIFrameControl int
|
||||
|
||||
func (a *errorDecoderForFDDIFrameControl) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return a
|
||||
}
|
||||
func (a *errorDecoderForFDDIFrameControl) Error() string {
|
||||
return fmt.Sprintf("Unable to decode FDDIFrameControl %d", int(*a))
|
||||
}
|
||||
|
||||
var errorDecodersForFDDIFrameControl [256]errorDecoderForFDDIFrameControl
|
||||
var FDDIFrameControlMetadata [256]EnumMetadata
|
||||
|
||||
func initUnknownTypesForFDDIFrameControl() {
|
||||
for i := 0; i < 256; i++ {
|
||||
errorDecodersForFDDIFrameControl[i] = errorDecoderForFDDIFrameControl(i)
|
||||
FDDIFrameControlMetadata[i] = EnumMetadata{
|
||||
DecodeWith: &errorDecodersForFDDIFrameControl[i],
|
||||
Name: "UnknownFDDIFrameControl",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decoder calls EAPOLTypeMetadata.DecodeWith's decoder.
|
||||
func (a EAPOLType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return EAPOLTypeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
|
||||
// String returns EAPOLTypeMetadata.Name.
|
||||
func (a EAPOLType) String() string {
|
||||
return EAPOLTypeMetadata[a].Name
|
||||
}
|
||||
|
||||
// LayerType returns EAPOLTypeMetadata.LayerType.
|
||||
func (a EAPOLType) LayerType() gopacket.LayerType {
|
||||
return EAPOLTypeMetadata[a].LayerType
|
||||
}
|
||||
|
||||
type errorDecoderForEAPOLType int
|
||||
|
||||
func (a *errorDecoderForEAPOLType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return a
|
||||
}
|
||||
func (a *errorDecoderForEAPOLType) Error() string {
|
||||
return fmt.Sprintf("Unable to decode EAPOLType %d", int(*a))
|
||||
}
|
||||
|
||||
var errorDecodersForEAPOLType [256]errorDecoderForEAPOLType
|
||||
var EAPOLTypeMetadata [256]EnumMetadata
|
||||
|
||||
func initUnknownTypesForEAPOLType() {
|
||||
for i := 0; i < 256; i++ {
|
||||
errorDecodersForEAPOLType[i] = errorDecoderForEAPOLType(i)
|
||||
EAPOLTypeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: &errorDecodersForEAPOLType[i],
|
||||
Name: "UnknownEAPOLType",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decoder calls ProtocolFamilyMetadata.DecodeWith's decoder.
|
||||
func (a ProtocolFamily) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return ProtocolFamilyMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
|
||||
// String returns ProtocolFamilyMetadata.Name.
|
||||
func (a ProtocolFamily) String() string {
|
||||
return ProtocolFamilyMetadata[a].Name
|
||||
}
|
||||
|
||||
// LayerType returns ProtocolFamilyMetadata.LayerType.
|
||||
func (a ProtocolFamily) LayerType() gopacket.LayerType {
|
||||
return ProtocolFamilyMetadata[a].LayerType
|
||||
}
|
||||
|
||||
type errorDecoderForProtocolFamily int
|
||||
|
||||
func (a *errorDecoderForProtocolFamily) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return a
|
||||
}
|
||||
func (a *errorDecoderForProtocolFamily) Error() string {
|
||||
return fmt.Sprintf("Unable to decode ProtocolFamily %d", int(*a))
|
||||
}
|
||||
|
||||
var errorDecodersForProtocolFamily [256]errorDecoderForProtocolFamily
|
||||
var ProtocolFamilyMetadata [256]EnumMetadata
|
||||
|
||||
func initUnknownTypesForProtocolFamily() {
|
||||
for i := 0; i < 256; i++ {
|
||||
errorDecodersForProtocolFamily[i] = errorDecoderForProtocolFamily(i)
|
||||
ProtocolFamilyMetadata[i] = EnumMetadata{
|
||||
DecodeWith: &errorDecodersForProtocolFamily[i],
|
||||
Name: "UnknownProtocolFamily",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decoder calls Dot11TypeMetadata.DecodeWith's decoder.
|
||||
func (a Dot11Type) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return Dot11TypeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
|
||||
// String returns Dot11TypeMetadata.Name.
|
||||
func (a Dot11Type) String() string {
|
||||
return Dot11TypeMetadata[a].Name
|
||||
}
|
||||
|
||||
// LayerType returns Dot11TypeMetadata.LayerType.
|
||||
func (a Dot11Type) LayerType() gopacket.LayerType {
|
||||
return Dot11TypeMetadata[a].LayerType
|
||||
}
|
||||
|
||||
type errorDecoderForDot11Type int
|
||||
|
||||
func (a *errorDecoderForDot11Type) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return a
|
||||
}
|
||||
func (a *errorDecoderForDot11Type) Error() string {
|
||||
return fmt.Sprintf("Unable to decode Dot11Type %d", int(*a))
|
||||
}
|
||||
|
||||
var errorDecodersForDot11Type [256]errorDecoderForDot11Type
|
||||
var Dot11TypeMetadata [256]EnumMetadata
|
||||
|
||||
func initUnknownTypesForDot11Type() {
|
||||
for i := 0; i < 256; i++ {
|
||||
errorDecodersForDot11Type[i] = errorDecoderForDot11Type(i)
|
||||
Dot11TypeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: &errorDecodersForDot11Type[i],
|
||||
Name: "UnknownDot11Type",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decoder calls USBTransportTypeMetadata.DecodeWith's decoder.
|
||||
func (a USBTransportType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return USBTransportTypeMetadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
|
||||
// String returns USBTransportTypeMetadata.Name.
|
||||
func (a USBTransportType) String() string {
|
||||
return USBTransportTypeMetadata[a].Name
|
||||
}
|
||||
|
||||
// LayerType returns USBTransportTypeMetadata.LayerType.
|
||||
func (a USBTransportType) LayerType() gopacket.LayerType {
|
||||
return USBTransportTypeMetadata[a].LayerType
|
||||
}
|
||||
|
||||
type errorDecoderForUSBTransportType int
|
||||
|
||||
func (a *errorDecoderForUSBTransportType) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return a
|
||||
}
|
||||
func (a *errorDecoderForUSBTransportType) Error() string {
|
||||
return fmt.Sprintf("Unable to decode USBTransportType %d", int(*a))
|
||||
}
|
||||
|
||||
var errorDecodersForUSBTransportType [256]errorDecoderForUSBTransportType
|
||||
var USBTransportTypeMetadata [256]EnumMetadata
|
||||
|
||||
func initUnknownTypesForUSBTransportType() {
|
||||
for i := 0; i < 256; i++ {
|
||||
errorDecodersForUSBTransportType[i] = errorDecoderForUSBTransportType(i)
|
||||
USBTransportTypeMetadata[i] = EnumMetadata{
|
||||
DecodeWith: &errorDecodersForUSBTransportType[i],
|
||||
Name: "UnknownUSBTransportType",
|
||||
}
|
||||
}
|
||||
}
|
1
vendor/github.com/google/gopacket/layers/ethernet.go
generated
vendored
1
vendor/github.com/google/gopacket/layers/ethernet.go
generated
vendored
|
@ -46,6 +46,7 @@ func (eth *Ethernet) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) er
|
|||
eth.SrcMAC = net.HardwareAddr(data[6:12])
|
||||
eth.EthernetType = EthernetType(binary.BigEndian.Uint16(data[12:14]))
|
||||
eth.BaseLayer = BaseLayer{data[:14], data[14:]}
|
||||
eth.Length = 0
|
||||
if eth.EthernetType < 0x0600 {
|
||||
eth.Length = uint16(eth.EthernetType)
|
||||
eth.EthernetType = EthernetTypeLLC
|
||||
|
|
104
vendor/github.com/google/gopacket/layers/gen2.go
generated
vendored
Normal file
104
vendor/github.com/google/gopacket/layers/gen2.go
generated
vendored
Normal file
|
@ -0,0 +1,104 @@
|
|||
// Copyright 2012 Google, Inc. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// This binary handles creating string constants and function templates for enums.
|
||||
//
|
||||
// go run gen.go | gofmt > enums_generated.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"text/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
const fmtString = `// Copyright 2012 Google, Inc. All rights reserved.
|
||||
|
||||
package layers
|
||||
|
||||
// Created by gen2.go, don't edit manually
|
||||
// Generated at %s
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
)
|
||||
|
||||
`
|
||||
|
||||
var funcsTmpl = template.Must(template.New("foo").Parse(`
|
||||
// Decoder calls {{.Name}}Metadata.DecodeWith's decoder.
|
||||
func (a {{.Name}}) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return {{.Name}}Metadata[a].DecodeWith.Decode(data, p)
|
||||
}
|
||||
// String returns {{.Name}}Metadata.Name.
|
||||
func (a {{.Name}}) String() string {
|
||||
return {{.Name}}Metadata[a].Name
|
||||
}
|
||||
// LayerType returns {{.Name}}Metadata.LayerType.
|
||||
func (a {{.Name}}) LayerType() gopacket.LayerType {
|
||||
return {{.Name}}Metadata[a].LayerType
|
||||
}
|
||||
|
||||
type errorDecoderFor{{.Name}} int
|
||||
func (a *errorDecoderFor{{.Name}}) Decode(data []byte, p gopacket.PacketBuilder) error {
|
||||
return a
|
||||
}
|
||||
func (a *errorDecoderFor{{.Name}}) Error() string {
|
||||
return fmt.Sprintf("Unable to decode {{.Name}} %d", int(*a))
|
||||
}
|
||||
|
||||
var errorDecodersFor{{.Name}} [{{.Num}}]errorDecoderFor{{.Name}}
|
||||
var {{.Name}}Metadata [{{.Num}}]EnumMetadata
|
||||
|
||||
func initUnknownTypesFor{{.Name}}() {
|
||||
for i := 0; i < {{.Num}}; i++ {
|
||||
errorDecodersFor{{.Name}}[i] = errorDecoderFor{{.Name}}(i)
|
||||
{{.Name}}Metadata[i] = EnumMetadata{
|
||||
DecodeWith: &errorDecodersFor{{.Name}}[i],
|
||||
Name: "Unknown{{.Name}}",
|
||||
}
|
||||
}
|
||||
}
|
||||
`))
|
||||
|
||||
func main() {
|
||||
fmt.Fprintf(os.Stderr, "Writing results to stdout\n")
|
||||
fmt.Printf(fmtString, time.Now())
|
||||
types := []struct {
|
||||
Name string
|
||||
Num int
|
||||
}{
|
||||
{"LinkType", 256},
|
||||
{"EthernetType", 65536},
|
||||
{"PPPType", 65536},
|
||||
{"IPProtocol", 256},
|
||||
{"SCTPChunkType", 256},
|
||||
{"PPPoECode", 256},
|
||||
{"FDDIFrameControl", 256},
|
||||
{"EAPOLType", 256},
|
||||
{"ProtocolFamily", 256},
|
||||
{"Dot11Type", 256},
|
||||
{"USBTransportType", 256},
|
||||
}
|
||||
|
||||
fmt.Println("func init() {")
|
||||
for _, t := range types {
|
||||
fmt.Printf("initUnknownTypesFor%s()\n", t.Name)
|
||||
}
|
||||
fmt.Println("initActualTypeData()")
|
||||
fmt.Println("}")
|
||||
for _, t := range types {
|
||||
if err := funcsTmpl.Execute(os.Stdout, t); err != nil {
|
||||
log.Fatalf("Failed to execute template %s: %v", t.Name, err)
|
||||
}
|
||||
}
|
||||
}
|
181
vendor/github.com/google/gopacket/layers/gtp.go
generated
vendored
Normal file
181
vendor/github.com/google/gopacket/layers/gtp.go
generated
vendored
Normal file
|
@ -0,0 +1,181 @@
|
|||
// Copyright 2017 Google, Inc. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree.
|
||||
//
|
||||
|
||||
package layers
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/google/gopacket"
|
||||
)
|
||||
|
||||
const gtpMinimumSizeInBytes int = 8
|
||||
|
||||
// GTPExtensionHeader is used to carry extra data and enable future extensions of the GTP without the need to use another version number.
|
||||
type GTPExtensionHeader struct {
|
||||
Type uint8
|
||||
Content []byte
|
||||
}
|
||||
|
||||
// GTPv1U protocol is used to exchange user data over GTP tunnels across the Sx interfaces.
|
||||
// Defined in https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1595
|
||||
type GTPv1U struct {
|
||||
BaseLayer
|
||||
Version uint8
|
||||
ProtocolType uint8
|
||||
Reserved uint8
|
||||
ExtensionHeaderFlag bool
|
||||
SequenceNumberFlag bool
|
||||
NPDUFlag bool
|
||||
MessageType uint8
|
||||
MessageLength uint16
|
||||
TEID uint32
|
||||
SequenceNumber uint16
|
||||
NPDU uint8
|
||||
GTPExtensionHeaders []GTPExtensionHeader
|
||||
}
|
||||
|
||||
// LayerType returns LayerTypeGTPV1U
|
||||
func (g *GTPv1U) LayerType() gopacket.LayerType { return LayerTypeGTPv1U }
|
||||
|
||||
// DecodeFromBytes analyses a byte slice and attempts to decode it as a GTPv1U packet
|
||||
func (g *GTPv1U) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
hLen := gtpMinimumSizeInBytes
|
||||
dLen := len(data)
|
||||
if dLen < hLen {
|
||||
return fmt.Errorf("GTP packet too small: %d bytes", dLen)
|
||||
}
|
||||
g.Version = (data[0] >> 5) & 0x07
|
||||
g.ProtocolType = (data[0] >> 4) & 0x01
|
||||
g.Reserved = (data[0] >> 3) & 0x01
|
||||
g.SequenceNumberFlag = ((data[0] >> 1) & 0x01) == 1
|
||||
g.NPDUFlag = (data[0] & 0x01) == 1
|
||||
g.ExtensionHeaderFlag = ((data[0] >> 2) & 0x01) == 1
|
||||
g.MessageType = data[1]
|
||||
g.MessageLength = binary.BigEndian.Uint16(data[2:4])
|
||||
pLen := 8 + g.MessageLength
|
||||
if uint16(dLen) < pLen {
|
||||
return fmt.Errorf("GTP packet too small: %d bytes", dLen)
|
||||
}
|
||||
// Field used to multiplex different connections in the same GTP tunnel.
|
||||
g.TEID = binary.BigEndian.Uint32(data[4:8])
|
||||
cIndex := uint16(hLen)
|
||||
if g.SequenceNumberFlag || g.NPDUFlag || g.ExtensionHeaderFlag {
|
||||
hLen += 4
|
||||
cIndex += 4
|
||||
if dLen < hLen {
|
||||
return fmt.Errorf("GTP packet too small: %d bytes", dLen)
|
||||
}
|
||||
if g.SequenceNumberFlag {
|
||||
g.SequenceNumber = binary.BigEndian.Uint16(data[8:10])
|
||||
}
|
||||
if g.NPDUFlag {
|
||||
g.NPDU = data[10]
|
||||
}
|
||||
if g.ExtensionHeaderFlag {
|
||||
extensionFlag := true
|
||||
for extensionFlag {
|
||||
extensionType := uint8(data[cIndex-1])
|
||||
extensionLength := uint(data[cIndex])
|
||||
if extensionLength == 0 {
|
||||
return fmt.Errorf("GTP packet with invalid extension header")
|
||||
}
|
||||
// extensionLength is in 4-octet units
|
||||
lIndex := cIndex + (uint16(extensionLength) * 4)
|
||||
if uint16(dLen) < lIndex {
|
||||
fmt.Println(dLen, lIndex)
|
||||
return fmt.Errorf("GTP packet with small extension header: %d bytes", dLen)
|
||||
}
|
||||
content := data[cIndex+1 : lIndex-1]
|
||||
eh := GTPExtensionHeader{Type: extensionType, Content: content}
|
||||
g.GTPExtensionHeaders = append(g.GTPExtensionHeaders, eh)
|
||||
cIndex = lIndex
|
||||
// Check if coming bytes are from an extension header
|
||||
extensionFlag = data[cIndex-1] != 0
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
g.BaseLayer = BaseLayer{Contents: data[:cIndex], Payload: data[cIndex:]}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// SerializeTo writes the serialized form of this layer into the
|
||||
// SerializationBuffer, implementing gopacket.SerializableLayer.
|
||||
// See the docs for gopacket.SerializableLayer for more info.
|
||||
func (g *GTPv1U) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
data, err := b.PrependBytes(gtpMinimumSizeInBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data[0] |= (g.Version << 5)
|
||||
data[0] |= (1 << 4)
|
||||
if len(g.GTPExtensionHeaders) > 0 {
|
||||
data[0] |= 0x04
|
||||
g.ExtensionHeaderFlag = true
|
||||
}
|
||||
if g.SequenceNumberFlag {
|
||||
data[0] |= 0x02
|
||||
}
|
||||
if g.NPDUFlag {
|
||||
data[0] |= 0x01
|
||||
}
|
||||
data[1] = g.MessageType
|
||||
binary.BigEndian.PutUint16(data[2:4], g.MessageLength)
|
||||
binary.BigEndian.PutUint32(data[4:8], g.TEID)
|
||||
if g.ExtensionHeaderFlag || g.SequenceNumberFlag || g.NPDUFlag {
|
||||
data, err := b.AppendBytes(4)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
binary.BigEndian.PutUint16(data[:2], g.SequenceNumber)
|
||||
data[2] = g.NPDU
|
||||
for _, eh := range g.GTPExtensionHeaders {
|
||||
data[len(data)-1] = eh.Type
|
||||
lContent := len(eh.Content)
|
||||
// extensionLength is in 4-octet units
|
||||
extensionLength := (lContent + 2) / 4
|
||||
// Get two extra byte for the next extension header type and length
|
||||
data, err = b.AppendBytes(lContent + 2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data[0] = byte(extensionLength)
|
||||
copy(data[1:lContent+1], eh.Content)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// CanDecode returns a set of layers that GTP objects can decode.
|
||||
func (g *GTPv1U) CanDecode() gopacket.LayerClass {
|
||||
return LayerTypeGTPv1U
|
||||
}
|
||||
|
||||
// NextLayerType specifies the next layer that GoPacket should attempt to
|
||||
func (g *GTPv1U) NextLayerType() gopacket.LayerType {
|
||||
version := uint8(g.LayerPayload()[0]) >> 4
|
||||
if version == 4 {
|
||||
return LayerTypeIPv4
|
||||
} else if version == 6 {
|
||||
return LayerTypeIPv6
|
||||
} else {
|
||||
return LayerTypePPP
|
||||
}
|
||||
}
|
||||
|
||||
func decodeGTPv1u(data []byte, p gopacket.PacketBuilder) error {
|
||||
gtp := >Pv1U{}
|
||||
err := gtp.DecodeFromBytes(data, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.AddLayer(gtp)
|
||||
return p.NextDecoder(gtp.NextLayerType())
|
||||
}
|
55
vendor/github.com/google/gopacket/layers/iana_ports.go
generated
vendored
55
vendor/github.com/google/gopacket/layers/iana_ports.go
generated
vendored
|
@ -3,7 +3,7 @@
|
|||
package layers
|
||||
|
||||
// Created by gen.go, don't edit manually
|
||||
// Generated at 2017-01-04 15:05:26.649794815 -0700 MST
|
||||
// Generated at 2017-10-23 09:57:28.214859163 -0600 MDT m=+1.011679290
|
||||
// Fetched from "http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml"
|
||||
|
||||
// TCPPortNames contains the port names for all TCP ports.
|
||||
|
@ -45,7 +45,6 @@ var tcpPortNames = map[TCPPort]string{
|
|||
44: "mpm-flags",
|
||||
45: "mpm",
|
||||
46: "mpm-snd",
|
||||
47: "ni-ftp",
|
||||
48: "auditd",
|
||||
49: "tacacs",
|
||||
50: "re-mail-ck",
|
||||
|
@ -55,7 +54,6 @@ var tcpPortNames = map[TCPPort]string{
|
|||
55: "isi-gl",
|
||||
56: "xns-auth",
|
||||
58: "xns-mail",
|
||||
61: "ni-mail",
|
||||
62: "acas",
|
||||
63: "whoispp",
|
||||
64: "covia",
|
||||
|
@ -673,6 +671,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
847: "dhcp-failover2",
|
||||
848: "gdoi",
|
||||
853: "domain-s",
|
||||
854: "dlep",
|
||||
860: "iscsi",
|
||||
861: "owamp-control",
|
||||
862: "twamp-control",
|
||||
|
@ -688,6 +687,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
911: "xact-backup",
|
||||
912: "apex-mesh",
|
||||
913: "apex-edge",
|
||||
953: "rndc",
|
||||
989: "ftps-data",
|
||||
990: "ftps",
|
||||
991: "nas",
|
||||
|
@ -2726,7 +2726,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
3068: "ls3bcast",
|
||||
3069: "ls3",
|
||||
3070: "mgxswitch",
|
||||
3071: "csd-mgmt-port",
|
||||
3071: "xplat-replicate",
|
||||
3072: "csd-monitor",
|
||||
3073: "vcrp",
|
||||
3074: "xbox",
|
||||
|
@ -3753,6 +3753,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
4117: "hillrserv",
|
||||
4118: "netscript",
|
||||
4119: "assuria-slm",
|
||||
4120: "minirem",
|
||||
4121: "e-builder",
|
||||
4122: "fprams",
|
||||
4123: "z-wave",
|
||||
|
@ -3823,6 +3824,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
4190: "sieve",
|
||||
4192: "azeti",
|
||||
4193: "pvxplusio",
|
||||
4197: "hctl",
|
||||
4199: "eims-admin",
|
||||
4300: "corelccam",
|
||||
4301: "d-data",
|
||||
|
@ -3831,7 +3833,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
4304: "owserver",
|
||||
4305: "batman",
|
||||
4306: "pinghgl",
|
||||
4307: "visicron-vs",
|
||||
4307: "trueconf",
|
||||
4308: "compx-lockview",
|
||||
4309: "dserver",
|
||||
4310: "mirrtex",
|
||||
|
@ -4028,6 +4030,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
4702: "netxms-sync",
|
||||
4703: "npqes-test",
|
||||
4704: "assuria-ins",
|
||||
4711: "trinity-dist",
|
||||
4725: "truckstar",
|
||||
4727: "fcis",
|
||||
4728: "capmux",
|
||||
|
@ -4105,6 +4108,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
4953: "dbsyncarbiter",
|
||||
4969: "ccss-qmm",
|
||||
4970: "ccss-qsm",
|
||||
4971: "burp",
|
||||
4984: "webyast",
|
||||
4985: "gerhcs",
|
||||
4986: "mrip",
|
||||
|
@ -4415,6 +4419,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
5638: "flcrs",
|
||||
5639: "ics",
|
||||
5646: "vfmobile",
|
||||
5666: "nrpe",
|
||||
5670: "filemq",
|
||||
5671: "amqps",
|
||||
5672: "amqp",
|
||||
|
@ -4432,6 +4437,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
5693: "rbsystem",
|
||||
5696: "kmip",
|
||||
5700: "supportassist",
|
||||
5705: "storageos",
|
||||
5713: "proshareaudio",
|
||||
5714: "prosharevideo",
|
||||
5715: "prosharedata",
|
||||
|
@ -4609,6 +4615,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
6446: "mysql-proxy",
|
||||
6455: "skip-cert-recv",
|
||||
6456: "skip-cert-send",
|
||||
6464: "ieee11073-20701",
|
||||
6471: "lvision-lm",
|
||||
6480: "sun-sr-http",
|
||||
6481: "servicetags",
|
||||
|
@ -4739,6 +4746,8 @@ var tcpPortNames = map[TCPPort]string{
|
|||
7013: "microtalon-dis",
|
||||
7014: "microtalon-com",
|
||||
7015: "talon-webserver",
|
||||
7016: "spg",
|
||||
7017: "grasp",
|
||||
7018: "fisa-svc",
|
||||
7019: "doceri-ctl",
|
||||
7020: "dpserve",
|
||||
|
@ -4776,6 +4785,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
7174: "clutild",
|
||||
7200: "fodms",
|
||||
7201: "dlip",
|
||||
7202: "pon-ictp",
|
||||
7215: "PS-Server",
|
||||
7216: "PS-Capture-Pro",
|
||||
7227: "ramp",
|
||||
|
@ -4926,6 +4936,8 @@ var tcpPortNames = map[TCPPort]string{
|
|||
8002: "teradataordbms",
|
||||
8003: "mcreport",
|
||||
8005: "mxi",
|
||||
8006: "wpl-analytics",
|
||||
8007: "warppipe",
|
||||
8008: "http-alt",
|
||||
8019: "qbdb",
|
||||
8020: "intu-ec-svcdisc",
|
||||
|
@ -4937,6 +4949,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
8033: "mindprint",
|
||||
8034: "vantronix-mgmt",
|
||||
8040: "ampify",
|
||||
8041: "enguity-xccetp",
|
||||
8042: "fs-agent",
|
||||
8043: "fs-server",
|
||||
8044: "fs-mgmt",
|
||||
|
@ -4951,7 +4964,9 @@ var tcpPortNames = map[TCPPort]string{
|
|||
8059: "senomix08",
|
||||
8066: "toad-bi-appsrvr",
|
||||
8067: "infi-async",
|
||||
8070: "ucs-isc",
|
||||
8074: "gadugadu",
|
||||
8077: "mles",
|
||||
8080: "http-alt",
|
||||
8081: "sunproxyadmin",
|
||||
8082: "us-cli",
|
||||
|
@ -4959,6 +4974,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
8086: "d-s-n",
|
||||
8087: "simplifymedia",
|
||||
8088: "radan-http",
|
||||
8090: "opsmessaging",
|
||||
8091: "jamlink",
|
||||
8097: "sac",
|
||||
8100: "xprint-server",
|
||||
|
@ -5000,6 +5016,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
8208: "lm-webwatcher",
|
||||
8230: "rexecj",
|
||||
8243: "synapse-nhttps",
|
||||
8270: "robot-remote",
|
||||
8276: "pando-sec",
|
||||
8280: "synapse-nhttp",
|
||||
8282: "libelle",
|
||||
|
@ -5028,6 +5045,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
8415: "dlpx-sp",
|
||||
8416: "espeech",
|
||||
8417: "espeech-rtp",
|
||||
8423: "aritts",
|
||||
8442: "cybro-a-bus",
|
||||
8443: "pcsync-https",
|
||||
8444: "pcsync-http",
|
||||
|
@ -5258,6 +5276,8 @@ var tcpPortNames = map[TCPPort]string{
|
|||
9955: "alljoyn-stm",
|
||||
9966: "odnsp",
|
||||
9978: "xybrid-rt",
|
||||
9979: "visweather",
|
||||
9981: "pumpkindb",
|
||||
9987: "dsm-scm-target",
|
||||
9988: "nsesrvr",
|
||||
9990: "osm-appsrvr",
|
||||
|
@ -5281,6 +5301,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
10008: "octopus",
|
||||
10009: "swdtp-sv",
|
||||
10010: "rxapi",
|
||||
10020: "abb-hw",
|
||||
10050: "zabbix-agent",
|
||||
10051: "zabbix-trapper",
|
||||
10055: "qptlmd",
|
||||
|
@ -5535,6 +5556,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
20999: "athand-mmp",
|
||||
21000: "irtrans",
|
||||
21010: "notezilla-lan",
|
||||
21221: "aigairserver",
|
||||
21553: "rdm-tfs",
|
||||
21554: "dfserver",
|
||||
21590: "vofr-gateway",
|
||||
|
@ -5648,6 +5670,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
30003: "amicon-fpsu-ra",
|
||||
30100: "rwp",
|
||||
30260: "kingdomsonline",
|
||||
30400: "gs-realtime",
|
||||
30999: "ovobs",
|
||||
31016: "ka-sddp",
|
||||
31020: "autotrac-acp",
|
||||
|
@ -5789,6 +5812,7 @@ var tcpPortNames = map[TCPPort]string{
|
|||
48619: "iqobject",
|
||||
48653: "robotraconteur",
|
||||
49000: "matahari",
|
||||
49001: "nusrp",
|
||||
}
|
||||
var udpPortNames = map[UDPPort]string{
|
||||
1: "tcpmux",
|
||||
|
@ -5820,7 +5844,6 @@ var udpPortNames = map[UDPPort]string{
|
|||
44: "mpm-flags",
|
||||
45: "mpm",
|
||||
46: "mpm-snd",
|
||||
47: "ni-ftp",
|
||||
48: "auditd",
|
||||
49: "tacacs",
|
||||
50: "re-mail-ck",
|
||||
|
@ -5830,7 +5853,6 @@ var udpPortNames = map[UDPPort]string{
|
|||
55: "isi-gl",
|
||||
56: "xns-auth",
|
||||
58: "xns-mail",
|
||||
61: "ni-mail",
|
||||
62: "acas",
|
||||
63: "whoispp",
|
||||
64: "covia",
|
||||
|
@ -6447,6 +6469,7 @@ var udpPortNames = map[UDPPort]string{
|
|||
847: "dhcp-failover2",
|
||||
848: "gdoi",
|
||||
853: "domain-s",
|
||||
854: "dlep",
|
||||
860: "iscsi",
|
||||
861: "owamp-control",
|
||||
862: "twamp-control",
|
||||
|
@ -8483,7 +8506,6 @@ var udpPortNames = map[UDPPort]string{
|
|||
3068: "ls3bcast",
|
||||
3069: "ls3",
|
||||
3070: "mgxswitch",
|
||||
3071: "csd-mgmt-port",
|
||||
3072: "csd-monitor",
|
||||
3073: "vcrp",
|
||||
3074: "xbox",
|
||||
|
@ -9562,6 +9584,7 @@ var udpPortNames = map[UDPPort]string{
|
|||
4188: "vatata",
|
||||
4191: "dsmipv6",
|
||||
4192: "azeti-bd",
|
||||
4197: "hctl",
|
||||
4199: "eims-admin",
|
||||
4300: "corelccam",
|
||||
4301: "d-data",
|
||||
|
@ -9570,7 +9593,7 @@ var udpPortNames = map[UDPPort]string{
|
|||
4304: "owserver",
|
||||
4305: "batman",
|
||||
4306: "pinghgl",
|
||||
4307: "visicron-vs",
|
||||
4307: "trueconf",
|
||||
4308: "compx-lockview",
|
||||
4309: "dserver",
|
||||
4310: "mirrtex",
|
||||
|
@ -9732,6 +9755,7 @@ var udpPortNames = map[UDPPort]string{
|
|||
4700: "netxms-agent",
|
||||
4701: "netxms-mgmt",
|
||||
4702: "netxms-sync",
|
||||
4711: "trinity-dist",
|
||||
4725: "truckstar",
|
||||
4726: "a26-fap-fgw",
|
||||
4727: "fcis-disc",
|
||||
|
@ -10239,6 +10263,7 @@ var udpPortNames = map[UDPPort]string{
|
|||
6446: "mysql-proxy",
|
||||
6455: "skip-cert-recv",
|
||||
6456: "skip-cert-send",
|
||||
6464: "ieee11073-20701",
|
||||
6471: "lvision-lm",
|
||||
6480: "sun-sr-http",
|
||||
6481: "servicetags",
|
||||
|
@ -10355,6 +10380,8 @@ var udpPortNames = map[UDPPort]string{
|
|||
7013: "microtalon-dis",
|
||||
7014: "microtalon-com",
|
||||
7015: "talon-webserver",
|
||||
7016: "spg",
|
||||
7017: "grasp",
|
||||
7019: "doceri-view",
|
||||
7020: "dpserve",
|
||||
7021: "dpserveadmin",
|
||||
|
@ -10513,6 +10540,8 @@ var udpPortNames = map[UDPPort]string{
|
|||
8002: "teradataordbms",
|
||||
8003: "mcreport",
|
||||
8005: "mxi",
|
||||
8006: "wpl-disc",
|
||||
8007: "warppipe",
|
||||
8008: "http-alt",
|
||||
8019: "qbdb",
|
||||
8020: "intu-ec-svcdisc",
|
||||
|
@ -10524,6 +10553,7 @@ var udpPortNames = map[UDPPort]string{
|
|||
8033: "mindprint",
|
||||
8034: "vantronix-mgmt",
|
||||
8040: "ampify",
|
||||
8041: "enguity-xccetp",
|
||||
8052: "senomix01",
|
||||
8053: "senomix02",
|
||||
8054: "senomix03",
|
||||
|
@ -10634,6 +10664,7 @@ var udpPortNames = map[UDPPort]string{
|
|||
8793: "acd-pm",
|
||||
8800: "sunwebadmin",
|
||||
8804: "truecm",
|
||||
8805: "pfcp",
|
||||
8808: "ssports-bcast",
|
||||
8873: "dxspider",
|
||||
8880: "cddbp-alt",
|
||||
|
@ -11241,6 +11272,7 @@ var udpPortNames = map[UDPPort]string{
|
|||
48556: "com-bardac-dw",
|
||||
48619: "iqobject",
|
||||
48653: "robotraconteur",
|
||||
49001: "nusdp-disc",
|
||||
}
|
||||
var sctpPortNames = map[SCTPPort]string{
|
||||
9: "discard",
|
||||
|
@ -11267,6 +11299,7 @@ var sctpPortNames = map[SCTPPort]string{
|
|||
3868: "diameter",
|
||||
4333: "ahsp",
|
||||
4502: "a25-fap-fgw",
|
||||
4711: "trinity-dist",
|
||||
4739: "ipfix",
|
||||
4740: "ipfixs",
|
||||
5060: "sip",
|
||||
|
@ -11287,6 +11320,7 @@ var sctpPortNames = map[SCTPPort]string{
|
|||
6706: "frc-lp",
|
||||
6970: "conductor-mpx",
|
||||
7626: "simco",
|
||||
7701: "nfapi",
|
||||
7728: "osvr",
|
||||
8471: "pim-port",
|
||||
9082: "lcs-ap",
|
||||
|
@ -11311,4 +11345,7 @@ var sctpPortNames = map[SCTPPort]string{
|
|||
36443: "m2ap",
|
||||
36444: "m3ap",
|
||||
36462: "xw-control",
|
||||
38412: "ng-control",
|
||||
38422: "xn-control",
|
||||
38472: "f1-control",
|
||||
}
|
||||
|
|
40
vendor/github.com/google/gopacket/layers/icmp6.go
generated
vendored
40
vendor/github.com/google/gopacket/layers/icmp6.go
generated
vendored
|
@ -165,8 +165,10 @@ func CreateICMPv6TypeCode(typ uint8, code uint8) ICMPv6TypeCode {
|
|||
// ICMPv6 is the layer for IPv6 ICMP packet data
|
||||
type ICMPv6 struct {
|
||||
BaseLayer
|
||||
TypeCode ICMPv6TypeCode
|
||||
Checksum uint16
|
||||
TypeCode ICMPv6TypeCode
|
||||
Checksum uint16
|
||||
// TypeBytes is deprecated and always nil. See the different ICMPv6 message types
|
||||
// instead (e.g. ICMPv6TypeRouterSolicitation).
|
||||
TypeBytes []byte
|
||||
tcpipchecksum
|
||||
}
|
||||
|
@ -176,14 +178,13 @@ func (i *ICMPv6) LayerType() gopacket.LayerType { return LayerTypeICMPv6 }
|
|||
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (i *ICMPv6) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
if len(data) < 8 {
|
||||
if len(data) < 4 {
|
||||
df.SetTruncated()
|
||||
return errors.New("ICMP layer less then 8 bytes for ICMPv6 packet")
|
||||
return errors.New("ICMP layer less then 4 bytes for ICMPv6 packet")
|
||||
}
|
||||
i.TypeCode = CreateICMPv6TypeCode(data[0], data[1])
|
||||
i.Checksum = binary.BigEndian.Uint16(data[2:4])
|
||||
i.TypeBytes = data[4:8]
|
||||
i.BaseLayer = BaseLayer{data[:8], data[8:]}
|
||||
i.BaseLayer = BaseLayer{data[:4], data[4:]}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -191,17 +192,12 @@ func (i *ICMPv6) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
|
|||
// SerializationBuffer, implementing gopacket.SerializableLayer.
|
||||
// See the docs for gopacket.SerializableLayer for more info.
|
||||
func (i *ICMPv6) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
if i.TypeBytes == nil {
|
||||
i.TypeBytes = lotsOfZeros[:4]
|
||||
} else if len(i.TypeBytes) != 4 {
|
||||
return fmt.Errorf("invalid type bytes for ICMPv6 packet: %v", i.TypeBytes)
|
||||
}
|
||||
bytes, err := b.PrependBytes(8)
|
||||
bytes, err := b.PrependBytes(4)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i.TypeCode.SerializeTo(bytes)
|
||||
copy(bytes[4:8], i.TypeBytes)
|
||||
|
||||
if opts.ComputeChecksums {
|
||||
bytes[2] = 0
|
||||
bytes[3] = 0
|
||||
|
@ -212,6 +208,7 @@ func (i *ICMPv6) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.Serialize
|
|||
i.Checksum = csum
|
||||
}
|
||||
binary.BigEndian.PutUint16(bytes[2:], i.Checksum)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -222,6 +219,23 @@ func (i *ICMPv6) CanDecode() gopacket.LayerClass {
|
|||
|
||||
// NextLayerType returns the layer type contained by this DecodingLayer.
|
||||
func (i *ICMPv6) NextLayerType() gopacket.LayerType {
|
||||
switch i.TypeCode.Type() {
|
||||
case ICMPv6TypeEchoRequest:
|
||||
return LayerTypeICMPv6Echo
|
||||
case ICMPv6TypeEchoReply:
|
||||
return LayerTypeICMPv6Echo
|
||||
case ICMPv6TypeRouterSolicitation:
|
||||
return LayerTypeICMPv6RouterSolicitation
|
||||
case ICMPv6TypeRouterAdvertisement:
|
||||
return LayerTypeICMPv6RouterAdvertisement
|
||||
case ICMPv6TypeNeighborSolicitation:
|
||||
return LayerTypeICMPv6NeighborSolicitation
|
||||
case ICMPv6TypeNeighborAdvertisement:
|
||||
return LayerTypeICMPv6NeighborAdvertisement
|
||||
case ICMPv6TypeRedirect:
|
||||
return LayerTypeICMPv6Redirect
|
||||
}
|
||||
|
||||
return gopacket.LayerTypePayload
|
||||
}
|
||||
|
||||
|
|
573
vendor/github.com/google/gopacket/layers/icmp6msg.go
generated
vendored
Normal file
573
vendor/github.com/google/gopacket/layers/icmp6msg.go
generated
vendored
Normal file
|
@ -0,0 +1,573 @@
|
|||
// Copyright 2012 Google, Inc. All rights reserved.
|
||||
// Copyright 2009-2011 Andreas Krennmair. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree.
|
||||
|
||||
package layers
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
)
|
||||
|
||||
// Based on RFC 4861
|
||||
|
||||
// ICMPv6Opt indicate how to decode the data associated with each ICMPv6Option.
|
||||
type ICMPv6Opt uint8
|
||||
|
||||
const (
|
||||
_ ICMPv6Opt = iota
|
||||
|
||||
// ICMPv6OptSourceAddress contains the link-layer address of the sender of
|
||||
// the packet. It is used in the Neighbor Solicitation, Router
|
||||
// Solicitation, and Router Advertisement packets. Must be ignored for other
|
||||
// Neighbor discovery messages.
|
||||
ICMPv6OptSourceAddress
|
||||
|
||||
// ICMPv6OptTargetAddress contains the link-layer address of the target. It
|
||||
// is used in Neighbor Advertisement and Redirect packets. Must be ignored
|
||||
// for other Neighbor discovery messages.
|
||||
ICMPv6OptTargetAddress
|
||||
|
||||
// ICMPv6OptPrefixInfo provides hosts with on-link prefixes and prefixes
|
||||
// for Address Autoconfiguration. The Prefix Information option appears in
|
||||
// Router Advertisement packets and MUST be silently ignored for other
|
||||
// messages.
|
||||
ICMPv6OptPrefixInfo
|
||||
|
||||
// ICMPv6OptRedirectedHeader is used in Redirect messages and contains all
|
||||
// or part of the packet that is being redirected.
|
||||
ICMPv6OptRedirectedHeader
|
||||
|
||||
// ICMPv6OptMTU is used in Router Advertisement messages to ensure that all
|
||||
// nodes on a link use the same MTU value in those cases where the link MTU
|
||||
// is not well known. This option MUST be silently ignored for other
|
||||
// Neighbor Discovery messages.
|
||||
ICMPv6OptMTU
|
||||
)
|
||||
|
||||
// ICMPv6Echo represents the structure of a ping.
|
||||
type ICMPv6Echo struct {
|
||||
BaseLayer
|
||||
Identifier uint16
|
||||
SeqNumber uint16
|
||||
}
|
||||
|
||||
// ICMPv6RouterSolicitation is sent by hosts to find routers.
|
||||
type ICMPv6RouterSolicitation struct {
|
||||
BaseLayer
|
||||
Options ICMPv6Options
|
||||
}
|
||||
|
||||
// ICMPv6RouterAdvertisement is sent by routers in response to Solicitation.
|
||||
type ICMPv6RouterAdvertisement struct {
|
||||
BaseLayer
|
||||
HopLimit uint8
|
||||
Flags uint8
|
||||
RouterLifetime uint16
|
||||
ReachableTime uint32
|
||||
RetransTimer uint32
|
||||
Options ICMPv6Options
|
||||
}
|
||||
|
||||
// ICMPv6NeighborSolicitation is sent to request the link-layer address of a
|
||||
// target node.
|
||||
type ICMPv6NeighborSolicitation struct {
|
||||
BaseLayer
|
||||
TargetAddress net.IP
|
||||
Options ICMPv6Options
|
||||
}
|
||||
|
||||
// ICMPv6NeighborAdvertisement is sent by nodes in response to Solicitation.
|
||||
type ICMPv6NeighborAdvertisement struct {
|
||||
BaseLayer
|
||||
Flags uint8
|
||||
TargetAddress net.IP
|
||||
Options ICMPv6Options
|
||||
}
|
||||
|
||||
// ICMPv6Redirect is sent by routers to inform hosts of a better first-hop node
|
||||
// on the path to a destination.
|
||||
type ICMPv6Redirect struct {
|
||||
BaseLayer
|
||||
TargetAddress net.IP
|
||||
DestinationAddress net.IP
|
||||
Options ICMPv6Options
|
||||
}
|
||||
|
||||
// ICMPv6Option contains the type and data for a single option.
|
||||
type ICMPv6Option struct {
|
||||
Type ICMPv6Opt
|
||||
Data []byte
|
||||
}
|
||||
|
||||
// ICMPv6Options is a slice of ICMPv6Option.
|
||||
type ICMPv6Options []ICMPv6Option
|
||||
|
||||
func (i ICMPv6Opt) String() string {
|
||||
switch i {
|
||||
case ICMPv6OptSourceAddress:
|
||||
return "SourceAddress"
|
||||
case ICMPv6OptTargetAddress:
|
||||
return "TargetAddress"
|
||||
case ICMPv6OptPrefixInfo:
|
||||
return "PrefixInfo"
|
||||
case ICMPv6OptRedirectedHeader:
|
||||
return "RedirectedHeader"
|
||||
case ICMPv6OptMTU:
|
||||
return "MTU"
|
||||
default:
|
||||
return fmt.Sprintf("Unknown(%d)", i)
|
||||
}
|
||||
}
|
||||
|
||||
// LayerType returns LayerTypeICMPv6Echo.
|
||||
func (i *ICMPv6Echo) LayerType() gopacket.LayerType {
|
||||
return LayerTypeICMPv6Echo
|
||||
}
|
||||
|
||||
// NextLayerType returns the layer type contained by this DecodingLayer.
|
||||
func (i *ICMPv6Echo) NextLayerType() gopacket.LayerType {
|
||||
return gopacket.LayerTypePayload
|
||||
}
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (i *ICMPv6Echo) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
if len(data) < 4 {
|
||||
df.SetTruncated()
|
||||
return errors.New("ICMP layer less then 4 bytes for ICMPv6 Echo")
|
||||
}
|
||||
i.Identifier = binary.BigEndian.Uint16(data[0:2])
|
||||
i.SeqNumber = binary.BigEndian.Uint16(data[2:4])
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SerializeTo writes the serialized form of this layer into the
|
||||
// SerializationBuffer, implementing gopacket.SerializableLayer.
|
||||
// See the docs for gopacket.SerializableLayer for more info.
|
||||
func (i *ICMPv6Echo) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
buf, err := b.PrependBytes(4)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
binary.BigEndian.PutUint16(buf, i.Identifier)
|
||||
binary.BigEndian.PutUint16(buf[2:], i.SeqNumber)
|
||||
return nil
|
||||
}
|
||||
|
||||
// LayerType returns LayerTypeICMPv6.
|
||||
func (i *ICMPv6RouterSolicitation) LayerType() gopacket.LayerType {
|
||||
return LayerTypeICMPv6RouterSolicitation
|
||||
}
|
||||
|
||||
// NextLayerType returns the layer type contained by this DecodingLayer.
|
||||
func (i *ICMPv6RouterSolicitation) NextLayerType() gopacket.LayerType {
|
||||
return gopacket.LayerTypePayload
|
||||
}
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (i *ICMPv6RouterSolicitation) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
// first 4 bytes are reserved followed by options
|
||||
if len(data) < 4 {
|
||||
df.SetTruncated()
|
||||
return errors.New("ICMP layer less then 4 bytes for ICMPv6 router solicitation")
|
||||
}
|
||||
|
||||
// truncate old options
|
||||
i.Options = i.Options[:0]
|
||||
|
||||
return i.Options.DecodeFromBytes(data[4:], df)
|
||||
}
|
||||
|
||||
// SerializeTo writes the serialized form of this layer into the
|
||||
// SerializationBuffer, implementing gopacket.SerializableLayer.
|
||||
// See the docs for gopacket.SerializableLayer for more info.
|
||||
func (i *ICMPv6RouterSolicitation) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
if err := i.Options.SerializeTo(b, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf, err := b.PrependBytes(4)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
copy(buf, lotsOfZeros[:4])
|
||||
return nil
|
||||
}
|
||||
|
||||
// CanDecode returns the set of layer types that this DecodingLayer can decode.
|
||||
func (i *ICMPv6RouterSolicitation) CanDecode() gopacket.LayerClass {
|
||||
return LayerTypeICMPv6RouterSolicitation
|
||||
}
|
||||
|
||||
// LayerType returns LayerTypeICMPv6RouterAdvertisement.
|
||||
func (i *ICMPv6RouterAdvertisement) LayerType() gopacket.LayerType {
|
||||
return LayerTypeICMPv6RouterAdvertisement
|
||||
}
|
||||
|
||||
// NextLayerType returns the layer type contained by this DecodingLayer.
|
||||
func (i *ICMPv6RouterAdvertisement) NextLayerType() gopacket.LayerType {
|
||||
return gopacket.LayerTypePayload
|
||||
}
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (i *ICMPv6RouterAdvertisement) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
if len(data) < 12 {
|
||||
df.SetTruncated()
|
||||
return errors.New("ICMP layer less then 12 bytes for ICMPv6 router advertisement")
|
||||
}
|
||||
|
||||
i.HopLimit = uint8(data[0])
|
||||
// M, O bit followed by 6 reserved bits
|
||||
i.Flags = uint8(data[1])
|
||||
i.RouterLifetime = binary.BigEndian.Uint16(data[2:4])
|
||||
i.ReachableTime = binary.BigEndian.Uint32(data[4:8])
|
||||
i.RetransTimer = binary.BigEndian.Uint32(data[8:12])
|
||||
i.BaseLayer = BaseLayer{data, nil} // assume no payload
|
||||
|
||||
// truncate old options
|
||||
i.Options = i.Options[:0]
|
||||
|
||||
return i.Options.DecodeFromBytes(data[12:], df)
|
||||
}
|
||||
|
||||
// SerializeTo writes the serialized form of this layer into the
|
||||
// SerializationBuffer, implementing gopacket.SerializableLayer.
|
||||
// See the docs for gopacket.SerializableLayer for more info.
|
||||
func (i *ICMPv6RouterAdvertisement) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
if err := i.Options.SerializeTo(b, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf, err := b.PrependBytes(12)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf[0] = byte(i.HopLimit)
|
||||
buf[1] = byte(i.Flags)
|
||||
binary.BigEndian.PutUint16(buf[2:], i.RouterLifetime)
|
||||
binary.BigEndian.PutUint32(buf[4:], i.ReachableTime)
|
||||
binary.BigEndian.PutUint32(buf[8:], i.RetransTimer)
|
||||
return nil
|
||||
}
|
||||
|
||||
// CanDecode returns the set of layer types that this DecodingLayer can decode.
|
||||
func (i *ICMPv6RouterAdvertisement) CanDecode() gopacket.LayerClass {
|
||||
return LayerTypeICMPv6RouterAdvertisement
|
||||
}
|
||||
|
||||
// ManagedAddressConfig is true when addresses are available via DHCPv6. If
|
||||
// set, the OtherConfig flag is redundant.
|
||||
func (i *ICMPv6RouterAdvertisement) ManagedAddressConfig() bool {
|
||||
return i.Flags&0x80 != 0
|
||||
}
|
||||
|
||||
// OtherConfig is true when there is other configuration information available
|
||||
// via DHCPv6. For example, DNS-related information.
|
||||
func (i *ICMPv6RouterAdvertisement) OtherConfig() bool {
|
||||
return i.Flags&0x40 != 0
|
||||
}
|
||||
|
||||
// LayerType returns LayerTypeICMPv6NeighborSolicitation.
|
||||
func (i *ICMPv6NeighborSolicitation) LayerType() gopacket.LayerType {
|
||||
return LayerTypeICMPv6NeighborSolicitation
|
||||
}
|
||||
|
||||
// NextLayerType returns the layer type contained by this DecodingLayer.
|
||||
func (i *ICMPv6NeighborSolicitation) NextLayerType() gopacket.LayerType {
|
||||
return gopacket.LayerTypePayload
|
||||
}
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (i *ICMPv6NeighborSolicitation) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
if len(data) < 20 {
|
||||
df.SetTruncated()
|
||||
return errors.New("ICMP layer less then 20 bytes for ICMPv6 neighbor solicitation")
|
||||
}
|
||||
|
||||
i.TargetAddress = net.IP(data[4:20])
|
||||
i.BaseLayer = BaseLayer{data, nil} // assume no payload
|
||||
|
||||
// truncate old options
|
||||
i.Options = i.Options[:0]
|
||||
|
||||
return i.Options.DecodeFromBytes(data[20:], df)
|
||||
}
|
||||
|
||||
// SerializeTo writes the serialized form of this layer into the
|
||||
// SerializationBuffer, implementing gopacket.SerializableLayer.
|
||||
// See the docs for gopacket.SerializableLayer for more info.
|
||||
func (i *ICMPv6NeighborSolicitation) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
if err := i.Options.SerializeTo(b, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf, err := b.PrependBytes(20)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
copy(buf, lotsOfZeros[:4])
|
||||
copy(buf[4:], i.TargetAddress)
|
||||
return nil
|
||||
}
|
||||
|
||||
// CanDecode returns the set of layer types that this DecodingLayer can decode.
|
||||
func (i *ICMPv6NeighborSolicitation) CanDecode() gopacket.LayerClass {
|
||||
return LayerTypeICMPv6NeighborSolicitation
|
||||
}
|
||||
|
||||
// LayerType returns LayerTypeICMPv6NeighborAdvertisement.
|
||||
func (i *ICMPv6NeighborAdvertisement) LayerType() gopacket.LayerType {
|
||||
return LayerTypeICMPv6NeighborAdvertisement
|
||||
}
|
||||
|
||||
// NextLayerType returns the layer type contained by this DecodingLayer.
|
||||
func (i *ICMPv6NeighborAdvertisement) NextLayerType() gopacket.LayerType {
|
||||
return gopacket.LayerTypePayload
|
||||
}
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (i *ICMPv6NeighborAdvertisement) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
if len(data) < 20 {
|
||||
df.SetTruncated()
|
||||
return errors.New("ICMP layer less then 20 bytes for ICMPv6 neighbor advertisement")
|
||||
}
|
||||
|
||||
i.Flags = uint8(data[0])
|
||||
i.TargetAddress = net.IP(data[4:20])
|
||||
i.BaseLayer = BaseLayer{data, nil} // assume no payload
|
||||
|
||||
// truncate old options
|
||||
i.Options = i.Options[:0]
|
||||
|
||||
return i.Options.DecodeFromBytes(data[20:], df)
|
||||
}
|
||||
|
||||
// SerializeTo writes the serialized form of this layer into the
|
||||
// SerializationBuffer, implementing gopacket.SerializableLayer.
|
||||
// See the docs for gopacket.SerializableLayer for more info.
|
||||
func (i *ICMPv6NeighborAdvertisement) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
if err := i.Options.SerializeTo(b, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf, err := b.PrependBytes(20)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf[0] = byte(i.Flags)
|
||||
copy(buf[1:], lotsOfZeros[:3])
|
||||
copy(buf[4:], i.TargetAddress)
|
||||
return nil
|
||||
}
|
||||
|
||||
// CanDecode returns the set of layer types that this DecodingLayer can decode.
|
||||
func (i *ICMPv6NeighborAdvertisement) CanDecode() gopacket.LayerClass {
|
||||
return LayerTypeICMPv6NeighborAdvertisement
|
||||
}
|
||||
|
||||
// Router indicates whether the sender is a router or not.
|
||||
func (i *ICMPv6NeighborAdvertisement) Router() bool {
|
||||
return i.Flags&0x80 != 0
|
||||
}
|
||||
|
||||
// Solicited indicates whether the advertisement was solicited or not.
|
||||
func (i *ICMPv6NeighborAdvertisement) Solicited() bool {
|
||||
return i.Flags&0x40 != 0
|
||||
}
|
||||
|
||||
// Override indicates whether the advertisement should Override an existing
|
||||
// cache entry.
|
||||
func (i *ICMPv6NeighborAdvertisement) Override() bool {
|
||||
return i.Flags&0x20 != 0
|
||||
}
|
||||
|
||||
// LayerType returns LayerTypeICMPv6Redirect.
|
||||
func (i *ICMPv6Redirect) LayerType() gopacket.LayerType {
|
||||
return LayerTypeICMPv6Redirect
|
||||
}
|
||||
|
||||
// NextLayerType returns the layer type contained by this DecodingLayer.
|
||||
func (i *ICMPv6Redirect) NextLayerType() gopacket.LayerType {
|
||||
return gopacket.LayerTypePayload
|
||||
}
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (i *ICMPv6Redirect) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
if len(data) < 36 {
|
||||
df.SetTruncated()
|
||||
return errors.New("ICMP layer less then 36 bytes for ICMPv6 redirect")
|
||||
}
|
||||
|
||||
i.TargetAddress = net.IP(data[4:20])
|
||||
i.DestinationAddress = net.IP(data[20:36])
|
||||
i.BaseLayer = BaseLayer{data, nil} // assume no payload
|
||||
|
||||
// truncate old options
|
||||
i.Options = i.Options[:0]
|
||||
|
||||
return i.Options.DecodeFromBytes(data[36:], df)
|
||||
}
|
||||
|
||||
// SerializeTo writes the serialized form of this layer into the
|
||||
// SerializationBuffer, implementing gopacket.SerializableLayer.
|
||||
// See the docs for gopacket.SerializableLayer for more info.
|
||||
func (i *ICMPv6Redirect) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
if err := i.Options.SerializeTo(b, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf, err := b.PrependBytes(36)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
copy(buf, lotsOfZeros[:4])
|
||||
copy(buf[4:], i.TargetAddress)
|
||||
copy(buf[20:], i.DestinationAddress)
|
||||
return nil
|
||||
}
|
||||
|
||||
// CanDecode returns the set of layer types that this DecodingLayer can decode.
|
||||
func (i *ICMPv6Redirect) CanDecode() gopacket.LayerClass {
|
||||
return LayerTypeICMPv6Redirect
|
||||
}
|
||||
|
||||
func (i ICMPv6Option) String() string {
|
||||
hd := hex.EncodeToString(i.Data)
|
||||
if len(hd) > 0 {
|
||||
hd = " 0x" + hd
|
||||
}
|
||||
|
||||
switch i.Type {
|
||||
case ICMPv6OptSourceAddress, ICMPv6OptTargetAddress:
|
||||
return fmt.Sprintf("ICMPv6Option(%s:%v)",
|
||||
i.Type,
|
||||
net.HardwareAddr(i.Data))
|
||||
case ICMPv6OptPrefixInfo:
|
||||
if len(i.Data) == 30 {
|
||||
prefixLen := uint8(i.Data[0])
|
||||
onLink := (i.Data[1]&0x80 != 0)
|
||||
autonomous := (i.Data[1]&0x40 != 0)
|
||||
validLifetime := time.Duration(binary.BigEndian.Uint32(i.Data[2:6])) * time.Second
|
||||
preferredLifetime := time.Duration(binary.BigEndian.Uint32(i.Data[6:10])) * time.Second
|
||||
|
||||
prefix := net.IP(i.Data[14:])
|
||||
|
||||
return fmt.Sprintf("ICMPv6Option(%s:%v/%v:%t:%t:%v:%v)",
|
||||
i.Type,
|
||||
prefix, prefixLen,
|
||||
onLink, autonomous,
|
||||
validLifetime, preferredLifetime)
|
||||
}
|
||||
case ICMPv6OptRedirectedHeader:
|
||||
// could invoke IP decoder on data... probably best not to
|
||||
break
|
||||
case ICMPv6OptMTU:
|
||||
if len(i.Data) == 6 {
|
||||
return fmt.Sprintf("ICMPv6Option(%s:%v)",
|
||||
i.Type,
|
||||
binary.BigEndian.Uint32(i.Data[2:]))
|
||||
}
|
||||
|
||||
}
|
||||
return fmt.Sprintf("ICMPv6Option(%s:%s)", i.Type, hd)
|
||||
}
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (i *ICMPv6Options) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
for len(data) > 0 {
|
||||
if len(data) < 2 {
|
||||
df.SetTruncated()
|
||||
return errors.New("ICMP layer less then 2 bytes for ICMPv6 message option")
|
||||
}
|
||||
|
||||
// unit is 8 octets, convert to bytes
|
||||
length := int(data[1]) * 8
|
||||
|
||||
if length == 0 {
|
||||
df.SetTruncated()
|
||||
return errors.New("ICMPv6 message option with length 0")
|
||||
}
|
||||
|
||||
if len(data) < length {
|
||||
df.SetTruncated()
|
||||
return fmt.Errorf("ICMP layer only %v bytes for ICMPv6 message option with length %v", len(data), length)
|
||||
}
|
||||
|
||||
o := ICMPv6Option{
|
||||
Type: ICMPv6Opt(data[0]),
|
||||
Data: data[2:length],
|
||||
}
|
||||
|
||||
// chop off option we just consumed
|
||||
data = data[length:]
|
||||
|
||||
*i = append(*i, o)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SerializeTo writes the serialized form of this layer into the
|
||||
// SerializationBuffer, implementing gopacket.SerializableLayer.
|
||||
// See the docs for gopacket.SerializableLayer for more info.
|
||||
func (i *ICMPv6Options) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
for _, opt := range []ICMPv6Option(*i) {
|
||||
length := len(opt.Data) + 2
|
||||
buf, err := b.PrependBytes(length)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf[0] = byte(opt.Type)
|
||||
buf[1] = byte(length / 8)
|
||||
copy(buf[2:], opt.Data)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func decodeICMPv6Echo(data []byte, p gopacket.PacketBuilder) error {
|
||||
i := &ICMPv6Echo{}
|
||||
return decodingLayerDecoder(i, data, p)
|
||||
}
|
||||
|
||||
func decodeICMPv6RouterSolicitation(data []byte, p gopacket.PacketBuilder) error {
|
||||
i := &ICMPv6RouterSolicitation{}
|
||||
return decodingLayerDecoder(i, data, p)
|
||||
}
|
||||
|
||||
func decodeICMPv6RouterAdvertisement(data []byte, p gopacket.PacketBuilder) error {
|
||||
i := &ICMPv6RouterAdvertisement{}
|
||||
return decodingLayerDecoder(i, data, p)
|
||||
}
|
||||
|
||||
func decodeICMPv6NeighborSolicitation(data []byte, p gopacket.PacketBuilder) error {
|
||||
i := &ICMPv6NeighborSolicitation{}
|
||||
return decodingLayerDecoder(i, data, p)
|
||||
}
|
||||
|
||||
func decodeICMPv6NeighborAdvertisement(data []byte, p gopacket.PacketBuilder) error {
|
||||
i := &ICMPv6NeighborAdvertisement{}
|
||||
return decodingLayerDecoder(i, data, p)
|
||||
}
|
||||
|
||||
func decodeICMPv6Redirect(data []byte, p gopacket.PacketBuilder) error {
|
||||
i := &ICMPv6Redirect{}
|
||||
return decodingLayerDecoder(i, data, p)
|
||||
}
|
2
vendor/github.com/google/gopacket/layers/ip6.go
generated
vendored
2
vendor/github.com/google/gopacket/layers/ip6.go
generated
vendored
|
@ -240,6 +240,8 @@ func (ip6 *IPv6) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error
|
|||
return errors.New("IPv6 has jumbo length and IPv6 length is not 0")
|
||||
} else if !jumbo && ip6.Length == 0 {
|
||||
return errors.New("IPv6 length 0, but HopByHop header does not have jumbogram option")
|
||||
} else {
|
||||
ip6.Payload = ip6.Payload[ip6.hbh.ActualLength:]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
22
vendor/github.com/google/gopacket/layers/layertypes.go
generated
vendored
22
vendor/github.com/google/gopacket/layers/layertypes.go
generated
vendored
|
@ -123,6 +123,19 @@ var (
|
|||
LayerTypeVRRP = gopacket.RegisterLayerType(119, gopacket.LayerTypeMetadata{Name: "VRRP", Decoder: gopacket.DecodeFunc(decodeVRRP)})
|
||||
LayerTypeGeneve = gopacket.RegisterLayerType(120, gopacket.LayerTypeMetadata{Name: "Geneve", Decoder: gopacket.DecodeFunc(decodeGeneve)})
|
||||
LayerTypeSTP = gopacket.RegisterLayerType(121, gopacket.LayerTypeMetadata{Name: "STP", Decoder: gopacket.DecodeFunc(decodeSTP)})
|
||||
LayerTypeBFD = gopacket.RegisterLayerType(122, gopacket.LayerTypeMetadata{Name: "BFD", Decoder: gopacket.DecodeFunc(decodeBFD)})
|
||||
LayerTypeOSPF = gopacket.RegisterLayerType(123, gopacket.LayerTypeMetadata{Name: "OSPF", Decoder: gopacket.DecodeFunc(decodeOSPF)})
|
||||
LayerTypeICMPv6RouterSolicitation = gopacket.RegisterLayerType(124, gopacket.LayerTypeMetadata{Name: "ICMPv6RouterSolicitation", Decoder: gopacket.DecodeFunc(decodeICMPv6RouterSolicitation)})
|
||||
LayerTypeICMPv6RouterAdvertisement = gopacket.RegisterLayerType(125, gopacket.LayerTypeMetadata{Name: "ICMPv6RouterAdvertisement", Decoder: gopacket.DecodeFunc(decodeICMPv6RouterAdvertisement)})
|
||||
LayerTypeICMPv6NeighborSolicitation = gopacket.RegisterLayerType(126, gopacket.LayerTypeMetadata{Name: "ICMPv6NeighborSolicitation", Decoder: gopacket.DecodeFunc(decodeICMPv6NeighborSolicitation)})
|
||||
LayerTypeICMPv6NeighborAdvertisement = gopacket.RegisterLayerType(127, gopacket.LayerTypeMetadata{Name: "ICMPv6NeighborAdvertisement", Decoder: gopacket.DecodeFunc(decodeICMPv6NeighborAdvertisement)})
|
||||
LayerTypeICMPv6Redirect = gopacket.RegisterLayerType(128, gopacket.LayerTypeMetadata{Name: "ICMPv6Redirect", Decoder: gopacket.DecodeFunc(decodeICMPv6Redirect)})
|
||||
LayerTypeGTPv1U = gopacket.RegisterLayerType(129, gopacket.LayerTypeMetadata{Name: "GTPv1U", Decoder: gopacket.DecodeFunc(decodeGTPv1u)})
|
||||
LayerTypeEAPOLKey = gopacket.RegisterLayerType(130, gopacket.LayerTypeMetadata{Name: "EAPOLKey", Decoder: gopacket.DecodeFunc(decodeEAPOLKey)})
|
||||
LayerTypeLCM = gopacket.RegisterLayerType(131, gopacket.LayerTypeMetadata{Name: "LCM", Decoder: gopacket.DecodeFunc(decodeLCM)})
|
||||
LayerTypeICMPv6Echo = gopacket.RegisterLayerType(132, gopacket.LayerTypeMetadata{Name: "ICMPv6Echo", Decoder: gopacket.DecodeFunc(decodeICMPv6Echo)})
|
||||
LayerTypeSIP = gopacket.RegisterLayerType(133, gopacket.LayerTypeMetadata{Name: "SIP", Decoder: gopacket.DecodeFunc(decodeSIP)})
|
||||
LayerTypeDHCPv6 = gopacket.RegisterLayerType(134, gopacket.LayerTypeMetadata{Name: "DHCPv6", Decoder: gopacket.DecodeFunc(decodeDHCPv6)})
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -172,4 +185,13 @@ var (
|
|||
LayerTypeIPSecAH,
|
||||
LayerTypeIPSecESP,
|
||||
})
|
||||
// LayerClassICMPv6NDP contains ICMPv6 neighbor discovery protocol
|
||||
// messages.
|
||||
LayerClassICMPv6NDP = gopacket.NewLayerClass([]gopacket.LayerType{
|
||||
LayerTypeICMPv6RouterSolicitation,
|
||||
LayerTypeICMPv6RouterAdvertisement,
|
||||
LayerTypeICMPv6NeighborSolicitation,
|
||||
LayerTypeICMPv6NeighborAdvertisement,
|
||||
LayerTypeICMPv6Redirect,
|
||||
})
|
||||
)
|
||||
|
|
213
vendor/github.com/google/gopacket/layers/lcm.go
generated
vendored
Normal file
213
vendor/github.com/google/gopacket/layers/lcm.go
generated
vendored
Normal file
|
@ -0,0 +1,213 @@
|
|||
// Copyright 2018 Google, Inc. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree.
|
||||
|
||||
package layers
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
)
|
||||
|
||||
const (
|
||||
// LCMShortHeaderMagic is the LCM small message header magic number
|
||||
LCMShortHeaderMagic uint32 = 0x4c433032
|
||||
// LCMFragmentedHeaderMagic is the LCM fragmented message header magic number
|
||||
LCMFragmentedHeaderMagic uint32 = 0x4c433033
|
||||
)
|
||||
|
||||
// LCM (Lightweight Communications and Marshalling) is a set of libraries and
|
||||
// tools for message passing and data marshalling, targeted at real-time systems
|
||||
// where high-bandwidth and low latency are critical. It provides a
|
||||
// publish/subscribe message passing model and automatic
|
||||
// marshalling/unmarshalling code generation with bindings for applications in a
|
||||
// variety of programming languages.
|
||||
//
|
||||
// References
|
||||
// https://lcm-proj.github.io/
|
||||
// https://github.com/lcm-proj/lcm
|
||||
type LCM struct {
|
||||
// Common (short & fragmented header) fields
|
||||
Magic uint32
|
||||
SequenceNumber uint32
|
||||
// Fragmented header only fields
|
||||
PayloadSize uint32
|
||||
FragmentOffset uint32
|
||||
FragmentNumber uint16
|
||||
TotalFragments uint16
|
||||
// Common field
|
||||
ChannelName string
|
||||
// Gopacket helper fields
|
||||
Fragmented bool
|
||||
fingerprint LCMFingerprint
|
||||
contents []byte
|
||||
payload []byte
|
||||
}
|
||||
|
||||
// LCMFingerprint is the type of a LCM fingerprint.
|
||||
type LCMFingerprint uint64
|
||||
|
||||
var (
|
||||
// lcmLayerTypes contains a map of all LCM fingerprints that we support and
|
||||
// their LayerType
|
||||
lcmLayerTypes = map[LCMFingerprint]gopacket.LayerType{}
|
||||
layerTypeIndex = 1001
|
||||
)
|
||||
|
||||
// RegisterLCMLayerType allows users to register decoders for the underlying
|
||||
// LCM payload. This is done based on the fingerprint that every LCM message
|
||||
// contains and which identifies it uniquely. If num is not the zero value it
|
||||
// will be used when registering with RegisterLayerType towards gopacket,
|
||||
// otherwise an incremental value starting from 1001 will be used.
|
||||
func RegisterLCMLayerType(num int, name string, fingerprint LCMFingerprint,
|
||||
decoder gopacket.Decoder) gopacket.LayerType {
|
||||
metadata := gopacket.LayerTypeMetadata{Name: name, Decoder: decoder}
|
||||
|
||||
if num == 0 {
|
||||
num = layerTypeIndex
|
||||
layerTypeIndex++
|
||||
}
|
||||
|
||||
lcmLayerTypes[fingerprint] = gopacket.RegisterLayerType(num, metadata)
|
||||
|
||||
return lcmLayerTypes[fingerprint]
|
||||
}
|
||||
|
||||
// SupportedLCMFingerprints returns a slice of all LCM fingerprints that has
|
||||
// been registered so far.
|
||||
func SupportedLCMFingerprints() []LCMFingerprint {
|
||||
fingerprints := make([]LCMFingerprint, 0, len(lcmLayerTypes))
|
||||
for fp := range lcmLayerTypes {
|
||||
fingerprints = append(fingerprints, fp)
|
||||
}
|
||||
return fingerprints
|
||||
}
|
||||
|
||||
// GetLCMLayerType returns the underlying LCM message's LayerType.
|
||||
// This LayerType has to be registered by using RegisterLCMLayerType.
|
||||
func GetLCMLayerType(fingerprint LCMFingerprint) gopacket.LayerType {
|
||||
layerType, ok := lcmLayerTypes[fingerprint]
|
||||
if !ok {
|
||||
return gopacket.LayerTypePayload
|
||||
}
|
||||
|
||||
return layerType
|
||||
}
|
||||
|
||||
func decodeLCM(data []byte, p gopacket.PacketBuilder) error {
|
||||
lcm := &LCM{}
|
||||
|
||||
err := lcm.DecodeFromBytes(data, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.AddLayer(lcm)
|
||||
p.SetApplicationLayer(lcm)
|
||||
|
||||
return p.NextDecoder(lcm.NextLayerType())
|
||||
}
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (lcm *LCM) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
offset := 0
|
||||
|
||||
lcm.Magic = binary.BigEndian.Uint32(data[offset:4])
|
||||
offset += 4
|
||||
|
||||
if lcm.Magic != LCMShortHeaderMagic && lcm.Magic != LCMFragmentedHeaderMagic {
|
||||
return fmt.Errorf("Received LCM header magic %v does not match know "+
|
||||
"LCM magic numbers. Dropping packet.", lcm.Magic)
|
||||
}
|
||||
|
||||
lcm.SequenceNumber = binary.BigEndian.Uint32(data[offset:8])
|
||||
offset += 4
|
||||
|
||||
if lcm.Magic == LCMFragmentedHeaderMagic {
|
||||
lcm.Fragmented = true
|
||||
|
||||
lcm.PayloadSize = binary.BigEndian.Uint32(data[offset : offset+4])
|
||||
offset += 4
|
||||
|
||||
lcm.FragmentOffset = binary.BigEndian.Uint32(data[offset : offset+4])
|
||||
offset += 4
|
||||
|
||||
lcm.FragmentNumber = binary.BigEndian.Uint16(data[offset : offset+2])
|
||||
offset += 2
|
||||
|
||||
lcm.TotalFragments = binary.BigEndian.Uint16(data[offset : offset+2])
|
||||
offset += 2
|
||||
} else {
|
||||
lcm.Fragmented = false
|
||||
}
|
||||
|
||||
if !lcm.Fragmented || (lcm.Fragmented && lcm.FragmentNumber == 0) {
|
||||
buffer := make([]byte, 0)
|
||||
for _, b := range data[offset:] {
|
||||
offset++
|
||||
|
||||
if b == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
buffer = append(buffer, b)
|
||||
}
|
||||
|
||||
lcm.ChannelName = string(buffer)
|
||||
}
|
||||
|
||||
lcm.fingerprint = LCMFingerprint(
|
||||
binary.BigEndian.Uint64(data[offset : offset+8]))
|
||||
|
||||
lcm.contents = data[:offset]
|
||||
lcm.payload = data[offset:]
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CanDecode returns a set of layers that LCM objects can decode.
|
||||
// As LCM objects can only decode the LCM layer, we just return that layer.
|
||||
func (lcm LCM) CanDecode() gopacket.LayerClass {
|
||||
return LayerTypeLCM
|
||||
}
|
||||
|
||||
// NextLayerType specifies the LCM payload layer type following this header.
|
||||
// As LCM packets are serialized structs with uniq fingerprints for each uniq
|
||||
// combination of data types, lookup of correct layer type is based on that
|
||||
// fingerprint.
|
||||
func (lcm LCM) NextLayerType() gopacket.LayerType {
|
||||
if !lcm.Fragmented || (lcm.Fragmented && lcm.FragmentNumber == 0) {
|
||||
return GetLCMLayerType(lcm.fingerprint)
|
||||
}
|
||||
|
||||
return gopacket.LayerTypeFragment
|
||||
}
|
||||
|
||||
// LayerType returns LayerTypeLCM
|
||||
func (lcm LCM) LayerType() gopacket.LayerType {
|
||||
return LayerTypeLCM
|
||||
}
|
||||
|
||||
// LayerContents returns the contents of the LCM header.
|
||||
func (lcm LCM) LayerContents() []byte {
|
||||
return lcm.contents
|
||||
}
|
||||
|
||||
// LayerPayload returns the payload following this LCM header.
|
||||
func (lcm LCM) LayerPayload() []byte {
|
||||
return lcm.payload
|
||||
}
|
||||
|
||||
// Payload returns the payload following this LCM header.
|
||||
func (lcm LCM) Payload() []byte {
|
||||
return lcm.LayerPayload()
|
||||
}
|
||||
|
||||
// Fingerprint returns the LCM fingerprint of the underlying message.
|
||||
func (lcm LCM) Fingerprint() LCMFingerprint {
|
||||
return lcm.fingerprint
|
||||
}
|
111
vendor/github.com/google/gopacket/layers/llc.go
generated
vendored
111
vendor/github.com/google/gopacket/layers/llc.go
generated
vendored
|
@ -27,6 +27,47 @@ type LLC struct {
|
|||
// LayerType returns gopacket.LayerTypeLLC.
|
||||
func (l *LLC) LayerType() gopacket.LayerType { return LayerTypeLLC }
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (l *LLC) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
if len(data) < 3 {
|
||||
return errors.New("LLC header too small")
|
||||
}
|
||||
l.DSAP = data[0] & 0xFE
|
||||
l.IG = data[0]&0x1 != 0
|
||||
l.SSAP = data[1] & 0xFE
|
||||
l.CR = data[1]&0x1 != 0
|
||||
l.Control = uint16(data[2])
|
||||
|
||||
if l.Control&0x1 == 0 || l.Control&0x3 == 0x1 {
|
||||
if len(data) < 4 {
|
||||
return errors.New("LLC header too small")
|
||||
}
|
||||
l.Control = l.Control<<8 | uint16(data[3])
|
||||
l.Contents = data[:4]
|
||||
l.Payload = data[4:]
|
||||
} else {
|
||||
l.Contents = data[:3]
|
||||
l.Payload = data[3:]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CanDecode returns the set of layer types that this DecodingLayer can decode.
|
||||
func (l *LLC) CanDecode() gopacket.LayerClass {
|
||||
return LayerTypeLLC
|
||||
}
|
||||
|
||||
// NextLayerType returns the layer type contained by this DecodingLayer.
|
||||
func (l *LLC) NextLayerType() gopacket.LayerType {
|
||||
switch {
|
||||
case l.DSAP == 0xAA && l.SSAP == 0xAA:
|
||||
return LayerTypeSNAP
|
||||
case l.DSAP == 0x42 && l.SSAP == 0x42:
|
||||
return LayerTypeSTP
|
||||
}
|
||||
return gopacket.LayerTypeZero // Not implemented
|
||||
}
|
||||
|
||||
// SNAP is used inside LLC. See
|
||||
// http://standards.ieee.org/getieee802/download/802-2001.pdf.
|
||||
// From http://en.wikipedia.org/wiki/Subnetwork_Access_Protocol:
|
||||
|
@ -42,37 +83,43 @@ type SNAP struct {
|
|||
// LayerType returns gopacket.LayerTypeSNAP.
|
||||
func (s *SNAP) LayerType() gopacket.LayerType { return LayerTypeSNAP }
|
||||
|
||||
func decodeLLC(data []byte, p gopacket.PacketBuilder) error {
|
||||
l := &LLC{
|
||||
DSAP: data[0] & 0xFE,
|
||||
IG: data[0]&0x1 != 0,
|
||||
SSAP: data[1] & 0xFE,
|
||||
CR: data[1]&0x1 != 0,
|
||||
Control: uint16(data[2]),
|
||||
// DecodeFromBytes decodes the given bytes into this layer.
|
||||
func (s *SNAP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
if len(data) < 5 {
|
||||
return errors.New("SNAP header too small")
|
||||
}
|
||||
if l.Control&0x1 == 0 || l.Control&0x3 == 0x1 {
|
||||
l.Control = l.Control<<8 | uint16(data[3])
|
||||
l.Contents = data[:4]
|
||||
l.Payload = data[4:]
|
||||
} else {
|
||||
l.Contents = data[:3]
|
||||
l.Payload = data[3:]
|
||||
s.OrganizationalCode = data[:3]
|
||||
s.Type = EthernetType(binary.BigEndian.Uint16(data[3:5]))
|
||||
s.BaseLayer = BaseLayer{data[:5], data[5:]}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CanDecode returns the set of layer types that this DecodingLayer can decode.
|
||||
func (s *SNAP) CanDecode() gopacket.LayerClass {
|
||||
return LayerTypeLLC
|
||||
}
|
||||
|
||||
// NextLayerType returns the layer type contained by this DecodingLayer.
|
||||
func (s *SNAP) NextLayerType() gopacket.LayerType {
|
||||
// See BUG(gconnel) in decodeSNAP
|
||||
return s.Type.LayerType()
|
||||
}
|
||||
|
||||
func decodeLLC(data []byte, p gopacket.PacketBuilder) error {
|
||||
l := &LLC{}
|
||||
err := l.DecodeFromBytes(data, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.AddLayer(l)
|
||||
switch {
|
||||
case l.DSAP == 0xAA && l.SSAP == 0xAA:
|
||||
return p.NextDecoder(LayerTypeSNAP)
|
||||
case l.DSAP == 0x42 && l.SSAP == 0x42:
|
||||
return p.NextDecoder(LayerTypeSTP)
|
||||
}
|
||||
return p.NextDecoder(gopacket.DecodeUnknown)
|
||||
return p.NextDecoder(l.NextLayerType())
|
||||
}
|
||||
|
||||
func decodeSNAP(data []byte, p gopacket.PacketBuilder) error {
|
||||
s := &SNAP{
|
||||
OrganizationalCode: data[:3],
|
||||
Type: EthernetType(binary.BigEndian.Uint16(data[3:5])),
|
||||
BaseLayer: BaseLayer{data[:5], data[5:]},
|
||||
s := &SNAP{}
|
||||
err := s.DecodeFromBytes(data, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.AddLayer(s)
|
||||
// BUG(gconnell): When decoding SNAP, we treat the SNAP type as an Ethernet
|
||||
|
@ -85,7 +132,7 @@ func decodeSNAP(data []byte, p gopacket.PacketBuilder) error {
|
|||
// SerializationBuffer, implementing gopacket.SerializableLayer.
|
||||
// See the docs for gopacket.SerializableLayer for more info.
|
||||
func (l *LLC) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
var ig_flag, cr_flag byte
|
||||
var igFlag, crFlag byte
|
||||
var length int
|
||||
|
||||
if l.Control&0xFF00 != 0 {
|
||||
|
@ -105,18 +152,18 @@ func (l *LLC) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOpt
|
|||
if buf, err := b.PrependBytes(length); err != nil {
|
||||
return err
|
||||
} else {
|
||||
ig_flag = 0
|
||||
igFlag = 0
|
||||
if l.IG {
|
||||
ig_flag = 0x1
|
||||
igFlag = 0x1
|
||||
}
|
||||
|
||||
cr_flag = 0
|
||||
crFlag = 0
|
||||
if l.CR {
|
||||
cr_flag = 0x1
|
||||
crFlag = 0x1
|
||||
}
|
||||
|
||||
buf[0] = l.DSAP + ig_flag
|
||||
buf[1] = l.SSAP + cr_flag
|
||||
buf[0] = l.DSAP + igFlag
|
||||
buf[1] = l.SSAP + crFlag
|
||||
|
||||
if length == 4 {
|
||||
buf[2] = uint8(l.Control >> 8)
|
||||
|
|
55
vendor/github.com/google/gopacket/layers/lldp.go
generated
vendored
55
vendor/github.com/google/gopacket/layers/lldp.go
generated
vendored
|
@ -37,6 +37,10 @@ type LinkLayerDiscoveryValue struct {
|
|||
Value []byte
|
||||
}
|
||||
|
||||
func (c *LinkLayerDiscoveryValue) len() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// LLDPChassisIDSubType specifies the value type for a single LLDPChassisID.ID
|
||||
type LLDPChassisIDSubType byte
|
||||
|
||||
|
@ -57,6 +61,20 @@ type LLDPChassisID struct {
|
|||
ID []byte
|
||||
}
|
||||
|
||||
func (c *LLDPChassisID) serialize() []byte {
|
||||
|
||||
var buf = make([]byte, c.serializedLen())
|
||||
idLen := uint16(LLDPTLVChassisID)<<9 | uint16(len(c.ID)+1) //id should take 7 bits, length should take 9 bits, +1 for subtype
|
||||
binary.BigEndian.PutUint16(buf[0:2], idLen)
|
||||
buf[2] = byte(c.Subtype)
|
||||
copy(buf[3:], c.ID)
|
||||
return buf
|
||||
}
|
||||
|
||||
func (c *LLDPChassisID) serializedLen() int {
|
||||
return len(c.ID) + 3 // +2 for id and length, +1 for subtype
|
||||
}
|
||||
|
||||
// LLDPPortIDSubType specifies the value type for a single LLDPPortID.ID
|
||||
type LLDPPortIDSubType byte
|
||||
|
||||
|
@ -77,6 +95,20 @@ type LLDPPortID struct {
|
|||
ID []byte
|
||||
}
|
||||
|
||||
func (c *LLDPPortID) serialize() []byte {
|
||||
|
||||
var buf = make([]byte, c.serializedLen())
|
||||
idLen := uint16(LLDPTLVPortID)<<9 | uint16(len(c.ID)+1) //id should take 7 bits, length should take 9 bits, +1 for subtype
|
||||
binary.BigEndian.PutUint16(buf[0:2], idLen)
|
||||
buf[2] = byte(c.Subtype)
|
||||
copy(buf[3:], c.ID)
|
||||
return buf
|
||||
}
|
||||
|
||||
func (c *LLDPPortID) serializedLen() int {
|
||||
return len(c.ID) + 3 // +2 for id and length, +1 for subtype
|
||||
}
|
||||
|
||||
// LinkLayerDiscovery is a packet layer containing the LinkLayer Discovery Protocol.
|
||||
// See http:http://standards.ieee.org/getieee802/download/802.1AB-2009.pdf
|
||||
// ChassisID, PortID and TTL are mandatory TLV's. Other values can be decoded
|
||||
|
@ -733,6 +765,29 @@ func (c *LinkLayerDiscovery) LayerType() gopacket.LayerType {
|
|||
return LayerTypeLinkLayerDiscovery
|
||||
}
|
||||
|
||||
// SerializeTo serializes LLDP packet to bytes and writes on SerializeBuffer.
|
||||
func (c *LinkLayerDiscovery) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
|
||||
chassIDLen := c.ChassisID.serializedLen()
|
||||
portIDLen := c.PortID.serializedLen()
|
||||
vb, err := b.AppendBytes(chassIDLen + portIDLen + 4) // +4 for TTL
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
copy(vb[:chassIDLen], c.ChassisID.serialize())
|
||||
copy(vb[chassIDLen:], c.PortID.serialize())
|
||||
ttlIDLen := uint16(LLDPTLVTTL)<<9 | uint16(2)
|
||||
binary.BigEndian.PutUint16(vb[chassIDLen+portIDLen:], ttlIDLen)
|
||||
binary.BigEndian.PutUint16(vb[chassIDLen+portIDLen+2:], c.TTL)
|
||||
|
||||
vb, err = b.AppendBytes(2) // End Tlv, 2 bytes
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
binary.BigEndian.PutUint16(vb[len(vb)-2:], uint16(0)) //End tlv, 2 bytes, all zero
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func decodeLinkLayerDiscovery(data []byte, p gopacket.PacketBuilder) error {
|
||||
var vals []LinkLayerDiscoveryValue
|
||||
vData := data[0:]
|
||||
|
|
680
vendor/github.com/google/gopacket/layers/ospf.go
generated
vendored
Normal file
680
vendor/github.com/google/gopacket/layers/ospf.go
generated
vendored
Normal file
|
@ -0,0 +1,680 @@
|
|||
// Copyright 2017 Google, Inc. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree.
|
||||
|
||||
package layers
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
)
|
||||
|
||||
// OSPFType denotes what kind of OSPF type it is
|
||||
type OSPFType uint8
|
||||
|
||||
// Potential values for OSPF.Type.
|
||||
const (
|
||||
OSPFHello OSPFType = 1
|
||||
OSPFDatabaseDescription OSPFType = 2
|
||||
OSPFLinkStateRequest OSPFType = 3
|
||||
OSPFLinkStateUpdate OSPFType = 4
|
||||
OSPFLinkStateAcknowledgment OSPFType = 5
|
||||
)
|
||||
|
||||
// LSA Function Codes for LSAheader.LSType
|
||||
const (
|
||||
RouterLSAtypeV2 = 0x1
|
||||
RouterLSAtype = 0x2001
|
||||
NetworkLSAtypeV2 = 0x2
|
||||
NetworkLSAtype = 0x2002
|
||||
SummaryLSANetworktypeV2 = 0x3
|
||||
InterAreaPrefixLSAtype = 0x2003
|
||||
SummaryLSAASBRtypeV2 = 0x4
|
||||
InterAreaRouterLSAtype = 0x2004
|
||||
ASExternalLSAtypeV2 = 0x5
|
||||
ASExternalLSAtype = 0x4005
|
||||
NSSALSAtype = 0x2007
|
||||
LinkLSAtype = 0x0008
|
||||
IntraAreaPrefixLSAtype = 0x2009
|
||||
)
|
||||
|
||||
// String conversions for OSPFType
|
||||
func (i OSPFType) String() string {
|
||||
switch i {
|
||||
case OSPFHello:
|
||||
return "Hello"
|
||||
case OSPFDatabaseDescription:
|
||||
return "Database Description"
|
||||
case OSPFLinkStateRequest:
|
||||
return "Link State Request"
|
||||
case OSPFLinkStateUpdate:
|
||||
return "Link State Update"
|
||||
case OSPFLinkStateAcknowledgment:
|
||||
return "Link State Acknowledgment"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// Prefix extends IntraAreaPrefixLSA
|
||||
type Prefix struct {
|
||||
PrefixLength uint8
|
||||
PrefixOptions uint8
|
||||
Metric uint16
|
||||
AddressPrefix []byte
|
||||
}
|
||||
|
||||
// IntraAreaPrefixLSA is the struct from RFC 5340 A.4.10.
|
||||
type IntraAreaPrefixLSA struct {
|
||||
NumOfPrefixes uint16
|
||||
RefLSType uint16
|
||||
RefLinkStateID uint32
|
||||
RefAdvRouter uint32
|
||||
Prefixes []Prefix
|
||||
}
|
||||
|
||||
// LinkLSA is the struct from RFC 5340 A.4.9.
|
||||
type LinkLSA struct {
|
||||
RtrPriority uint8
|
||||
Options uint32
|
||||
LinkLocalAddress []byte
|
||||
NumOfPrefixes uint32
|
||||
Prefixes []Prefix
|
||||
}
|
||||
|
||||
// ASExternalLSAV2 is the struct from RFC 2328 A.4.5.
|
||||
type ASExternalLSAV2 struct {
|
||||
NetworkMask uint32
|
||||
ExternalBit uint8
|
||||
Metric uint32
|
||||
ForwardingAddress uint32
|
||||
ExternalRouteTag uint32
|
||||
}
|
||||
|
||||
// ASExternalLSA is the struct from RFC 5340 A.4.7.
|
||||
type ASExternalLSA struct {
|
||||
Flags uint8
|
||||
Metric uint32
|
||||
PrefixLength uint8
|
||||
PrefixOptions uint8
|
||||
RefLSType uint16
|
||||
AddressPrefix []byte
|
||||
ForwardingAddress []byte
|
||||
ExternalRouteTag uint32
|
||||
RefLinkStateID uint32
|
||||
}
|
||||
|
||||
// InterAreaRouterLSA is the struct from RFC 5340 A.4.6.
|
||||
type InterAreaRouterLSA struct {
|
||||
Options uint32
|
||||
Metric uint32
|
||||
DestinationRouterID uint32
|
||||
}
|
||||
|
||||
// InterAreaPrefixLSA is the struct from RFC 5340 A.4.5.
|
||||
type InterAreaPrefixLSA struct {
|
||||
Metric uint32
|
||||
PrefixLength uint8
|
||||
PrefixOptions uint8
|
||||
AddressPrefix []byte
|
||||
}
|
||||
|
||||
// NetworkLSA is the struct from RFC 5340 A.4.4.
|
||||
type NetworkLSA struct {
|
||||
Options uint32
|
||||
AttachedRouter []uint32
|
||||
}
|
||||
|
||||
// RouterV2 extends RouterLSAV2
|
||||
type RouterV2 struct {
|
||||
Type uint8
|
||||
LinkID uint32
|
||||
LinkData uint32
|
||||
Metric uint16
|
||||
}
|
||||
|
||||
// RouterLSAV2 is the struct from RFC 2328 A.4.2.
|
||||
type RouterLSAV2 struct {
|
||||
Flags uint8
|
||||
Links uint16
|
||||
Routers []RouterV2
|
||||
}
|
||||
|
||||
// Router extends RouterLSA
|
||||
type Router struct {
|
||||
Type uint8
|
||||
Metric uint16
|
||||
InterfaceID uint32
|
||||
NeighborInterfaceID uint32
|
||||
NeighborRouterID uint32
|
||||
}
|
||||
|
||||
// RouterLSA is the struct from RFC 5340 A.4.3.
|
||||
type RouterLSA struct {
|
||||
Flags uint8
|
||||
Options uint32
|
||||
Routers []Router
|
||||
}
|
||||
|
||||
// LSAheader is the struct from RFC 5340 A.4.2 and RFC 2328 A.4.1.
|
||||
type LSAheader struct {
|
||||
LSAge uint16
|
||||
LSType uint16
|
||||
LinkStateID uint32
|
||||
AdvRouter uint32
|
||||
LSSeqNumber uint32
|
||||
LSChecksum uint16
|
||||
Length uint16
|
||||
LSOptions uint8
|
||||
}
|
||||
|
||||
// LSA links LSAheader with the structs from RFC 5340 A.4.
|
||||
type LSA struct {
|
||||
LSAheader
|
||||
Content interface{}
|
||||
}
|
||||
|
||||
// LSUpdate is the struct from RFC 5340 A.3.5.
|
||||
type LSUpdate struct {
|
||||
NumOfLSAs uint32
|
||||
LSAs []LSA
|
||||
}
|
||||
|
||||
// LSReq is the struct from RFC 5340 A.3.4.
|
||||
type LSReq struct {
|
||||
LSType uint16
|
||||
LSID uint32
|
||||
AdvRouter uint32
|
||||
}
|
||||
|
||||
// DbDescPkg is the struct from RFC 5340 A.3.3.
|
||||
type DbDescPkg struct {
|
||||
Options uint32
|
||||
InterfaceMTU uint16
|
||||
Flags uint16
|
||||
DDSeqNumber uint32
|
||||
LSAinfo []LSAheader
|
||||
}
|
||||
|
||||
// HelloPkg is the struct from RFC 5340 A.3.2.
|
||||
type HelloPkg struct {
|
||||
InterfaceID uint32
|
||||
RtrPriority uint8
|
||||
Options uint32
|
||||
HelloInterval uint16
|
||||
RouterDeadInterval uint32
|
||||
DesignatedRouterID uint32
|
||||
BackupDesignatedRouterID uint32
|
||||
NeighborID []uint32
|
||||
}
|
||||
|
||||
// HelloPkgV2 extends the HelloPkg struct with OSPFv2 information
|
||||
type HelloPkgV2 struct {
|
||||
HelloPkg
|
||||
NetworkMask uint32
|
||||
}
|
||||
|
||||
// OSPF is a basic OSPF packet header with common fields of Version 2 and Version 3.
|
||||
type OSPF struct {
|
||||
Version uint8
|
||||
Type OSPFType
|
||||
PacketLength uint16
|
||||
RouterID uint32
|
||||
AreaID uint32
|
||||
Checksum uint16
|
||||
Content interface{}
|
||||
}
|
||||
|
||||
//OSPFv2 extend the OSPF head with version 2 specific fields
|
||||
type OSPFv2 struct {
|
||||
BaseLayer
|
||||
OSPF
|
||||
AuType uint16
|
||||
Authentication uint64
|
||||
}
|
||||
|
||||
// OSPFv3 extend the OSPF head with version 3 specific fields
|
||||
type OSPFv3 struct {
|
||||
BaseLayer
|
||||
OSPF
|
||||
Instance uint8
|
||||
Reserved uint8
|
||||
}
|
||||
|
||||
// getLSAsv2 parses the LSA information from the packet for OSPFv2
|
||||
func getLSAsv2(num uint32, data []byte) ([]LSA, error) {
|
||||
var lsas []LSA
|
||||
var i uint32 = 0
|
||||
var offset uint32 = 0
|
||||
for ; i < num; i++ {
|
||||
lstype := uint16(data[offset+3])
|
||||
lsalength := binary.BigEndian.Uint16(data[offset+18 : offset+20])
|
||||
content, err := extractLSAInformation(lstype, lsalength, data[offset:])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not extract Link State type.")
|
||||
}
|
||||
lsa := LSA{
|
||||
LSAheader: LSAheader{
|
||||
LSAge: binary.BigEndian.Uint16(data[offset : offset+2]),
|
||||
LSOptions: data[offset+2],
|
||||
LSType: lstype,
|
||||
LinkStateID: binary.BigEndian.Uint32(data[offset+4 : offset+8]),
|
||||
AdvRouter: binary.BigEndian.Uint32(data[offset+8 : offset+12]),
|
||||
LSSeqNumber: binary.BigEndian.Uint32(data[offset+12 : offset+16]),
|
||||
LSChecksum: binary.BigEndian.Uint16(data[offset+16 : offset+18]),
|
||||
Length: lsalength,
|
||||
},
|
||||
Content: content,
|
||||
}
|
||||
lsas = append(lsas, lsa)
|
||||
offset += uint32(lsalength)
|
||||
}
|
||||
return lsas, nil
|
||||
}
|
||||
|
||||
// extractLSAInformation extracts all the LSA information
|
||||
func extractLSAInformation(lstype, lsalength uint16, data []byte) (interface{}, error) {
|
||||
if lsalength < 20 {
|
||||
return nil, fmt.Errorf("Link State header length %v too short, %v required", lsalength, 20)
|
||||
}
|
||||
if len(data) < int(lsalength) {
|
||||
return nil, fmt.Errorf("Link State header length %v too short, %v required", len(data), lsalength)
|
||||
}
|
||||
var content interface{}
|
||||
switch lstype {
|
||||
case RouterLSAtypeV2:
|
||||
var routers []RouterV2
|
||||
links := binary.BigEndian.Uint16(data[22:24])
|
||||
content = RouterLSAV2{
|
||||
Flags: data[20],
|
||||
Links: links,
|
||||
Routers: routers,
|
||||
}
|
||||
case ASExternalLSAtypeV2:
|
||||
content = ASExternalLSAV2{
|
||||
NetworkMask: binary.BigEndian.Uint32(data[20:24]),
|
||||
ExternalBit: data[24] & 0x80,
|
||||
Metric: binary.BigEndian.Uint32(data[24:28]) & 0x00FFFFFF,
|
||||
ForwardingAddress: binary.BigEndian.Uint32(data[28:32]),
|
||||
ExternalRouteTag: binary.BigEndian.Uint32(data[32:36]),
|
||||
}
|
||||
case RouterLSAtype:
|
||||
var routers []Router
|
||||
var j uint32
|
||||
for j = 24; j < uint32(lsalength); j += 16 {
|
||||
router := Router{
|
||||
Type: uint8(data[j]),
|
||||
Metric: binary.BigEndian.Uint16(data[j+2 : j+4]),
|
||||
InterfaceID: binary.BigEndian.Uint32(data[j+4 : j+8]),
|
||||
NeighborInterfaceID: binary.BigEndian.Uint32(data[j+8 : j+12]),
|
||||
NeighborRouterID: binary.BigEndian.Uint32(data[j+12 : j+16]),
|
||||
}
|
||||
routers = append(routers, router)
|
||||
}
|
||||
content = RouterLSA{
|
||||
Flags: uint8(data[20]),
|
||||
Options: binary.BigEndian.Uint32(data[20:24]) & 0x00FFFFFF,
|
||||
Routers: routers,
|
||||
}
|
||||
case NetworkLSAtype:
|
||||
var routers []uint32
|
||||
var j uint32
|
||||
for j = 24; j < uint32(lsalength); j += 4 {
|
||||
routers = append(routers, binary.BigEndian.Uint32(data[j:j+4]))
|
||||
}
|
||||
content = NetworkLSA{
|
||||
Options: binary.BigEndian.Uint32(data[20:24]) & 0x00FFFFFF,
|
||||
AttachedRouter: routers,
|
||||
}
|
||||
case InterAreaPrefixLSAtype:
|
||||
content = InterAreaPrefixLSA{
|
||||
Metric: binary.BigEndian.Uint32(data[20:24]) & 0x00FFFFFF,
|
||||
PrefixLength: uint8(data[24]),
|
||||
PrefixOptions: uint8(data[25]),
|
||||
AddressPrefix: data[28:uint32(lsalength)],
|
||||
}
|
||||
case InterAreaRouterLSAtype:
|
||||
content = InterAreaRouterLSA{
|
||||
Options: binary.BigEndian.Uint32(data[20:24]) & 0x00FFFFFF,
|
||||
Metric: binary.BigEndian.Uint32(data[24:28]) & 0x00FFFFFF,
|
||||
DestinationRouterID: binary.BigEndian.Uint32(data[28:32]),
|
||||
}
|
||||
case ASExternalLSAtype:
|
||||
fallthrough
|
||||
case NSSALSAtype:
|
||||
|
||||
flags := uint8(data[20])
|
||||
prefixLen := uint8(data[24]) / 8
|
||||
var forwardingAddress []byte
|
||||
if (flags & 0x02) == 0x02 {
|
||||
forwardingAddress = data[28+uint32(prefixLen) : 28+uint32(prefixLen)+16]
|
||||
}
|
||||
content = ASExternalLSA{
|
||||
Flags: flags,
|
||||
Metric: binary.BigEndian.Uint32(data[20:24]) & 0x00FFFFFF,
|
||||
PrefixLength: prefixLen,
|
||||
PrefixOptions: uint8(data[25]),
|
||||
RefLSType: binary.BigEndian.Uint16(data[26:28]),
|
||||
AddressPrefix: data[28 : 28+uint32(prefixLen)],
|
||||
ForwardingAddress: forwardingAddress,
|
||||
}
|
||||
case LinkLSAtype:
|
||||
var prefixes []Prefix
|
||||
var prefixOffset uint32 = 44
|
||||
var j uint32
|
||||
numOfPrefixes := binary.BigEndian.Uint32(data[40:44])
|
||||
for j = 0; j < numOfPrefixes; j++ {
|
||||
prefixLen := uint8(data[prefixOffset])
|
||||
prefix := Prefix{
|
||||
PrefixLength: prefixLen,
|
||||
PrefixOptions: uint8(data[prefixOffset+1]),
|
||||
AddressPrefix: data[prefixOffset+4 : prefixOffset+4+uint32(prefixLen)/8],
|
||||
}
|
||||
prefixes = append(prefixes, prefix)
|
||||
prefixOffset = prefixOffset + 4 + uint32(prefixLen)/8
|
||||
}
|
||||
content = LinkLSA{
|
||||
RtrPriority: uint8(data[20]),
|
||||
Options: binary.BigEndian.Uint32(data[20:24]) & 0x00FFFFFF,
|
||||
LinkLocalAddress: data[24:40],
|
||||
NumOfPrefixes: numOfPrefixes,
|
||||
Prefixes: prefixes,
|
||||
}
|
||||
case IntraAreaPrefixLSAtype:
|
||||
var prefixes []Prefix
|
||||
var prefixOffset uint32 = 32
|
||||
var j uint16
|
||||
numOfPrefixes := binary.BigEndian.Uint16(data[20:22])
|
||||
for j = 0; j < numOfPrefixes; j++ {
|
||||
prefixLen := uint8(data[prefixOffset])
|
||||
prefix := Prefix{
|
||||
PrefixLength: prefixLen,
|
||||
PrefixOptions: uint8(data[prefixOffset+1]),
|
||||
Metric: binary.BigEndian.Uint16(data[prefixOffset+2 : prefixOffset+4]),
|
||||
AddressPrefix: data[prefixOffset+4 : prefixOffset+4+uint32(prefixLen)/8],
|
||||
}
|
||||
prefixes = append(prefixes, prefix)
|
||||
prefixOffset = prefixOffset + 4 + uint32(prefixLen)
|
||||
}
|
||||
content = IntraAreaPrefixLSA{
|
||||
NumOfPrefixes: numOfPrefixes,
|
||||
RefLSType: binary.BigEndian.Uint16(data[22:24]),
|
||||
RefLinkStateID: binary.BigEndian.Uint32(data[24:28]),
|
||||
RefAdvRouter: binary.BigEndian.Uint32(data[28:32]),
|
||||
Prefixes: prefixes,
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("Unknown Link State type.")
|
||||
}
|
||||
return content, nil
|
||||
}
|
||||
|
||||
// getLSAs parses the LSA information from the packet for OSPFv3
|
||||
func getLSAs(num uint32, data []byte) ([]LSA, error) {
|
||||
var lsas []LSA
|
||||
var i uint32 = 0
|
||||
var offset uint32 = 0
|
||||
for ; i < num; i++ {
|
||||
var content interface{}
|
||||
lstype := binary.BigEndian.Uint16(data[offset+2 : offset+4])
|
||||
lsalength := binary.BigEndian.Uint16(data[offset+18 : offset+20])
|
||||
|
||||
content, err := extractLSAInformation(lstype, lsalength, data[offset:])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not extract Link State type.")
|
||||
}
|
||||
lsa := LSA{
|
||||
LSAheader: LSAheader{
|
||||
LSAge: binary.BigEndian.Uint16(data[offset : offset+2]),
|
||||
LSType: lstype,
|
||||
LinkStateID: binary.BigEndian.Uint32(data[offset+4 : offset+8]),
|
||||
AdvRouter: binary.BigEndian.Uint32(data[offset+8 : offset+12]),
|
||||
LSSeqNumber: binary.BigEndian.Uint32(data[offset+12 : offset+16]),
|
||||
LSChecksum: binary.BigEndian.Uint16(data[offset+16 : offset+18]),
|
||||
Length: lsalength,
|
||||
},
|
||||
Content: content,
|
||||
}
|
||||
lsas = append(lsas, lsa)
|
||||
offset += uint32(lsalength)
|
||||
}
|
||||
return lsas, nil
|
||||
}
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into the OSPF layer.
|
||||
func (ospf *OSPFv2) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
if len(data) < 24 {
|
||||
return fmt.Errorf("Packet too smal for OSPF Version 2")
|
||||
}
|
||||
|
||||
ospf.Version = uint8(data[0])
|
||||
ospf.Type = OSPFType(data[1])
|
||||
ospf.PacketLength = binary.BigEndian.Uint16(data[2:4])
|
||||
ospf.RouterID = binary.BigEndian.Uint32(data[4:8])
|
||||
ospf.AreaID = binary.BigEndian.Uint32(data[8:12])
|
||||
ospf.Checksum = binary.BigEndian.Uint16(data[12:14])
|
||||
ospf.AuType = binary.BigEndian.Uint16(data[14:16])
|
||||
ospf.Authentication = binary.BigEndian.Uint64(data[16:24])
|
||||
|
||||
switch ospf.Type {
|
||||
case OSPFHello:
|
||||
var neighbors []uint32
|
||||
for i := 44; uint16(i+4) <= ospf.PacketLength; i += 4 {
|
||||
neighbors = append(neighbors, binary.BigEndian.Uint32(data[i:i+4]))
|
||||
}
|
||||
ospf.Content = HelloPkgV2{
|
||||
NetworkMask: binary.BigEndian.Uint32(data[24:28]),
|
||||
HelloPkg: HelloPkg{
|
||||
HelloInterval: binary.BigEndian.Uint16(data[28:30]),
|
||||
Options: uint32(data[30]),
|
||||
RtrPriority: uint8(data[31]),
|
||||
RouterDeadInterval: binary.BigEndian.Uint32(data[32:36]),
|
||||
DesignatedRouterID: binary.BigEndian.Uint32(data[36:40]),
|
||||
BackupDesignatedRouterID: binary.BigEndian.Uint32(data[40:44]),
|
||||
NeighborID: neighbors,
|
||||
},
|
||||
}
|
||||
case OSPFDatabaseDescription:
|
||||
var lsas []LSAheader
|
||||
for i := 32; uint16(i+20) <= ospf.PacketLength; i += 20 {
|
||||
lsa := LSAheader{
|
||||
LSAge: binary.BigEndian.Uint16(data[i : i+2]),
|
||||
LSType: binary.BigEndian.Uint16(data[i+2 : i+4]),
|
||||
LinkStateID: binary.BigEndian.Uint32(data[i+4 : i+8]),
|
||||
AdvRouter: binary.BigEndian.Uint32(data[i+8 : i+12]),
|
||||
LSSeqNumber: binary.BigEndian.Uint32(data[i+12 : i+16]),
|
||||
LSChecksum: binary.BigEndian.Uint16(data[i+16 : i+18]),
|
||||
Length: binary.BigEndian.Uint16(data[i+18 : i+20]),
|
||||
}
|
||||
lsas = append(lsas, lsa)
|
||||
}
|
||||
ospf.Content = DbDescPkg{
|
||||
InterfaceMTU: binary.BigEndian.Uint16(data[24:26]),
|
||||
Options: uint32(data[26]),
|
||||
Flags: uint16(data[27]),
|
||||
DDSeqNumber: binary.BigEndian.Uint32(data[28:32]),
|
||||
LSAinfo: lsas,
|
||||
}
|
||||
case OSPFLinkStateRequest:
|
||||
var lsrs []LSReq
|
||||
for i := 24; uint16(i+12) <= ospf.PacketLength; i += 12 {
|
||||
lsr := LSReq{
|
||||
LSType: binary.BigEndian.Uint16(data[i+2 : i+4]),
|
||||
LSID: binary.BigEndian.Uint32(data[i+4 : i+8]),
|
||||
AdvRouter: binary.BigEndian.Uint32(data[i+8 : i+12]),
|
||||
}
|
||||
lsrs = append(lsrs, lsr)
|
||||
}
|
||||
ospf.Content = lsrs
|
||||
case OSPFLinkStateUpdate:
|
||||
num := binary.BigEndian.Uint32(data[24:28])
|
||||
|
||||
lsas, err := getLSAsv2(num, data[28:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot parse Link State Update packet: %v", err)
|
||||
}
|
||||
ospf.Content = LSUpdate{
|
||||
NumOfLSAs: num,
|
||||
LSAs: lsas,
|
||||
}
|
||||
case OSPFLinkStateAcknowledgment:
|
||||
var lsas []LSAheader
|
||||
for i := 24; uint16(i+20) <= ospf.PacketLength; i += 20 {
|
||||
lsa := LSAheader{
|
||||
LSAge: binary.BigEndian.Uint16(data[i : i+2]),
|
||||
LSOptions: data[i+2],
|
||||
LSType: uint16(data[i+3]),
|
||||
LinkStateID: binary.BigEndian.Uint32(data[i+4 : i+8]),
|
||||
AdvRouter: binary.BigEndian.Uint32(data[i+8 : i+12]),
|
||||
LSSeqNumber: binary.BigEndian.Uint32(data[i+12 : i+16]),
|
||||
LSChecksum: binary.BigEndian.Uint16(data[i+16 : i+18]),
|
||||
Length: binary.BigEndian.Uint16(data[i+18 : i+20]),
|
||||
}
|
||||
lsas = append(lsas, lsa)
|
||||
}
|
||||
ospf.Content = lsas
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DecodeFromBytes decodes the given bytes into the OSPF layer.
|
||||
func (ospf *OSPFv3) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
|
||||
if len(data) < 16 {
|
||||
return fmt.Errorf("Packet too smal for OSPF Version 3")
|
||||
}
|
||||
|
||||
ospf.Version = uint8(data[0])
|
||||
ospf.Type = OSPFType(data[1])
|
||||
ospf.PacketLength = binary.BigEndian.Uint16(data[2:4])
|
||||
ospf.RouterID = binary.BigEndian.Uint32(data[4:8])
|
||||
ospf.AreaID = binary.BigEndian.Uint32(data[8:12])
|
||||
ospf.Checksum = binary.BigEndian.Uint16(data[12:14])
|
||||
ospf.Instance = uint8(data[14])
|
||||
ospf.Reserved = uint8(data[15])
|
||||
|
||||
switch ospf.Type {
|
||||
case OSPFHello:
|
||||
var neighbors []uint32
|
||||
for i := 36; uint16(i+4) <= ospf.PacketLength; i += 4 {
|
||||
neighbors = append(neighbors, binary.BigEndian.Uint32(data[i:i+4]))
|
||||
}
|
||||
ospf.Content = HelloPkg{
|
||||
InterfaceID: binary.BigEndian.Uint32(data[16:20]),
|
||||
RtrPriority: uint8(data[20]),
|
||||
Options: binary.BigEndian.Uint32(data[21:25]) >> 8,
|
||||
HelloInterval: binary.BigEndian.Uint16(data[24:26]),
|
||||
RouterDeadInterval: uint32(binary.BigEndian.Uint16(data[26:28])),
|
||||
DesignatedRouterID: binary.BigEndian.Uint32(data[28:32]),
|
||||
BackupDesignatedRouterID: binary.BigEndian.Uint32(data[32:36]),
|
||||
NeighborID: neighbors,
|
||||
}
|
||||
case OSPFDatabaseDescription:
|
||||
var lsas []LSAheader
|
||||
for i := 28; uint16(i+20) <= ospf.PacketLength; i += 20 {
|
||||
lsa := LSAheader{
|
||||
LSAge: binary.BigEndian.Uint16(data[i : i+2]),
|
||||
LSType: binary.BigEndian.Uint16(data[i+2 : i+4]),
|
||||
LinkStateID: binary.BigEndian.Uint32(data[i+4 : i+8]),
|
||||
AdvRouter: binary.BigEndian.Uint32(data[i+8 : i+12]),
|
||||
LSSeqNumber: binary.BigEndian.Uint32(data[i+12 : i+16]),
|
||||
LSChecksum: binary.BigEndian.Uint16(data[i+16 : i+18]),
|
||||
Length: binary.BigEndian.Uint16(data[i+18 : i+20]),
|
||||
}
|
||||
lsas = append(lsas, lsa)
|
||||
}
|
||||
ospf.Content = DbDescPkg{
|
||||
Options: binary.BigEndian.Uint32(data[16:20]) & 0x00FFFFFF,
|
||||
InterfaceMTU: binary.BigEndian.Uint16(data[20:22]),
|
||||
Flags: binary.BigEndian.Uint16(data[22:24]),
|
||||
DDSeqNumber: binary.BigEndian.Uint32(data[24:28]),
|
||||
LSAinfo: lsas,
|
||||
}
|
||||
case OSPFLinkStateRequest:
|
||||
var lsrs []LSReq
|
||||
for i := 16; uint16(i+12) <= ospf.PacketLength; i += 12 {
|
||||
lsr := LSReq{
|
||||
LSType: binary.BigEndian.Uint16(data[i+2 : i+4]),
|
||||
LSID: binary.BigEndian.Uint32(data[i+4 : i+8]),
|
||||
AdvRouter: binary.BigEndian.Uint32(data[i+8 : i+12]),
|
||||
}
|
||||
lsrs = append(lsrs, lsr)
|
||||
}
|
||||
ospf.Content = lsrs
|
||||
case OSPFLinkStateUpdate:
|
||||
num := binary.BigEndian.Uint32(data[16:20])
|
||||
lsas, err := getLSAs(num, data[20:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot parse Link State Update packet: %v", err)
|
||||
}
|
||||
ospf.Content = LSUpdate{
|
||||
NumOfLSAs: num,
|
||||
LSAs: lsas,
|
||||
}
|
||||
|
||||
case OSPFLinkStateAcknowledgment:
|
||||
var lsas []LSAheader
|
||||
for i := 16; uint16(i+20) <= ospf.PacketLength; i += 20 {
|
||||
lsa := LSAheader{
|
||||
LSAge: binary.BigEndian.Uint16(data[i : i+2]),
|
||||
LSType: binary.BigEndian.Uint16(data[i+2 : i+4]),
|
||||
LinkStateID: binary.BigEndian.Uint32(data[i+4 : i+8]),
|
||||
AdvRouter: binary.BigEndian.Uint32(data[i+8 : i+12]),
|
||||
LSSeqNumber: binary.BigEndian.Uint32(data[i+12 : i+16]),
|
||||
LSChecksum: binary.BigEndian.Uint16(data[i+16 : i+18]),
|
||||
Length: binary.BigEndian.Uint16(data[i+18 : i+20]),
|
||||
}
|
||||
lsas = append(lsas, lsa)
|
||||
}
|
||||
ospf.Content = lsas
|
||||
default:
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LayerType returns LayerTypeOSPF
|
||||
func (ospf *OSPFv2) LayerType() gopacket.LayerType {
|
||||
return LayerTypeOSPF
|
||||
}
|
||||
func (ospf *OSPFv3) LayerType() gopacket.LayerType {
|
||||
return LayerTypeOSPF
|
||||
}
|
||||
|
||||
// NextLayerType returns the layer type contained by this DecodingLayer.
|
||||
func (ospf *OSPFv2) NextLayerType() gopacket.LayerType {
|
||||
return gopacket.LayerTypeZero
|
||||
}
|
||||
func (ospf *OSPFv3) NextLayerType() gopacket.LayerType {
|
||||
return gopacket.LayerTypeZero
|
||||
}
|
||||
|
||||
// CanDecode returns the set of layer types that this DecodingLayer can decode.
|
||||
func (ospf *OSPFv2) CanDecode() gopacket.LayerClass {
|
||||
return LayerTypeOSPF
|
||||
}
|
||||
func (ospf *OSPFv3) CanDecode() gopacket.LayerClass {
|
||||
return LayerTypeOSPF
|
||||
}
|
||||
|
||||
func decodeOSPF(data []byte, p gopacket.PacketBuilder) error {
|
||||
if len(data) < 14 {
|
||||
return fmt.Errorf("Packet too smal for OSPF")
|
||||
}
|
||||
|
||||
switch uint8(data[0]) {
|
||||
case 2:
|
||||
ospf := &OSPFv2{}
|
||||
return decodingLayerDecoder(ospf, data, p)
|
||||
case 3:
|
||||
ospf := &OSPFv3{}
|
||||
return decodingLayerDecoder(ospf, data, p)
|
||||
default:
|
||||
}
|
||||
|
||||
return fmt.Errorf("Unable to determine OSPF type.")
|
||||
}
|
5
vendor/github.com/google/gopacket/layers/ports.go
generated
vendored
5
vendor/github.com/google/gopacket/layers/ports.go
generated
vendored
|
@ -98,8 +98,13 @@ var udpPortLayerType = [65536]gopacket.LayerType{
|
|||
4789: LayerTypeVXLAN,
|
||||
67: LayerTypeDHCPv4,
|
||||
68: LayerTypeDHCPv4,
|
||||
546: LayerTypeDHCPv6,
|
||||
547: LayerTypeDHCPv6,
|
||||
5060: LayerTypeSIP,
|
||||
6343: LayerTypeSFlow,
|
||||
6081: LayerTypeGeneve,
|
||||
3784: LayerTypeBFD,
|
||||
2152: LayerTypeGTPv1U,
|
||||
}
|
||||
|
||||
// RegisterUDPPortLayerType creates a new mapping between a UDPPort
|
||||
|
|
32
vendor/github.com/google/gopacket/layers/radiotap.go
generated
vendored
32
vendor/github.com/google/gopacket/layers/radiotap.go
generated
vendored
|
@ -859,12 +859,36 @@ func (m *RadioTap) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) erro
|
|||
}
|
||||
|
||||
payload := data[m.Length:]
|
||||
if !m.Flags.FCS() { // Dot11.DecodeFromBytes() expects FCS present
|
||||
fcs := make([]byte, 4)
|
||||
|
||||
// Remove non standard padding used by some Wi-Fi drivers
|
||||
if m.Flags.Datapad() &&
|
||||
payload[0]&0xC == 0x8 { //&& // Data frame
|
||||
headlen := 24
|
||||
if payload[0]&0x8C == 0x88 { // QoS
|
||||
headlen += 2
|
||||
}
|
||||
if payload[1]&0x3 == 0x3 { // 4 addresses
|
||||
headlen += 2
|
||||
}
|
||||
if headlen%4 == 2 {
|
||||
payload = append(payload[:headlen], payload[headlen+2:len(payload)]...)
|
||||
}
|
||||
}
|
||||
|
||||
if !m.Flags.FCS() {
|
||||
// Dot11.DecodeFromBytes() expects FCS present and performs a hard chop on the checksum
|
||||
// If a user is handing in subslices or packets from a buffered stream, the capacity of the slice
|
||||
// may extend beyond the len, rather than expecting callers to enforce cap==len on every packet
|
||||
// we take the hit in this one case and do a reallocation. If the user DOES enforce cap==len
|
||||
// then the reallocation will happen anyway on the append. This is requried because the append
|
||||
// write to the memory directly after the payload if there is sufficient capacity, which callers
|
||||
// may not expect.
|
||||
reallocPayload := make([]byte, len(payload)+4)
|
||||
copy(reallocPayload[0:len(payload)], payload)
|
||||
h := crc32.NewIEEE()
|
||||
h.Write(payload)
|
||||
binary.LittleEndian.PutUint32(fcs, h.Sum32())
|
||||
payload = append(payload, fcs...)
|
||||
binary.LittleEndian.PutUint32(reallocPayload[len(payload):], h.Sum32())
|
||||
payload = reallocPayload
|
||||
}
|
||||
m.BaseLayer = BaseLayer{Contents: data[:m.Length], Payload: payload}
|
||||
|
||||
|
|
531
vendor/github.com/google/gopacket/layers/sip.go
generated
vendored
Normal file
531
vendor/github.com/google/gopacket/layers/sip.go
generated
vendored
Normal file
|
@ -0,0 +1,531 @@
|
|||
// Copyright 2017 Google, Inc. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree.
|
||||
|
||||
package layers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
)
|
||||
|
||||
// SIPVersion defines the different versions of the SIP Protocol
|
||||
type SIPVersion uint8
|
||||
|
||||
// Represents all the versions of SIP protocol
|
||||
const (
|
||||
SIPVersion1 SIPVersion = 1
|
||||
SIPVersion2 SIPVersion = 2
|
||||
)
|
||||
|
||||
func (sv SIPVersion) String() string {
|
||||
switch sv {
|
||||
default:
|
||||
// Defaulting to SIP/2.0
|
||||
return "SIP/2.0"
|
||||
case SIPVersion1:
|
||||
return "SIP/1.0"
|
||||
case SIPVersion2:
|
||||
return "SIP/2.0"
|
||||
}
|
||||
}
|
||||
|
||||
// GetSIPVersion is used to get SIP version constant
|
||||
func GetSIPVersion(version string) (SIPVersion, error) {
|
||||
switch strings.ToUpper(version) {
|
||||
case "SIP/1.0":
|
||||
return SIPVersion1, nil
|
||||
case "SIP/2.0":
|
||||
return SIPVersion2, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("Unknown SIP version: '%s'", version)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SIPMethod defines the different methods of the SIP Protocol
|
||||
// defined in the different RFC's
|
||||
type SIPMethod uint16
|
||||
|
||||
// Here are all the SIP methods
|
||||
const (
|
||||
SIPMethodInvite SIPMethod = 1 // INVITE [RFC3261]
|
||||
SIPMethodAck SIPMethod = 2 // ACK [RFC3261]
|
||||
SIPMethodBye SIPMethod = 3 // BYE [RFC3261]
|
||||
SIPMethodCancel SIPMethod = 4 // CANCEL [RFC3261]
|
||||
SIPMethodOptions SIPMethod = 5 // OPTIONS [RFC3261]
|
||||
SIPMethodRegister SIPMethod = 6 // REGISTER [RFC3261]
|
||||
SIPMethodPrack SIPMethod = 7 // PRACK [RFC3262]
|
||||
SIPMethodSubscribe SIPMethod = 8 // SUBSCRIBE [RFC6665]
|
||||
SIPMethodNotify SIPMethod = 9 // NOTIFY [RFC6665]
|
||||
SIPMethodPublish SIPMethod = 10 // PUBLISH [RFC3903]
|
||||
SIPMethodInfo SIPMethod = 11 // INFO [RFC6086]
|
||||
SIPMethodRefer SIPMethod = 12 // REFER [RFC3515]
|
||||
SIPMethodMessage SIPMethod = 13 // MESSAGE [RFC3428]
|
||||
SIPMethodUpdate SIPMethod = 14 // UPDATE [RFC3311]
|
||||
SIPMethodPing SIPMethod = 15 // PING [https://tools.ietf.org/html/draft-fwmiller-ping-03]
|
||||
)
|
||||
|
||||
func (sm SIPMethod) String() string {
|
||||
switch sm {
|
||||
default:
|
||||
return "Unknown method"
|
||||
case SIPMethodInvite:
|
||||
return "INVITE"
|
||||
case SIPMethodAck:
|
||||
return "ACK"
|
||||
case SIPMethodBye:
|
||||
return "BYE"
|
||||
case SIPMethodCancel:
|
||||
return "CANCEL"
|
||||
case SIPMethodOptions:
|
||||
return "OPTIONS"
|
||||
case SIPMethodRegister:
|
||||
return "REGISTER"
|
||||
case SIPMethodPrack:
|
||||
return "PRACK"
|
||||
case SIPMethodSubscribe:
|
||||
return "SUBSCRIBE"
|
||||
case SIPMethodNotify:
|
||||
return "NOTIFY"
|
||||
case SIPMethodPublish:
|
||||
return "PUBLISH"
|
||||
case SIPMethodInfo:
|
||||
return "INFO"
|
||||
case SIPMethodRefer:
|
||||
return "REFER"
|
||||
case SIPMethodMessage:
|
||||
return "MESSAGE"
|
||||
case SIPMethodUpdate:
|
||||
return "UPDATE"
|
||||
case SIPMethodPing:
|
||||
return "PING"
|
||||
}
|
||||
}
|
||||
|
||||
// GetSIPMethod returns the constant of a SIP method
|
||||
// from its string
|
||||
func GetSIPMethod(method string) (SIPMethod, error) {
|
||||
switch strings.ToUpper(method) {
|
||||
case "INVITE":
|
||||
return SIPMethodInvite, nil
|
||||
case "ACK":
|
||||
return SIPMethodAck, nil
|
||||
case "BYE":
|
||||
return SIPMethodBye, nil
|
||||
case "CANCEL":
|
||||
return SIPMethodCancel, nil
|
||||
case "OPTIONS":
|
||||
return SIPMethodOptions, nil
|
||||
case "REGISTER":
|
||||
return SIPMethodRegister, nil
|
||||
case "PRACK":
|
||||
return SIPMethodPrack, nil
|
||||
case "SUBSCRIBE":
|
||||
return SIPMethodSubscribe, nil
|
||||
case "NOTIFY":
|
||||
return SIPMethodNotify, nil
|
||||
case "PUBLISH":
|
||||
return SIPMethodPublish, nil
|
||||
case "INFO":
|
||||
return SIPMethodInfo, nil
|
||||
case "REFER":
|
||||
return SIPMethodRefer, nil
|
||||
case "MESSAGE":
|
||||
return SIPMethodMessage, nil
|
||||
case "UPDATE":
|
||||
return SIPMethodUpdate, nil
|
||||
case "PING":
|
||||
return SIPMethodPing, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("Unknown SIP method: '%s'", method)
|
||||
}
|
||||
}
|
||||
|
||||
// Here is a correspondance between long header names and short
|
||||
// as defined in rfc3261 in section 20
|
||||
var compactSipHeadersCorrespondance = map[string]string{
|
||||
"accept-contact": "a",
|
||||
"allow-events": "u",
|
||||
"call-id": "i",
|
||||
"contact": "m",
|
||||
"content-encoding": "e",
|
||||
"content-length": "l",
|
||||
"content-type": "c",
|
||||
"event": "o",
|
||||
"from": "f",
|
||||
"identity": "y",
|
||||
"refer-to": "r",
|
||||
"referred-by": "b",
|
||||
"reject-contact": "j",
|
||||
"request-disposition": "d",
|
||||
"session-expires": "x",
|
||||
"subject": "s",
|
||||
"supported": "k",
|
||||
"to": "t",
|
||||
"via": "v",
|
||||
}
|
||||
|
||||
// SIP object will contains information about decoded SIP packet.
|
||||
// -> The SIP Version
|
||||
// -> The SIP Headers (in a map[string][]string because of multiple headers with the same name
|
||||
// -> The SIP Method
|
||||
// -> The SIP Response code (if it's a response)
|
||||
// -> The SIP Status line (if it's a response)
|
||||
// You can easily know the type of the packet with the IsResponse boolean
|
||||
//
|
||||
type SIP struct {
|
||||
BaseLayer
|
||||
|
||||
// Base information
|
||||
Version SIPVersion
|
||||
Method SIPMethod
|
||||
Headers map[string][]string
|
||||
|
||||
// Response
|
||||
IsResponse bool
|
||||
ResponseCode int
|
||||
ResponseStatus string
|
||||
|
||||
// Private fields
|
||||
cseq int64
|
||||
contentLength int64
|
||||
lastHeaderParsed string
|
||||
}
|
||||
|
||||
// decodeSIP decodes the byte slice into a SIP type. It also
|
||||
// setups the application Layer in PacketBuilder.
|
||||
func decodeSIP(data []byte, p gopacket.PacketBuilder) error {
|
||||
s := NewSIP()
|
||||
err := s.DecodeFromBytes(data, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.AddLayer(s)
|
||||
p.SetApplicationLayer(s)
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewSIP instantiates a new empty SIP object
|
||||
func NewSIP() *SIP {
|
||||
s := new(SIP)
|
||||
s.Headers = make(map[string][]string)
|
||||
return s
|
||||
}
|
||||
|
||||
// LayerType returns gopacket.LayerTypeSIP.
|
||||
func (s *SIP) LayerType() gopacket.LayerType {
|
||||
return LayerTypeSIP
|
||||
}
|
||||
|
||||
// Payload returns the base layer payload
|
||||
func (s *SIP) Payload() []byte {
|
||||
return s.BaseLayer.Payload
|
||||
}
|
||||
|
||||
// DecodeFromBytes decodes the slice into the SIP struct.
|
||||
func (s *SIP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
||||
|
||||
// Init some vars for parsing follow-up
|
||||
var countLines int
|
||||
var line []byte
|
||||
var err error
|
||||
|
||||
// Clean leading new line
|
||||
data = bytes.Trim(data, "\n")
|
||||
|
||||
// Iterate on all lines of the SIP Headers
|
||||
// and stop when we reach the SDP (aka when the new line
|
||||
// is at index 0 of the remaining packet)
|
||||
buffer := bytes.NewBuffer(data)
|
||||
|
||||
for {
|
||||
|
||||
// Read next line
|
||||
line, err = buffer.ReadBytes(byte('\n'))
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Trim the new line delimiters
|
||||
line = bytes.Trim(line, "\r\n")
|
||||
|
||||
// Empty line, we hit Body
|
||||
// Putting packet remain in Paypload
|
||||
if len(line) == 0 {
|
||||
s.BaseLayer.Payload = buffer.Bytes()
|
||||
break
|
||||
}
|
||||
|
||||
// First line is the SIP request/response line
|
||||
// Other lines are headers
|
||||
if countLines == 0 {
|
||||
err = s.ParseFirstLine(line)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
} else {
|
||||
err = s.ParseHeader(line)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
countLines++
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ParseFirstLine will compute the first line of a SIP packet.
|
||||
// The first line will tell us if it's a request or a response.
|
||||
//
|
||||
// Examples of first line of SIP Prococol :
|
||||
//
|
||||
// Request : INVITE bob@example.com SIP/2.0
|
||||
// Response : SIP/2.0 200 OK
|
||||
// Response : SIP/2.0 501 Not Implemented
|
||||
//
|
||||
func (s *SIP) ParseFirstLine(firstLine []byte) error {
|
||||
|
||||
var err error
|
||||
|
||||
// Splits line by space
|
||||
splits := strings.SplitN(string(firstLine), " ", 3)
|
||||
|
||||
// We must have at least 3 parts
|
||||
if len(splits) < 3 {
|
||||
return fmt.Errorf("invalid first SIP line: '%s'", string(firstLine))
|
||||
}
|
||||
|
||||
// Determine the SIP packet type
|
||||
if strings.HasPrefix(splits[0], "SIP") {
|
||||
|
||||
// --> Response
|
||||
s.IsResponse = true
|
||||
|
||||
// Validate SIP Version
|
||||
s.Version, err = GetSIPVersion(splits[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Compute code
|
||||
s.ResponseCode, err = strconv.Atoi(splits[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Compute status line
|
||||
s.ResponseStatus = splits[2]
|
||||
|
||||
} else {
|
||||
|
||||
// --> Request
|
||||
|
||||
// Validate method
|
||||
s.Method, err = GetSIPMethod(splits[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Validate SIP Version
|
||||
s.Version, err = GetSIPVersion(splits[2])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ParseHeader will parse a SIP Header
|
||||
// SIP Headers are quite simple, there are colon separated name and value
|
||||
// Headers can be spread over multiple lines
|
||||
//
|
||||
// Examples of header :
|
||||
//
|
||||
// CSeq: 1 REGISTER
|
||||
// Via: SIP/2.0/UDP there.com:5060
|
||||
// Authorization:Digest username="UserB",
|
||||
// realm="MCI WorldCom SIP",
|
||||
// nonce="1cec4341ae6cbe5a359ea9c8e88df84f", opaque="",
|
||||
// uri="sip:ss2.wcom.com", response="71ba27c64bd01de719686aa4590d5824"
|
||||
//
|
||||
func (s *SIP) ParseHeader(header []byte) (err error) {
|
||||
|
||||
// Ignore empty headers
|
||||
if len(header) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if this is the following of last header
|
||||
// RFC 3261 - 7.3.1 - Header Field Format specify that following lines of
|
||||
// multiline headers must begin by SP or TAB
|
||||
if header[0] == '\t' || header[0] == ' ' {
|
||||
|
||||
header = bytes.TrimSpace(header)
|
||||
s.Headers[s.lastHeaderParsed][len(s.Headers[s.lastHeaderParsed])-1] += fmt.Sprintf(" %s", string(header))
|
||||
return
|
||||
}
|
||||
|
||||
// Find the ':' to separate header name and value
|
||||
index := bytes.Index(header, []byte(":"))
|
||||
if index >= 0 {
|
||||
|
||||
headerName := strings.ToLower(string(bytes.Trim(header[:index], " ")))
|
||||
headerValue := string(bytes.Trim(header[index+1:], " "))
|
||||
|
||||
// Add header to object
|
||||
s.Headers[headerName] = append(s.Headers[headerName], headerValue)
|
||||
s.lastHeaderParsed = headerName
|
||||
|
||||
// Compute specific headers
|
||||
err = s.ParseSpecificHeaders(headerName, headerValue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ParseSpecificHeaders will parse some specific key values from
|
||||
// specific headers like CSeq or Content-Length integer values
|
||||
func (s *SIP) ParseSpecificHeaders(headerName string, headerValue string) (err error) {
|
||||
|
||||
switch headerName {
|
||||
case "cseq":
|
||||
|
||||
// CSeq header value is formatted like that :
|
||||
// CSeq: 123 INVITE
|
||||
// We split the value to parse Cseq integer value, and method
|
||||
splits := strings.Split(headerValue, " ")
|
||||
if len(splits) > 1 {
|
||||
|
||||
// Parse Cseq
|
||||
s.cseq, err = strconv.ParseInt(splits[0], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Validate method
|
||||
if s.IsResponse {
|
||||
s.Method, err = GetSIPMethod(splits[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case "content-length":
|
||||
|
||||
// Parse Content-Length
|
||||
s.contentLength, err = strconv.ParseInt(headerValue, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAllHeaders will return the full headers of the
|
||||
// current SIP packets in a map[string][]string
|
||||
func (s *SIP) GetAllHeaders() map[string][]string {
|
||||
return s.Headers
|
||||
}
|
||||
|
||||
// GetHeader will return all the headers with
|
||||
// the specified name.
|
||||
func (s *SIP) GetHeader(headerName string) []string {
|
||||
headerName = strings.ToLower(headerName)
|
||||
h := make([]string, 0)
|
||||
if _, ok := s.Headers[headerName]; ok {
|
||||
if len(s.Headers[headerName]) > 0 {
|
||||
return s.Headers[headerName]
|
||||
} else if len(s.Headers[compactSipHeadersCorrespondance[headerName]]) > 0 {
|
||||
return s.Headers[compactSipHeadersCorrespondance[headerName]]
|
||||
}
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
// GetFirstHeader will return the first header with
|
||||
// the specified name. If the current SIP packet has multiple
|
||||
// headers with the same name, it returns the first.
|
||||
func (s *SIP) GetFirstHeader(headerName string) string {
|
||||
headerName = strings.ToLower(headerName)
|
||||
if _, ok := s.Headers[headerName]; ok {
|
||||
if len(s.Headers[headerName]) > 0 {
|
||||
return s.Headers[headerName][0]
|
||||
} else if len(s.Headers[compactSipHeadersCorrespondance[headerName]]) > 0 {
|
||||
return s.Headers[compactSipHeadersCorrespondance[headerName]][0]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
//
|
||||
// Some handy getters for most used SIP headers
|
||||
//
|
||||
|
||||
// GetAuthorization will return the Authorization
|
||||
// header of the current SIP packet
|
||||
func (s *SIP) GetAuthorization() string {
|
||||
return s.GetFirstHeader("Authorization")
|
||||
}
|
||||
|
||||
// GetFrom will return the From
|
||||
// header of the current SIP packet
|
||||
func (s *SIP) GetFrom() string {
|
||||
return s.GetFirstHeader("From")
|
||||
}
|
||||
|
||||
// GetTo will return the To
|
||||
// header of the current SIP packet
|
||||
func (s *SIP) GetTo() string {
|
||||
return s.GetFirstHeader("To")
|
||||
}
|
||||
|
||||
// GetContact will return the Contact
|
||||
// header of the current SIP packet
|
||||
func (s *SIP) GetContact() string {
|
||||
return s.GetFirstHeader("Contact")
|
||||
}
|
||||
|
||||
// GetCallID will return the Call-ID
|
||||
// header of the current SIP packet
|
||||
func (s *SIP) GetCallID() string {
|
||||
return s.GetFirstHeader("Call-ID")
|
||||
}
|
||||
|
||||
// GetUserAgent will return the User-Agent
|
||||
// header of the current SIP packet
|
||||
func (s *SIP) GetUserAgent() string {
|
||||
return s.GetFirstHeader("User-Agent")
|
||||
}
|
||||
|
||||
// GetContentLength will return the parsed integer
|
||||
// Content-Length header of the current SIP packet
|
||||
func (s *SIP) GetContentLength() int64 {
|
||||
return s.contentLength
|
||||
}
|
||||
|
||||
// GetCSeq will return the parsed integer CSeq header
|
||||
// header of the current SIP packet
|
||||
func (s *SIP) GetCSeq() int64 {
|
||||
return s.cseq
|
||||
}
|
11
vendor/github.com/google/gopacket/layers/tcp.go
generated
vendored
11
vendor/github.com/google/gopacket/layers/tcp.go
generated
vendored
|
@ -244,7 +244,12 @@ func (tcp *TCP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
|||
tcp.Window = binary.BigEndian.Uint16(data[14:16])
|
||||
tcp.Checksum = binary.BigEndian.Uint16(data[16:18])
|
||||
tcp.Urgent = binary.BigEndian.Uint16(data[18:20])
|
||||
tcp.Options = tcp.opts[:0]
|
||||
if tcp.Options == nil {
|
||||
// Pre-allocate to avoid allocating a slice.
|
||||
tcp.Options = tcp.opts[:0]
|
||||
} else {
|
||||
tcp.Options = tcp.Options[:0]
|
||||
}
|
||||
if tcp.DataOffset < 5 {
|
||||
return fmt.Errorf("Invalid TCP data offset %d < 5", tcp.DataOffset)
|
||||
}
|
||||
|
@ -260,10 +265,6 @@ func (tcp *TCP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
|
|||
// From here on, data points just to the header options.
|
||||
data = data[20:dataStart]
|
||||
for len(data) > 0 {
|
||||
if tcp.Options == nil {
|
||||
// Pre-allocate to avoid allocating a slice.
|
||||
tcp.Options = tcp.opts[:0]
|
||||
}
|
||||
tcp.Options = append(tcp.Options, TCPOption{OptionType: TCPOptionKind(data[0])})
|
||||
opt := &tcp.Options[len(tcp.Options)-1]
|
||||
switch opt.OptionType {
|
||||
|
|
8
vendor/github.com/google/gopacket/layers/udp.go
generated
vendored
8
vendor/github.com/google/gopacket/layers/udp.go
generated
vendored
|
@ -118,3 +118,11 @@ func decodeUDP(data []byte, p gopacket.PacketBuilder) error {
|
|||
func (u *UDP) TransportFlow() gopacket.Flow {
|
||||
return gopacket.NewFlow(EndpointUDPPort, u.sPort, u.dPort)
|
||||
}
|
||||
|
||||
// For testing only
|
||||
func (u *UDP) SetInternalPortsForTesting() {
|
||||
u.sPort = make([]byte, 2)
|
||||
u.dPort = make([]byte, 2)
|
||||
binary.BigEndian.PutUint16(u.sPort, uint16(u.SrcPort))
|
||||
binary.BigEndian.PutUint16(u.dPort, uint16(u.DstPort))
|
||||
}
|
||||
|
|
21
vendor/github.com/google/gopacket/layers/usb.go
generated
vendored
21
vendor/github.com/google/gopacket/layers/usb.go
generated
vendored
|
@ -81,27 +81,6 @@ const (
|
|||
USBTransportTypeBulk USBTransportType = 0x03 // Bulk transfers can be used for large bursty data, using all remaining available bandwidth, no guarantees on bandwidth or latency, such as file transfers.
|
||||
)
|
||||
|
||||
func (a USBTransportType) LayerType() gopacket.LayerType {
|
||||
return USBTypeMetadata[a].LayerType
|
||||
}
|
||||
|
||||
func (a USBTransportType) String() string {
|
||||
switch a {
|
||||
case USBTransportTypeTransferIn:
|
||||
return "Transfer In"
|
||||
case USBTransportTypeIsochronous:
|
||||
return "Isochronous"
|
||||
case USBTransportTypeInterrupt:
|
||||
return "Interrupt"
|
||||
case USBTransportTypeControl:
|
||||
return "Control"
|
||||
case USBTransportTypeBulk:
|
||||
return "Bulk"
|
||||
default:
|
||||
return "Unknown transport type"
|
||||
}
|
||||
}
|
||||
|
||||
type USBDirectionType uint8
|
||||
|
||||
const (
|
||||
|
|
4
vendor/github.com/google/gopacket/layers/vxlan.go
generated
vendored
4
vendor/github.com/google/gopacket/layers/vxlan.go
generated
vendored
|
@ -72,6 +72,10 @@ func (vx *VXLAN) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.Serialize
|
|||
return err
|
||||
}
|
||||
|
||||
// PrependBytes does not guarantee that bytes are zeroed. Setting flags via OR requires that they start off at zero
|
||||
bytes[0] = 0
|
||||
bytes[1] = 0
|
||||
|
||||
if vx.ValidIDFlag {
|
||||
bytes[0] |= 0x08
|
||||
}
|
||||
|
|
4
vendor/github.com/google/gopacket/packet.go
generated
vendored
4
vendor/github.com/google/gopacket/packet.go
generated
vendored
|
@ -31,6 +31,10 @@ type CaptureInfo struct {
|
|||
Length int
|
||||
// InterfaceIndex
|
||||
InterfaceIndex int
|
||||
// The packet source can place ancillary data of various types here.
|
||||
// For example, the afpacket source can report the VLAN of captured
|
||||
// packets this way.
|
||||
AncillaryData []interface{}
|
||||
}
|
||||
|
||||
// PacketMetadata contains metadata for a packet.
|
||||
|
|
9
vendor/github.com/google/gopacket/parser.go
generated
vendored
9
vendor/github.com/google/gopacket/parser.go
generated
vendored
|
@ -158,6 +158,9 @@ func (l *DecodingLayerParser) DecodeLayers(data []byte, decoded *[]LayerType) (e
|
|||
for len(data) > 0 {
|
||||
decoder, ok := l.decoders[typ]
|
||||
if !ok {
|
||||
if l.IgnoreUnsupported {
|
||||
return nil
|
||||
}
|
||||
return UnsupportedLayerType(typ)
|
||||
} else if err = decoder.DecodeFromBytes(data, l.df); err != nil {
|
||||
return err
|
||||
|
@ -195,4 +198,10 @@ type DecodingLayerParserOptions struct {
|
|||
// callers. IgnorePanic defaults to false, thus if the caller does
|
||||
// nothing decode panics will be returned as errors.
|
||||
IgnorePanic bool
|
||||
// IgnoreUnsupported will stop parsing and return a nil error when it
|
||||
// encounters a layer it doesn't have a parser for, instead of returning an
|
||||
// UnsupportedLayerType error. If this is true, it's up to the caller to make
|
||||
// sure that all expected layers have been parsed (by checking the decoded
|
||||
// slice).
|
||||
IgnoreUnsupported bool
|
||||
}
|
||||
|
|
148
vendor/github.com/google/gopacket/pcap/pcap.go
generated
vendored
148
vendor/github.com/google/gopacket/pcap/pcap.go
generated
vendored
|
@ -20,6 +20,7 @@ package pcap
|
|||
#cgo windows,amd64 LDFLAGS: -L C:/WpdPack/Lib/x64 -lwpcap
|
||||
#include <stdlib.h>
|
||||
#include <pcap.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Some old versions of pcap don't define this constant.
|
||||
#ifndef PCAP_NETMASK_UNKNOWN
|
||||
|
@ -83,6 +84,9 @@ int pcap_set_rfmon(pcap_t *p, int rfmon) {
|
|||
#elif __APPLE__
|
||||
#define gopacket_time_secs_t __darwin_time_t
|
||||
#define gopacket_time_usecs_t __darwin_suseconds_t
|
||||
#elif __ANDROID__
|
||||
#define gopacket_time_secs_t __kernel_time_t
|
||||
#define gopacket_time_usecs_t __kernel_suseconds_t
|
||||
#elif __GLIBC__
|
||||
#define gopacket_time_secs_t __time_t
|
||||
#define gopacket_time_usecs_t __suseconds_t
|
||||
|
@ -96,6 +100,18 @@ int pcap_set_rfmon(pcap_t *p, int rfmon) {
|
|||
#define gopacket_time_usecs_t suseconds_t
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// The things we do to avoid pointers escaping to the heap...
|
||||
// According to https://github.com/the-tcpdump-group/libpcap/blob/1131a7c26c6f4d4772e4a2beeaf7212f4dea74ac/pcap.c#L398-L406 ,
|
||||
// the return value of pcap_next_ex could be greater than 1 for success.
|
||||
// Let's just make it 1 if it comes bigger than 1.
|
||||
int pcap_next_ex_escaping(pcap_t *p, uintptr_t pkt_hdr, uintptr_t pkt_data) {
|
||||
int ex = pcap_next_ex(p, (struct pcap_pkthdr**)(pkt_hdr), (const u_char**)(pkt_data));
|
||||
if (ex > 1) {
|
||||
ex = 1;
|
||||
}
|
||||
return ex;
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
|
@ -104,6 +120,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
@ -119,6 +136,9 @@ import (
|
|||
|
||||
const errorBufferSize = 256
|
||||
|
||||
// ErrNotActive is returned if handle is not activated
|
||||
const ErrNotActive = int(C.PCAP_ERROR_NOT_ACTIVATED)
|
||||
|
||||
// MaxBpfInstructions is the maximum number of BPF instructions supported (BPF_MAXINSNS),
|
||||
// taken from Linux kernel: include/uapi/linux/bpf_common.h
|
||||
//
|
||||
|
@ -165,8 +185,8 @@ type Stats struct {
|
|||
type Interface struct {
|
||||
Name string
|
||||
Description string
|
||||
Flags uint32
|
||||
Addresses []InterfaceAddress
|
||||
// TODO: add more elements
|
||||
}
|
||||
|
||||
// Datalink describes the datalink
|
||||
|
@ -178,9 +198,10 @@ type Datalink struct {
|
|||
// InterfaceAddress describes an address associated with an Interface.
|
||||
// Currently, it's IPv4/6 specific.
|
||||
type InterfaceAddress struct {
|
||||
IP net.IP
|
||||
Netmask net.IPMask // Netmask may be nil if we were unable to retrieve it.
|
||||
// TODO: add broadcast + PtP dst ?
|
||||
IP net.IP
|
||||
Netmask net.IPMask // Netmask may be nil if we were unable to retrieve it.
|
||||
Broadaddr net.IP // Broadcast address for this IP may be nil
|
||||
P2P net.IP // P2P destination address for this IP may be nil
|
||||
}
|
||||
|
||||
// BPF is a compiled filter program, useful for offline packet matching.
|
||||
|
@ -247,9 +268,14 @@ func OpenLive(device string, snaplen int32, promisc bool, timeout time.Duration)
|
|||
return nil, errors.New(C.GoString(buf))
|
||||
}
|
||||
|
||||
if err := p.openLive(); err != nil {
|
||||
C.pcap_close(p.cptr)
|
||||
return nil, err
|
||||
// Only set the PCAP handle into non-blocking mode if we have a timeout
|
||||
// greater than zero. If the user wants to block forever, we'll let libpcap
|
||||
// handle that.
|
||||
if p.timeout > 0 {
|
||||
if err := p.setNonBlocking(); err != nil {
|
||||
C.pcap_close(p.cptr)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return p, nil
|
||||
|
@ -266,7 +292,13 @@ func OpenOffline(file string) (handle *Handle, err error) {
|
|||
if cptr == nil {
|
||||
return nil, errors.New(C.GoString(buf))
|
||||
}
|
||||
return &Handle{cptr: cptr}, nil
|
||||
h := &Handle{cptr: cptr}
|
||||
return h, nil
|
||||
}
|
||||
|
||||
// OpenOfflineFile returns contents of input file as a *Handle.
|
||||
func OpenOfflineFile(file *os.File) (handle *Handle, err error) {
|
||||
return openOfflineFile(file)
|
||||
}
|
||||
|
||||
// NextError is the return code from a call to Next.
|
||||
|
@ -325,6 +357,7 @@ const (
|
|||
aeNoSuchDevice = C.PCAP_ERROR_NO_SUCH_DEVICE
|
||||
aeDenied = C.PCAP_ERROR_PERM_DENIED
|
||||
aeNotUp = C.PCAP_ERROR_IFACE_NOT_UP
|
||||
aeWarning = C.PCAP_WARNING
|
||||
)
|
||||
|
||||
func (a activateError) Error() string {
|
||||
|
@ -341,6 +374,8 @@ func (a activateError) Error() string {
|
|||
return "Permission Denied"
|
||||
case aeNotUp:
|
||||
return "Interface Not Up"
|
||||
case aeWarning:
|
||||
return fmt.Sprintf("Warning: %v", activateErrMsg.Error())
|
||||
default:
|
||||
return fmt.Sprintf("unknown activated error: %d", a)
|
||||
}
|
||||
|
@ -353,9 +388,19 @@ func (p *Handle) getNextBufPtrLocked(ci *gopacket.CaptureInfo) error {
|
|||
return io.EOF
|
||||
}
|
||||
|
||||
// This horrible magic allows us to pass a ptr-to-ptr to pcap_next_ex
|
||||
// without causing that ptr-to-ptr to itself be allocated on the heap.
|
||||
// Since Handle itself survives through the duration of the pcap_next_ex
|
||||
// call, this should be perfectly safe for GC stuff, etc.
|
||||
pp := C.uintptr_t(uintptr(unsafe.Pointer(&p.pkthdr)))
|
||||
bp := C.uintptr_t(uintptr(unsafe.Pointer(&p.bufptr)))
|
||||
|
||||
// set after we have call waitForPacket for the first time
|
||||
var waited bool
|
||||
|
||||
for atomic.LoadUint64(&p.stop) == 0 {
|
||||
// try to read a packet if one is immediately available
|
||||
result := NextError(C.pcap_next_ex(p.cptr, &p.pkthdr, &p.bufptr))
|
||||
result := NextError(C.pcap_next_ex_escaping(p.cptr, pp, bp))
|
||||
|
||||
switch result {
|
||||
case NextErrorOk:
|
||||
|
@ -374,13 +419,18 @@ func (p *Handle) getNextBufPtrLocked(ci *gopacket.CaptureInfo) error {
|
|||
// no more packets, return EOF rather than libpcap-specific error
|
||||
return io.EOF
|
||||
case NextErrorTimeoutExpired:
|
||||
// Negative timeout means to loop forever, instead of actually returning
|
||||
// the timeout error.
|
||||
if p.timeout < 0 {
|
||||
// must have had a timeout... wait before trying again
|
||||
p.waitForPacket()
|
||||
continue
|
||||
// we've already waited for a packet and we're supposed to time out
|
||||
//
|
||||
// we should never actually hit this if we were passed BlockForever
|
||||
// since we should block on C.pcap_next_ex until there's a packet
|
||||
// to read.
|
||||
if waited && p.timeout > 0 {
|
||||
return result
|
||||
}
|
||||
|
||||
// wait for packet before trying again
|
||||
p.waitForPacket()
|
||||
waited = true
|
||||
default:
|
||||
return result
|
||||
}
|
||||
|
@ -652,6 +702,28 @@ func (p *Handle) NewBPF(expr string) (*BPF, error) {
|
|||
return bpf, nil
|
||||
}
|
||||
|
||||
// NewBPF allows to create a BPF without requiring an existing handle.
|
||||
// This allows to match packets obtained from a-non GoPacket capture source
|
||||
// to be matched.
|
||||
//
|
||||
// buf := make([]byte, MaxFrameSize)
|
||||
// bpfi, _ := pcap.NewBPF(layers.LinkTypeEthernet, MaxFrameSize, "icmp")
|
||||
// n, _ := someIO.Read(buf)
|
||||
// ci := gopacket.CaptureInfo{CaptureLength: n, Length: n}
|
||||
// if bpfi.Matches(ci, buf) {
|
||||
// doSomething()
|
||||
// }
|
||||
func NewBPF(linkType layers.LinkType, captureLength int, expr string) (*BPF, error) {
|
||||
cptr := C.pcap_open_dead(C.int(linkType), C.int(captureLength))
|
||||
if cptr == nil {
|
||||
return nil, errors.New("error opening dead capture")
|
||||
}
|
||||
|
||||
h := Handle{cptr: cptr}
|
||||
defer h.Close()
|
||||
return h.NewBPF(expr)
|
||||
}
|
||||
|
||||
// NewBPFInstructionFilter sets the given BPFInstructions as new filter program.
|
||||
//
|
||||
// More details see func SetBPFInstructionFilter
|
||||
|
@ -708,6 +780,23 @@ func (p *Handle) SetLinkType(dlt layers.LinkType) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// DatalinkValToName returns pcap_datalink_val_to_name as string
|
||||
func DatalinkValToName(dlt int) string {
|
||||
return C.GoString(C.pcap_datalink_val_to_name(C.int(dlt)))
|
||||
}
|
||||
|
||||
// DatalinkValToDescription returns pcap_datalink_val_to_description as string
|
||||
func DatalinkValToDescription(dlt int) string {
|
||||
return C.GoString(C.pcap_datalink_val_to_description(C.int(dlt)))
|
||||
}
|
||||
|
||||
// DatalinkNameToVal returns pcap_datalink_name_to_val as int
|
||||
func DatalinkNameToVal(name string) C.int {
|
||||
cptr := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cptr))
|
||||
return C.int(C.pcap_datalink_name_to_val(cptr))
|
||||
}
|
||||
|
||||
// FindAllDevs attempts to enumerate all interfaces on the current machine.
|
||||
func FindAllDevs() (ifs []Interface, err error) {
|
||||
var buf *C.char
|
||||
|
@ -731,7 +820,7 @@ func FindAllDevs() (ifs []Interface, err error) {
|
|||
iface.Name = C.GoString(dev.name)
|
||||
iface.Description = C.GoString(dev.description)
|
||||
iface.Addresses = findalladdresses(dev.addresses)
|
||||
// TODO: add more elements
|
||||
iface.Flags = uint32(dev.flags)
|
||||
ifs[j] = iface
|
||||
j++
|
||||
}
|
||||
|
@ -762,12 +851,22 @@ func findalladdresses(addresses *_Ctype_struct_pcap_addr) (retval []InterfaceAdd
|
|||
// address.
|
||||
a.Netmask = nil
|
||||
}
|
||||
if a.Broadaddr, err = sockaddrToIP((*syscall.RawSockaddr)(unsafe.Pointer(curaddr.broadaddr))); err != nil {
|
||||
a.Broadaddr = nil
|
||||
}
|
||||
if a.P2P, err = sockaddrToIP((*syscall.RawSockaddr)(unsafe.Pointer(curaddr.dstaddr))); err != nil {
|
||||
a.P2P = nil
|
||||
}
|
||||
retval = append(retval, a)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func sockaddrToIP(rsa *syscall.RawSockaddr) (IP []byte, err error) {
|
||||
if unsafe.Pointer(rsa) == nil {
|
||||
err = errors.New("Value not set")
|
||||
return
|
||||
}
|
||||
switch rsa.Family {
|
||||
case syscall.AF_INET:
|
||||
pp := (*syscall.RawSockaddrInet4)(unsafe.Pointer(rsa))
|
||||
|
@ -817,6 +916,12 @@ func (p *Handle) SetDirection(direction Direction) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// SnapLen returns the snapshot length
|
||||
func (p *Handle) SnapLen() int {
|
||||
len := C.pcap_snapshot(p.cptr)
|
||||
return int(len)
|
||||
}
|
||||
|
||||
// TimestampSource tells PCAP which type of timestamp to use for packets.
|
||||
type TimestampSource C.int
|
||||
|
||||
|
@ -851,11 +956,22 @@ type InactiveHandle struct {
|
|||
timeout time.Duration
|
||||
}
|
||||
|
||||
// holds the err messoge in case activation returned a Warning
|
||||
var activateErrMsg error
|
||||
|
||||
// Error returns the current error associated with a pcap handle (pcap_geterr).
|
||||
func (p *InactiveHandle) Error() error {
|
||||
return errors.New(C.GoString(C.pcap_geterr(p.cptr)))
|
||||
}
|
||||
|
||||
// Activate activates the handle. The current InactiveHandle becomes invalid
|
||||
// and all future function calls on it will fail.
|
||||
func (p *InactiveHandle) Activate() (*Handle, error) {
|
||||
err := activateError(C.pcap_activate(p.cptr))
|
||||
if err != aeNoError {
|
||||
if err == aeWarning {
|
||||
activateErrMsg = p.Error()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
h := &Handle{
|
||||
|
|
18
vendor/github.com/google/gopacket/pcap/pcap_unix.go
generated
vendored
18
vendor/github.com/google/gopacket/pcap/pcap_unix.go
generated
vendored
|
@ -43,10 +43,11 @@ import "C"
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func (p *Handle) openLive() error {
|
||||
func (p *Handle) setNonBlocking() error {
|
||||
buf := (*C.char)(C.calloc(errorBufferSize, 1))
|
||||
defer C.free(unsafe.Pointer(buf))
|
||||
|
||||
|
@ -69,3 +70,18 @@ func (p *Handle) waitForPacket() {
|
|||
|
||||
C.pcap_wait(p.cptr, usec)
|
||||
}
|
||||
|
||||
// openOfflineFile returns contents of input file as a *Handle.
|
||||
func openOfflineFile(file *os.File) (handle *Handle, err error) {
|
||||
buf := (*C.char)(C.calloc(errorBufferSize, 1))
|
||||
defer C.free(unsafe.Pointer(buf))
|
||||
cmode := C.CString("rb")
|
||||
defer C.free(unsafe.Pointer(cmode))
|
||||
cf := C.fdopen(C.int(file.Fd()), cmode)
|
||||
|
||||
cptr := C.pcap_fopen_offline(cf, buf)
|
||||
if cptr == nil {
|
||||
return nil, errors.New(C.GoString(buf))
|
||||
}
|
||||
return &Handle{cptr: cptr}, nil
|
||||
}
|
||||
|
|
23
vendor/github.com/google/gopacket/pcap/pcap_windows.go
generated
vendored
23
vendor/github.com/google/gopacket/pcap/pcap_windows.go
generated
vendored
|
@ -7,11 +7,19 @@
|
|||
|
||||
package pcap
|
||||
|
||||
/*
|
||||
#include <pcap.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func (p *Handle) openLive() error {
|
||||
func (p *Handle) setNonBlocking() error {
|
||||
// do nothing
|
||||
return nil
|
||||
}
|
||||
|
@ -21,3 +29,16 @@ func (p *Handle) waitForPacket() {
|
|||
// can't use select() so instead just switch goroutines
|
||||
runtime.Gosched()
|
||||
}
|
||||
|
||||
// openOfflineFile returns contents of input file as a *Handle.
|
||||
func openOfflineFile(file *os.File) (handle *Handle, err error) {
|
||||
buf := (*C.char)(C.calloc(errorBufferSize, 1))
|
||||
defer C.free(unsafe.Pointer(buf))
|
||||
cf := C.intptr_t(file.Fd())
|
||||
|
||||
cptr := C.pcap_hopen_offline(cf, buf)
|
||||
if cptr == nil {
|
||||
return nil, errors.New(C.GoString(buf))
|
||||
}
|
||||
return &Handle{cptr: cptr}, nil
|
||||
}
|
||||
|
|
BIN
vendor/github.com/google/gopacket/pcap/test_ethernet.pcap
generated
vendored
BIN
vendor/github.com/google/gopacket/pcap/test_ethernet.pcap
generated
vendored
Binary file not shown.
52
vendor/github.com/google/gopacket/pcapgo/capture.go
generated
vendored
Normal file
52
vendor/github.com/google/gopacket/pcapgo/capture.go
generated
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
// Copyright 2012 Google, Inc. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree.
|
||||
|
||||
package pcapgo
|
||||
|
||||
import (
|
||||
"net"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
"github.com/mdlayher/raw"
|
||||
)
|
||||
|
||||
// EthernetHandle wraps a raw.Conn, implementing gopacket.PacketDataSource so
|
||||
// that the handle can be used with gopacket.NewPacketSource.
|
||||
type EthernetHandle struct {
|
||||
*raw.Conn
|
||||
}
|
||||
|
||||
// ReadPacketData implements gopacket.PacketDataSource.
|
||||
func (h *EthernetHandle) ReadPacketData() ([]byte, gopacket.CaptureInfo, error) {
|
||||
b := make([]byte, 4096) // TODO(correctness): how much space do we need?
|
||||
n, _, err := h.ReadFrom(b)
|
||||
if err != nil {
|
||||
return nil, gopacket.CaptureInfo{}, err
|
||||
}
|
||||
data := b[:n]
|
||||
return data, gopacket.CaptureInfo{
|
||||
CaptureLength: len(data),
|
||||
Length: len(data),
|
||||
Timestamp: time.Now(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewEthernetHandle implements pcap.OpenLive for ethernet interfaces only.
|
||||
func NewEthernetHandle(ifname string) (*EthernetHandle, error) {
|
||||
intf, err := net.InterfaceByName(ifname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conn, err := raw.ListenPacket(intf, syscall.ETH_P_ALL, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &EthernetHandle{conn}, nil
|
||||
}
|
31
vendor/github.com/google/gopacket/pcapgo/read.go
generated
vendored
31
vendor/github.com/google/gopacket/pcapgo/read.go
generated
vendored
|
@ -149,6 +149,37 @@ func (r *Reader) Snaplen() uint32 {
|
|||
return r.snaplen
|
||||
}
|
||||
|
||||
// SetSnaplen sets the snapshot length of the capture file.
|
||||
//
|
||||
// This is useful when a pcap file contains packets bigger than then snaplen.
|
||||
// Pcapgo will error when reading packets bigger than snaplen, then it dumps those
|
||||
// packets and reads the next 16 bytes, which are part of the "faulty" packet's payload, but pcapgo
|
||||
// thinks it's the next header, which is probably also faulty because it's not really a packet header.
|
||||
// This can lead to a lot of faulty reads.
|
||||
//
|
||||
// The SetSnaplen function can be used to set a bigger snaplen to prevent those read errors.
|
||||
//
|
||||
// This snaplen situation can happen when a pcap writer doesn't truncate packets to the snaplen size while writing packets to file.
|
||||
// E.g. In Python, dpkt.pcap.Writer sets snaplen by default to 1500 (https://dpkt.readthedocs.io/en/latest/api/api_auto.html#dpkt.pcap.Writer)
|
||||
// but doesn't enforce this when writing packets (https://dpkt.readthedocs.io/en/latest/_modules/dpkt/pcap.html#Writer.writepkt).
|
||||
// When reading, tools like tcpdump, tcpslice, mergecap and wireshark ignore the snaplen and use
|
||||
// their own defined snaplen.
|
||||
// E.g. When reading packets, tcpdump defines MAXIMUM_SNAPLEN (https://github.com/the-tcpdump-group/tcpdump/blob/6e80fcdbe9c41366df3fa244ffe4ac8cce2ab597/netdissect.h#L290)
|
||||
// and uses it (https://github.com/the-tcpdump-group/tcpdump/blob/66384fa15b04b47ad08c063d4728df3b9c1c0677/print.c#L343-L358).
|
||||
//
|
||||
// For further reading:
|
||||
// - https://github.com/the-tcpdump-group/tcpdump/issues/389
|
||||
// - https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8808
|
||||
// - https://www.wireshark.org/lists/wireshark-dev/201307/msg00061.html
|
||||
// - https://github.com/wireshark/wireshark/blob/bfd51199e707c1d5c28732be34b44a9ee8a91cd8/wiretap/pcap-common.c#L723-L742
|
||||
// - https://github.com/wireshark/wireshark/blob/f07fb6cdfc0904905627707b88450054e921f092/wiretap/libpcap.c#L592-L598
|
||||
// - https://github.com/wireshark/wireshark/blob/f07fb6cdfc0904905627707b88450054e921f092/wiretap/libpcap.c#L714-L727
|
||||
// - https://github.com/the-tcpdump-group/tcpdump/commit/d033c1bc381c76d13e4aface97a4f4ec8c3beca2
|
||||
// - https://github.com/the-tcpdump-group/tcpdump/blob/88e87cb2cb74c5f939792171379acd9e0efd8b9a/netdissect.h#L263-L290
|
||||
func (r *Reader) SetSnaplen(newSnaplen uint32) {
|
||||
r.snaplen = newSnaplen
|
||||
}
|
||||
|
||||
// Reader formater
|
||||
func (r *Reader) String() string {
|
||||
return fmt.Sprintf("PcapFile maj: %x min: %x snaplen: %d linktype: %s", r.versionMajor, r.versionMinor, r.snaplen, r.linkType)
|
||||
|
|
15
vendor/github.com/google/gopacket/pcapgo/write.go
generated
vendored
15
vendor/github.com/google/gopacket/pcapgo/write.go
generated
vendored
|
@ -26,6 +26,9 @@ import (
|
|||
// timestamp resolution and little-endian encoding.
|
||||
type Writer struct {
|
||||
w io.Writer
|
||||
|
||||
// Moving this into the struct seems to save an allocation for each call to writePacketHeader
|
||||
buf [16]byte
|
||||
}
|
||||
|
||||
const magicMicroseconds = 0xA1B2C3D4
|
||||
|
@ -71,19 +74,17 @@ func (w *Writer) WriteFileHeader(snaplen uint32, linktype layers.LinkType) error
|
|||
const nanosPerMicro = 1000
|
||||
|
||||
func (w *Writer) writePacketHeader(ci gopacket.CaptureInfo) error {
|
||||
var buf [16]byte
|
||||
|
||||
t := ci.Timestamp
|
||||
if t.IsZero() {
|
||||
t = time.Now()
|
||||
}
|
||||
secs := t.Unix()
|
||||
usecs := t.Nanosecond() / nanosPerMicro
|
||||
binary.LittleEndian.PutUint32(buf[0:4], uint32(secs))
|
||||
binary.LittleEndian.PutUint32(buf[4:8], uint32(usecs))
|
||||
binary.LittleEndian.PutUint32(buf[8:12], uint32(ci.CaptureLength))
|
||||
binary.LittleEndian.PutUint32(buf[12:16], uint32(ci.Length))
|
||||
_, err := w.w.Write(buf[:])
|
||||
binary.LittleEndian.PutUint32(w.buf[0:4], uint32(secs))
|
||||
binary.LittleEndian.PutUint32(w.buf[4:8], uint32(usecs))
|
||||
binary.LittleEndian.PutUint32(w.buf[8:12], uint32(ci.CaptureLength))
|
||||
binary.LittleEndian.PutUint32(w.buf[12:16], uint32(ci.Length))
|
||||
_, err := w.w.Write(w.buf[:])
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
16
vendor/github.com/mdlayher/raw/.travis.yml
generated
vendored
Normal file
16
vendor/github.com/mdlayher/raw/.travis.yml
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
language: go
|
||||
go:
|
||||
- "1.x"
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
before_install:
|
||||
- go get github.com/golang/lint/golint
|
||||
- go get honnef.co/go/tools/cmd/staticcheck
|
||||
- go get -d -t ./...
|
||||
script:
|
||||
- go build -tags=gofuzz ./...
|
||||
- go vet ./...
|
||||
- staticcheck -ignore 'github.com/mdlayher/raw/raw_bsd.go:SA1019' ./...
|
||||
- golint -set_exit_status ./...
|
||||
- go test -v -race ./...
|
10
vendor/github.com/mdlayher/raw/LICENSE.md
generated
vendored
Normal file
10
vendor/github.com/mdlayher/raw/LICENSE.md
generated
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
MIT License
|
||||
===========
|
||||
|
||||
Copyright (C) 2015 Matt Layher
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
12
vendor/github.com/mdlayher/raw/README.md
generated
vendored
Normal file
12
vendor/github.com/mdlayher/raw/README.md
generated
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
raw [](https://travis-ci.org/mdlayher/raw) [](https://godoc.org/github.com/mdlayher/raw) [](https://goreportcard.com/report/github.com/mdlayher/raw)
|
||||
===
|
||||
|
||||
Package `raw` enables reading and writing data at the device driver level for
|
||||
a network interface. MIT Licensed.
|
||||
|
||||
For more information about using raw sockets with Ethernet frames in Go, check
|
||||
out my blog post: [Network Protocol Breakdown: Ethernet and Go](https://medium.com/@mdlayher/network-protocol-breakdown-ethernet-and-go-de985d726cc1).
|
||||
|
||||
Portions of this code are taken from the Go standard library. The Go
|
||||
standard library is Copyright (c) 2012 The Go Authors. All rights reserved.
|
||||
The Go license can be found at https://golang.org/LICENSE.
|
189
vendor/github.com/mdlayher/raw/raw.go
generated
vendored
Normal file
189
vendor/github.com/mdlayher/raw/raw.go
generated
vendored
Normal file
|
@ -0,0 +1,189 @@
|
|||
// Package raw enables reading and writing data at the device driver level for
|
||||
// a network interface.
|
||||
package raw
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/bpf"
|
||||
)
|
||||
|
||||
const (
|
||||
// Maximum read timeout per syscall.
|
||||
// It is required because read/recvfrom won't be interrupted on closing of the file descriptor.
|
||||
readTimeout = 200 * time.Millisecond
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrNotImplemented is returned when certain functionality is not yet
|
||||
// implemented for the host operating system.
|
||||
ErrNotImplemented = errors.New("raw: not implemented")
|
||||
)
|
||||
|
||||
var _ net.Addr = &Addr{}
|
||||
|
||||
// Addr is a network address which can be used to contact other machines, using
|
||||
// their hardware addresses.
|
||||
type Addr struct {
|
||||
HardwareAddr net.HardwareAddr
|
||||
}
|
||||
|
||||
// Network returns the address's network name, "raw".
|
||||
func (a *Addr) Network() string {
|
||||
return "raw"
|
||||
}
|
||||
|
||||
// String returns the address's hardware address.
|
||||
func (a *Addr) String() string {
|
||||
return a.HardwareAddr.String()
|
||||
}
|
||||
|
||||
var _ net.PacketConn = &Conn{}
|
||||
|
||||
// Conn is an implementation of the net.PacketConn interface which can send
|
||||
// and receive data at the network interface device driver level.
|
||||
type Conn struct {
|
||||
// packetConn is the operating system-specific implementation of
|
||||
// a raw connection.
|
||||
p *packetConn
|
||||
}
|
||||
|
||||
// ReadFrom implements the net.PacketConn ReadFrom method.
|
||||
func (c *Conn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||
return c.p.ReadFrom(b)
|
||||
}
|
||||
|
||||
// WriteTo implements the net.PacketConn WriteTo method.
|
||||
func (c *Conn) WriteTo(b []byte, addr net.Addr) (int, error) {
|
||||
return c.p.WriteTo(b, addr)
|
||||
}
|
||||
|
||||
// Close closes the connection.
|
||||
func (c *Conn) Close() error {
|
||||
return c.p.Close()
|
||||
}
|
||||
|
||||
// LocalAddr returns the local network address.
|
||||
func (c *Conn) LocalAddr() net.Addr {
|
||||
return c.p.LocalAddr()
|
||||
}
|
||||
|
||||
// SetDeadline implements the net.PacketConn SetDeadline method.
|
||||
func (c *Conn) SetDeadline(t time.Time) error {
|
||||
return c.p.SetDeadline(t)
|
||||
}
|
||||
|
||||
// SetReadDeadline implements the net.PacketConn SetReadDeadline method.
|
||||
func (c *Conn) SetReadDeadline(t time.Time) error {
|
||||
return c.p.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
// SetWriteDeadline implements the net.PacketConn SetWriteDeadline method.
|
||||
func (c *Conn) SetWriteDeadline(t time.Time) error {
|
||||
return c.p.SetWriteDeadline(t)
|
||||
}
|
||||
|
||||
var _ bpf.Setter = &Conn{}
|
||||
|
||||
// SetBPF attaches an assembled BPF program to the connection.
|
||||
func (c *Conn) SetBPF(filter []bpf.RawInstruction) error {
|
||||
return c.p.SetBPF(filter)
|
||||
}
|
||||
|
||||
// SetPromiscuous enables or disables promiscuous mode on the interface, allowing it
|
||||
// to receive traffic that is not addressed to the interface.
|
||||
func (c *Conn) SetPromiscuous(b bool) error {
|
||||
return c.p.SetPromiscuous(b)
|
||||
}
|
||||
|
||||
// Stats contains statistics about a Conn.
|
||||
type Stats struct {
|
||||
// The total number of packets received.
|
||||
Packets uint64
|
||||
|
||||
// The number of packets dropped.
|
||||
Drops uint64
|
||||
}
|
||||
|
||||
// Stats retrieves statistics from the Conn.
|
||||
//
|
||||
// Only supported on Linux at this time.
|
||||
func (c *Conn) Stats() (*Stats, error) {
|
||||
return c.p.Stats()
|
||||
}
|
||||
|
||||
// ListenPacket creates a net.PacketConn which can be used to send and receive
|
||||
// data at the network interface device driver level.
|
||||
//
|
||||
// ifi specifies the network interface which will be used to send and receive
|
||||
// data.
|
||||
//
|
||||
// proto specifies the protocol (usually the EtherType) which should be
|
||||
// captured and transmitted. proto, if needed, is automatically converted to
|
||||
// network byte order (big endian), akin to the htons() function in C.
|
||||
//
|
||||
// cfg specifies optional configuration which may be operating system-specific.
|
||||
// A nil Config is equivalent to the default configuration: send and receive
|
||||
// data at the network interface device driver level (usually raw Ethernet frames).
|
||||
func ListenPacket(ifi *net.Interface, proto uint16, cfg *Config) (*Conn, error) {
|
||||
// A nil config is an empty Config.
|
||||
if cfg == nil {
|
||||
cfg = &Config{}
|
||||
}
|
||||
|
||||
p, err := listenPacket(ifi, proto, *cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Conn{
|
||||
p: p,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// A Config can be used to specify additional options for a Conn.
|
||||
type Config struct {
|
||||
// Linux only: call socket(7) with SOCK_DGRAM instead of SOCK_RAW.
|
||||
// Has no effect on other operating systems.
|
||||
LinuxSockDGRAM bool
|
||||
|
||||
// Experimental: Linux only (for now, but can be ported to BSD):
|
||||
// disables repeated socket reads due to internal timeouts, at the expense
|
||||
// of losing the ability to cancel a ReadFrom operation by calling the Close
|
||||
// method of the net.PacketConn.
|
||||
//
|
||||
// Not recommended for programs which may need to open and close multiple
|
||||
// sockets during program runs. This may save some CPU time by avoiding a
|
||||
// busy loop for programs which do not need timeouts, or programs which keep
|
||||
// a single socket open for the entire duration of the program.
|
||||
NoTimeouts bool
|
||||
|
||||
// Linux only: do not accumulate packet socket statistic counters. Packet
|
||||
// socket statistics are reset on each call to retrieve them via getsockopt,
|
||||
// but this package's default behavior is to continue accumulating the
|
||||
// statistics internally per Conn. To use the Linux default behavior of
|
||||
// resetting statistics on each call to Stats, set this value to true.
|
||||
NoCumulativeStats bool
|
||||
}
|
||||
|
||||
// htons converts a short (uint16) from host-to-network byte order.
|
||||
// Thanks to mikioh for this neat trick:
|
||||
// https://github.com/mikioh/-stdyng/blob/master/afpacket.go
|
||||
func htons(i uint16) uint16 {
|
||||
return (i<<8)&0xff00 | i>>8
|
||||
}
|
||||
|
||||
// Copyright (c) 2012 The Go Authors. All rights reserved.
|
||||
// Source code in this file is based on src/net/interface_linux.go,
|
||||
// from the Go standard library. The Go license can be found here:
|
||||
// https://golang.org/LICENSE.
|
||||
|
||||
// Taken from:
|
||||
// https://github.com/golang/go/blob/master/src/net/net.go#L417-L421.
|
||||
type timeoutError struct{}
|
||||
|
||||
func (e *timeoutError) Error() string { return "i/o timeout" }
|
||||
func (e *timeoutError) Timeout() bool { return true }
|
||||
func (e *timeoutError) Temporary() bool { return true }
|
366
vendor/github.com/mdlayher/raw/raw_bsd.go
generated
vendored
Normal file
366
vendor/github.com/mdlayher/raw/raw_bsd.go
generated
vendored
Normal file
|
@ -0,0 +1,366 @@
|
|||
// +build darwin dragonfly freebsd netbsd openbsd
|
||||
|
||||
package raw
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/bpf"
|
||||
)
|
||||
|
||||
const (
|
||||
// bpfDIn tells BPF to pass through only incoming packets, so we do not
|
||||
// receive the packets we send using BPF.
|
||||
bpfDIn = 0
|
||||
|
||||
// osFreeBSD is the GOOS name for FreeBSD.
|
||||
osFreeBSD = "freebsd"
|
||||
)
|
||||
|
||||
// bpfLen returns the length of the BPF header prepended to each incoming ethernet
|
||||
// frame. FreeBSD uses a slightly modified header from other BSD variants.
|
||||
func bpfLen() int {
|
||||
// Majority of BSD family systems use the bpf_hdr struct, but FreeBSD
|
||||
// has replaced this with bpf_xhdr, which is longer.
|
||||
const (
|
||||
bpfHeaderLen = 18
|
||||
bpfXHeaderLen = 26
|
||||
)
|
||||
|
||||
if runtime.GOOS == osFreeBSD {
|
||||
return bpfXHeaderLen
|
||||
}
|
||||
|
||||
return bpfHeaderLen
|
||||
}
|
||||
|
||||
var (
|
||||
// Must implement net.PacketConn at compile-time.
|
||||
_ net.PacketConn = &packetConn{}
|
||||
)
|
||||
|
||||
// packetConn is the Linux-specific implementation of net.PacketConn for this
|
||||
// package.
|
||||
type packetConn struct {
|
||||
proto uint16
|
||||
ifi *net.Interface
|
||||
f *os.File
|
||||
fd int
|
||||
buflen int
|
||||
|
||||
// Timeouts set via Set{Read,}Deadline, guarded by mutex
|
||||
timeoutMu sync.RWMutex
|
||||
rtimeout time.Time
|
||||
}
|
||||
|
||||
// listenPacket creates a net.PacketConn which can be used to send and receive
|
||||
// data at the device driver level.
|
||||
func listenPacket(ifi *net.Interface, proto uint16, _ Config) (*packetConn, error) {
|
||||
// Config is, as of now, unused on BSD.
|
||||
// TODO(mdlayher): consider porting NoTimeouts option to BSD if it pans out.
|
||||
|
||||
var f *os.File
|
||||
var err error
|
||||
|
||||
// Try to find an available BPF device
|
||||
for i := 0; i <= 10; i++ {
|
||||
bpfPath := fmt.Sprintf("/dev/bpf%d", i)
|
||||
f, err = os.OpenFile(bpfPath, os.O_RDWR, 0666)
|
||||
if err == nil {
|
||||
// Found a usable device
|
||||
break
|
||||
}
|
||||
|
||||
// Device is busy, try the next one
|
||||
if perr, ok := err.(*os.PathError); ok {
|
||||
if perr.Err.(syscall.Errno) == syscall.EBUSY {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if f == nil {
|
||||
return nil, errors.New("unable to open BPF device")
|
||||
}
|
||||
|
||||
fd := int(f.Fd())
|
||||
if fd == -1 {
|
||||
return nil, errors.New("unable to open BPF device")
|
||||
}
|
||||
|
||||
// Configure BPF device to send and receive data
|
||||
buflen, err := configureBPF(fd, ifi, proto)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &packetConn{
|
||||
proto: proto,
|
||||
ifi: ifi,
|
||||
f: f,
|
||||
fd: fd,
|
||||
buflen: buflen,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ReadFrom implements the net.PacketConn.ReadFrom method.
|
||||
func (p *packetConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||
p.timeoutMu.Lock()
|
||||
deadline := p.rtimeout
|
||||
p.timeoutMu.Unlock()
|
||||
|
||||
buf := make([]byte, p.buflen)
|
||||
var n int
|
||||
|
||||
for {
|
||||
var timeout time.Duration
|
||||
|
||||
if deadline.IsZero() {
|
||||
timeout = readTimeout
|
||||
} else {
|
||||
timeout = deadline.Sub(time.Now())
|
||||
if timeout > readTimeout {
|
||||
timeout = readTimeout
|
||||
}
|
||||
}
|
||||
|
||||
tv, err := newTimeval(timeout)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(p.fd), syscall.BIOCSRTIMEOUT, uintptr(unsafe.Pointer(tv))); err != 0 {
|
||||
return 0, nil, syscall.Errno(err)
|
||||
}
|
||||
|
||||
// Attempt to receive on socket
|
||||
// The read sycall will NOT be interrupted by closing of the socket
|
||||
n, err = syscall.Read(p.fd, buf)
|
||||
if err != nil {
|
||||
return n, nil, err
|
||||
}
|
||||
if n > 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(mdlayher): consider parsing BPF header if it proves useful.
|
||||
// BPF header length depends on the platform this code is running on
|
||||
bpfl := bpfLen()
|
||||
|
||||
// Retrieve source MAC address of ethernet header
|
||||
mac := make(net.HardwareAddr, 6)
|
||||
copy(mac, buf[bpfl+6:bpfl+12])
|
||||
|
||||
// Skip past BPF header to retrieve ethernet frame
|
||||
out := copy(b, buf[bpfl:bpfl+n])
|
||||
|
||||
return out, &Addr{
|
||||
HardwareAddr: mac,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WriteTo implements the net.PacketConn.WriteTo method.
|
||||
func (p *packetConn) WriteTo(b []byte, _ net.Addr) (int, error) {
|
||||
return syscall.Write(p.fd, b)
|
||||
}
|
||||
|
||||
// Close closes the connection.
|
||||
func (p *packetConn) Close() error {
|
||||
return p.f.Close()
|
||||
}
|
||||
|
||||
// LocalAddr returns the local network address.
|
||||
func (p *packetConn) LocalAddr() net.Addr {
|
||||
return &Addr{
|
||||
HardwareAddr: p.ifi.HardwareAddr,
|
||||
}
|
||||
}
|
||||
|
||||
// SetDeadline implements the net.PacketConn.SetDeadline method.
|
||||
func (p *packetConn) SetDeadline(t time.Time) error {
|
||||
return p.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
// SetReadDeadline implements the net.PacketConn.SetReadDeadline method.
|
||||
func (p *packetConn) SetReadDeadline(t time.Time) error {
|
||||
p.timeoutMu.Lock()
|
||||
p.rtimeout = t
|
||||
p.timeoutMu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetWriteDeadline implements the net.PacketConn.SetWriteDeadline method.
|
||||
func (p *packetConn) SetWriteDeadline(t time.Time) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
// SetBPF attaches an assembled BPF program to a raw net.PacketConn.
|
||||
func (p *packetConn) SetBPF(filter []bpf.RawInstruction) error {
|
||||
// Base filter filters traffic based on EtherType
|
||||
base, err := bpf.Assemble(baseFilter(p.proto))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Append user filter to base filter, translate to raw format,
|
||||
// and apply to BPF device
|
||||
return syscall.SetBpf(p.fd, assembleBpfInsn(append(base, filter...)))
|
||||
}
|
||||
|
||||
// SetPromiscuous enables or disables promiscuous mode on the interface, allowing it
|
||||
// to receive traffic that is not addressed to the interface.
|
||||
func (p *packetConn) SetPromiscuous(b bool) error {
|
||||
m := 1
|
||||
if !b {
|
||||
m = 0
|
||||
}
|
||||
|
||||
return syscall.SetBpfPromisc(p.fd, m)
|
||||
}
|
||||
|
||||
// Stats retrieves statistics from the Conn.
|
||||
func (p *packetConn) Stats() (*Stats, error) {
|
||||
return nil, ErrNotImplemented
|
||||
}
|
||||
|
||||
// configureBPF configures a BPF device with the specified file descriptor to
|
||||
// use the specified network and interface and protocol.
|
||||
func configureBPF(fd int, ifi *net.Interface, proto uint16) (int, error) {
|
||||
// Use specified interface with BPF device
|
||||
if err := syscall.SetBpfInterface(fd, ifi.Name); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Inform BPF to send us its data immediately
|
||||
if err := syscall.SetBpfImmediate(fd, 1); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Check buffer size of BPF device
|
||||
buflen, err := syscall.BpfBuflen(fd)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Do not automatically complete source address in ethernet headers
|
||||
if err := syscall.SetBpfHeadercmpl(fd, 1); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Only retrieve incoming traffic using BPF device
|
||||
if err := setBPFDirection(fd, bpfDIn); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Build and apply base BPF filter which checks for correct EtherType
|
||||
// on incoming packets
|
||||
prog, err := bpf.Assemble(baseInterfaceFilter(proto, ifi.MTU))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if err := syscall.SetBpf(fd, assembleBpfInsn(prog)); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Flush any packets currently in the BPF device's buffer
|
||||
if err := syscall.FlushBpf(fd); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return buflen, nil
|
||||
}
|
||||
|
||||
// setBPFDirection enables filtering traffic traveling in a specific direction
|
||||
// using BPF, so that traffic sent by this package is not captured when reading
|
||||
// using this package.
|
||||
func setBPFDirection(fd int, direction int) error {
|
||||
_, _, err := syscall.Syscall(
|
||||
syscall.SYS_IOCTL,
|
||||
uintptr(fd),
|
||||
// Even though BIOCSDIRECTION is preferred on FreeBSD, BIOCSSEESENT continues
|
||||
// to work, and is required for other BSD platforms
|
||||
syscall.BIOCSSEESENT,
|
||||
uintptr(unsafe.Pointer(&direction)),
|
||||
)
|
||||
if err != 0 {
|
||||
return syscall.Errno(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// assembleBpfInsn assembles a slice of bpf.RawInstructions to the format required by
|
||||
// package syscall.
|
||||
func assembleBpfInsn(filter []bpf.RawInstruction) []syscall.BpfInsn {
|
||||
// Copy each bpf.RawInstruction into syscall.BpfInsn. If needed,
|
||||
// the structures have the same memory layout and could probably be
|
||||
// unsafely cast to each other for speed.
|
||||
insns := make([]syscall.BpfInsn, 0, len(filter))
|
||||
for _, ins := range filter {
|
||||
insns = append(insns, syscall.BpfInsn{
|
||||
Code: ins.Op,
|
||||
Jt: ins.Jt,
|
||||
Jf: ins.Jf,
|
||||
K: ins.K,
|
||||
})
|
||||
}
|
||||
|
||||
return insns
|
||||
}
|
||||
|
||||
// baseInterfaceFilter creates a base BPF filter which filters traffic based
|
||||
// on its EtherType and returns up to "mtu" bytes of data for processing.
|
||||
func baseInterfaceFilter(proto uint16, mtu int) []bpf.Instruction {
|
||||
return append(
|
||||
// Filter traffic based on EtherType
|
||||
baseFilter(proto),
|
||||
// Accept the packet bytes up to the interface's MTU
|
||||
bpf.RetConstant{
|
||||
Val: uint32(mtu),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// baseFilter creates a base BPF filter which filters traffic based on its
|
||||
// EtherType. baseFilter can be prepended to other filters to handle common
|
||||
// filtering tasks.
|
||||
func baseFilter(proto uint16) []bpf.Instruction {
|
||||
// Offset | Length | Comment
|
||||
// -------------------------
|
||||
// 00 | 06 | Ethernet destination MAC address
|
||||
// 06 | 06 | Ethernet source MAC address
|
||||
// 12 | 02 | Ethernet EtherType
|
||||
const (
|
||||
etherTypeOffset = 12
|
||||
etherTypeLength = 2
|
||||
)
|
||||
|
||||
return []bpf.Instruction{
|
||||
// Load EtherType value from Ethernet header
|
||||
bpf.LoadAbsolute{
|
||||
Off: etherTypeOffset,
|
||||
Size: etherTypeLength,
|
||||
},
|
||||
// If EtherType is equal to the protocol we are using, jump to instructions
|
||||
// added outside of this function.
|
||||
bpf.JumpIf{
|
||||
Cond: bpf.JumpEqual,
|
||||
Val: uint32(proto),
|
||||
SkipTrue: 1,
|
||||
},
|
||||
// EtherType does not match our protocol
|
||||
bpf.RetConstant{
|
||||
Val: 0,
|
||||
},
|
||||
}
|
||||
}
|
341
vendor/github.com/mdlayher/raw/raw_linux.go
generated
vendored
Normal file
341
vendor/github.com/mdlayher/raw/raw_linux.go
generated
vendored
Normal file
|
@ -0,0 +1,341 @@
|
|||
// +build linux
|
||||
|
||||
package raw
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/bpf"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var (
|
||||
// Must implement net.PacketConn at compile-time.
|
||||
_ net.PacketConn = &packetConn{}
|
||||
)
|
||||
|
||||
// packetConn is the Linux-specific implementation of net.PacketConn for this
|
||||
// package.
|
||||
type packetConn struct {
|
||||
ifi *net.Interface
|
||||
s socket
|
||||
pbe uint16
|
||||
|
||||
// Should timeouts be set at all?
|
||||
noTimeouts bool
|
||||
|
||||
// Should stats be accumulated instead of reset on each call?
|
||||
noCumulativeStats bool
|
||||
|
||||
// Internal storage for cumulative stats.
|
||||
stats Stats
|
||||
|
||||
// Timeouts set via Set{Read,}Deadline, guarded by mutex.
|
||||
timeoutMu sync.RWMutex
|
||||
rtimeout time.Time
|
||||
}
|
||||
|
||||
// socket is an interface which enables swapping out socket syscalls for
|
||||
// testing.
|
||||
type socket interface {
|
||||
Bind(syscall.Sockaddr) error
|
||||
Close() error
|
||||
FD() int
|
||||
GetSockopt(level, name int, v unsafe.Pointer, l uintptr) error
|
||||
Recvfrom([]byte, int) (int, syscall.Sockaddr, error)
|
||||
Sendto([]byte, int, syscall.Sockaddr) error
|
||||
SetSockopt(level, name int, v unsafe.Pointer, l uint32) error
|
||||
SetTimeout(time.Duration) error
|
||||
}
|
||||
|
||||
// listenPacket creates a net.PacketConn which can be used to send and receive
|
||||
// data at the device driver level.
|
||||
func listenPacket(ifi *net.Interface, proto uint16, cfg Config) (*packetConn, error) {
|
||||
// Convert proto to big endian.
|
||||
pbe := htons(proto)
|
||||
|
||||
// Enabling overriding the socket type via config.
|
||||
typ := syscall.SOCK_RAW
|
||||
if cfg.LinuxSockDGRAM {
|
||||
typ = syscall.SOCK_DGRAM
|
||||
}
|
||||
|
||||
// Open a packet socket using specified socket and protocol types.
|
||||
sock, err := syscall.Socket(syscall.AF_PACKET, typ, int(pbe))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Wrap raw socket in socket interface.
|
||||
pc, err := newPacketConn(ifi, &sysSocket{fd: sock}, pbe)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pc.noTimeouts = cfg.NoTimeouts
|
||||
pc.noCumulativeStats = cfg.NoCumulativeStats
|
||||
return pc, nil
|
||||
}
|
||||
|
||||
// newPacketConn creates a net.PacketConn using the specified network
|
||||
// interface, wrapped socket and big endian protocol number.
|
||||
//
|
||||
// It is the entry point for tests in this package.
|
||||
func newPacketConn(ifi *net.Interface, s socket, pbe uint16) (*packetConn, error) {
|
||||
// Bind the packet socket to the interface specified by ifi
|
||||
// packet(7):
|
||||
// Only the sll_protocol and the sll_ifindex address fields are used for
|
||||
// purposes of binding.
|
||||
err := s.Bind(&syscall.SockaddrLinklayer{
|
||||
Protocol: pbe,
|
||||
Ifindex: ifi.Index,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &packetConn{
|
||||
ifi: ifi,
|
||||
s: s,
|
||||
pbe: pbe,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ReadFrom implements the net.PacketConn.ReadFrom method.
|
||||
func (p *packetConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||
p.timeoutMu.Lock()
|
||||
deadline := p.rtimeout
|
||||
p.timeoutMu.Unlock()
|
||||
|
||||
var (
|
||||
// Information returned by syscall.Recvfrom.
|
||||
n int
|
||||
addr syscall.Sockaddr
|
||||
err error
|
||||
|
||||
// Timeout for a single loop iteration.
|
||||
timeout = readTimeout
|
||||
)
|
||||
|
||||
for {
|
||||
if !deadline.IsZero() {
|
||||
timeout = deadline.Sub(time.Now())
|
||||
if timeout > readTimeout {
|
||||
timeout = readTimeout
|
||||
}
|
||||
}
|
||||
|
||||
// Set a timeout for this iteration if configured to do so.
|
||||
if !p.noTimeouts {
|
||||
if err := p.s.SetTimeout(timeout); err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt to receive on socket
|
||||
// The recvfrom sycall will NOT be interrupted by closing of the socket
|
||||
n, addr, err = p.s.Recvfrom(b, 0)
|
||||
switch err {
|
||||
case nil:
|
||||
// Got data, break this loop shortly.
|
||||
case syscall.EAGAIN:
|
||||
// Hit a timeout, keep looping.
|
||||
continue
|
||||
default:
|
||||
// Return on any other error.
|
||||
return n, nil, err
|
||||
}
|
||||
|
||||
// Got data, exit the loop.
|
||||
break
|
||||
}
|
||||
|
||||
// Retrieve hardware address and other information from addr.
|
||||
sa, ok := addr.(*syscall.SockaddrLinklayer)
|
||||
if !ok || sa.Halen < 6 {
|
||||
return n, nil, syscall.EINVAL
|
||||
}
|
||||
|
||||
// Use length specified to convert byte array into a hardware address slice.
|
||||
mac := make(net.HardwareAddr, sa.Halen)
|
||||
copy(mac, sa.Addr[:])
|
||||
|
||||
// packet(7):
|
||||
// sll_hatype and sll_pkttype are set on received packets for your
|
||||
// information.
|
||||
// TODO(mdlayher): determine if similar fields exist and are useful on
|
||||
// non-Linux platforms
|
||||
return n, &Addr{
|
||||
HardwareAddr: mac,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WriteTo implements the net.PacketConn.WriteTo method.
|
||||
func (p *packetConn) WriteTo(b []byte, addr net.Addr) (int, error) {
|
||||
// Ensure correct Addr type.
|
||||
a, ok := addr.(*Addr)
|
||||
if !ok || a.HardwareAddr == nil || len(a.HardwareAddr) < 6 {
|
||||
return 0, syscall.EINVAL
|
||||
}
|
||||
|
||||
// Convert hardware address back to byte array form.
|
||||
var baddr [8]byte
|
||||
copy(baddr[:], a.HardwareAddr)
|
||||
|
||||
// Send message on socket to the specified hardware address from addr
|
||||
// packet(7):
|
||||
// When you send packets it is enough to specify sll_family, sll_addr,
|
||||
// sll_halen, sll_ifindex, and sll_protocol. The other fields should
|
||||
// be 0.
|
||||
// In this case, sll_family is taken care of automatically by syscall.
|
||||
err := p.s.Sendto(b, 0, &syscall.SockaddrLinklayer{
|
||||
Ifindex: p.ifi.Index,
|
||||
Halen: uint8(len(a.HardwareAddr)),
|
||||
Addr: baddr,
|
||||
Protocol: p.pbe,
|
||||
})
|
||||
return len(b), err
|
||||
}
|
||||
|
||||
// Close closes the connection.
|
||||
func (p *packetConn) Close() error {
|
||||
return p.s.Close()
|
||||
}
|
||||
|
||||
// LocalAddr returns the local network address.
|
||||
func (p *packetConn) LocalAddr() net.Addr {
|
||||
return &Addr{
|
||||
HardwareAddr: p.ifi.HardwareAddr,
|
||||
}
|
||||
}
|
||||
|
||||
// SetDeadline implements the net.PacketConn.SetDeadline method.
|
||||
func (p *packetConn) SetDeadline(t time.Time) error {
|
||||
return p.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
// SetReadDeadline implements the net.PacketConn.SetReadDeadline method.
|
||||
func (p *packetConn) SetReadDeadline(t time.Time) error {
|
||||
p.timeoutMu.Lock()
|
||||
p.rtimeout = t
|
||||
p.timeoutMu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetWriteDeadline implements the net.PacketConn.SetWriteDeadline method.
|
||||
func (p *packetConn) SetWriteDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetBPF attaches an assembled BPF program to a raw net.PacketConn.
|
||||
func (p *packetConn) SetBPF(filter []bpf.RawInstruction) error {
|
||||
prog := syscall.SockFprog{
|
||||
Len: uint16(len(filter)),
|
||||
Filter: (*syscall.SockFilter)(unsafe.Pointer(&filter[0])),
|
||||
}
|
||||
|
||||
err := p.s.SetSockopt(
|
||||
syscall.SOL_SOCKET,
|
||||
syscall.SO_ATTACH_FILTER,
|
||||
unsafe.Pointer(&prog),
|
||||
uint32(unsafe.Sizeof(prog)),
|
||||
)
|
||||
if err != nil {
|
||||
return os.NewSyscallError("setsockopt", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetPromiscuous enables or disables promiscuous mode on the interface, allowing it
|
||||
// to receive traffic that is not addressed to the interface.
|
||||
func (p *packetConn) SetPromiscuous(b bool) error {
|
||||
mreq := unix.PacketMreq{
|
||||
Ifindex: int32(p.ifi.Index),
|
||||
Type: unix.PACKET_MR_PROMISC,
|
||||
}
|
||||
|
||||
membership := unix.PACKET_ADD_MEMBERSHIP
|
||||
if !b {
|
||||
membership = unix.PACKET_DROP_MEMBERSHIP
|
||||
}
|
||||
|
||||
return p.s.SetSockopt(unix.SOL_PACKET, membership, unsafe.Pointer(&mreq), unix.SizeofPacketMreq)
|
||||
}
|
||||
|
||||
// Stats retrieves statistics from the Conn.
|
||||
func (p *packetConn) Stats() (*Stats, error) {
|
||||
var s unix.TpacketStats
|
||||
if err := p.s.GetSockopt(unix.SOL_PACKET, unix.PACKET_STATISTICS, unsafe.Pointer(&s), unsafe.Sizeof(s)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return p.handleStats(s), nil
|
||||
}
|
||||
|
||||
// handleStats handles creation of Stats structures from raw packet socket stats.
|
||||
func (p *packetConn) handleStats(s unix.TpacketStats) *Stats {
|
||||
// Does the caller want instantaneous stats as provided by Linux? If so,
|
||||
// return the structure directly.
|
||||
if p.noCumulativeStats {
|
||||
return &Stats{
|
||||
Packets: uint64(s.Packets),
|
||||
Drops: uint64(s.Drops),
|
||||
}
|
||||
}
|
||||
|
||||
// The caller wants cumulative stats. Add stats with the internal stats
|
||||
// structure and return a copy of the resulting stats.
|
||||
packets := atomic.AddUint64(&p.stats.Packets, uint64(s.Packets))
|
||||
drops := atomic.AddUint64(&p.stats.Drops, uint64(s.Drops))
|
||||
|
||||
return &Stats{
|
||||
Packets: packets,
|
||||
Drops: drops,
|
||||
}
|
||||
}
|
||||
|
||||
// sysSocket is the default socket implementation. It makes use of
|
||||
// Linux-specific system calls to handle raw socket functionality.
|
||||
type sysSocket struct {
|
||||
fd int
|
||||
}
|
||||
|
||||
// Method implementations simply invoke the syscall of the same name, but pass
|
||||
// the file descriptor stored in the sysSocket as the socket to use.
|
||||
func (s *sysSocket) Bind(sa syscall.Sockaddr) error { return syscall.Bind(s.fd, sa) }
|
||||
func (s *sysSocket) Close() error { return syscall.Close(s.fd) }
|
||||
func (s *sysSocket) FD() int { return s.fd }
|
||||
func (s *sysSocket) GetSockopt(level, name int, v unsafe.Pointer, l uintptr) error {
|
||||
_, _, err := syscall.Syscall6(syscall.SYS_GETSOCKOPT, uintptr(s.fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(&l)), 0)
|
||||
if err != 0 {
|
||||
return syscall.Errno(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (s *sysSocket) Recvfrom(p []byte, flags int) (int, syscall.Sockaddr, error) {
|
||||
return syscall.Recvfrom(s.fd, p, flags)
|
||||
}
|
||||
func (s *sysSocket) Sendto(p []byte, flags int, to syscall.Sockaddr) error {
|
||||
return syscall.Sendto(s.fd, p, flags, to)
|
||||
}
|
||||
func (s *sysSocket) SetSockopt(level, name int, v unsafe.Pointer, l uint32) error {
|
||||
_, _, err := syscall.Syscall6(syscall.SYS_SETSOCKOPT, uintptr(s.fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0)
|
||||
if err != 0 {
|
||||
return syscall.Errno(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (s *sysSocket) SetTimeout(timeout time.Duration) error {
|
||||
tv, err := newTimeval(timeout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return syscall.SetsockoptTimeval(s.fd, syscall.SOL_SOCKET, syscall.SO_RCVTIMEO, tv)
|
||||
}
|
73
vendor/github.com/mdlayher/raw/raw_others.go
generated
vendored
Normal file
73
vendor/github.com/mdlayher/raw/raw_others.go
generated
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd
|
||||
|
||||
package raw
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/bpf"
|
||||
)
|
||||
|
||||
var (
|
||||
// Must implement net.PacketConn at compile-time.
|
||||
_ net.PacketConn = &packetConn{}
|
||||
)
|
||||
|
||||
// packetConn is the generic implementation of net.PacketConn for this package.
|
||||
type packetConn struct{}
|
||||
|
||||
// listenPacket is not currently implemented on this platform.
|
||||
func listenPacket(ifi *net.Interface, proto uint16, cfg Config) (*packetConn, error) {
|
||||
return nil, ErrNotImplemented
|
||||
}
|
||||
|
||||
// ReadFrom is not currently implemented on this platform.
|
||||
func (p *packetConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||
return 0, nil, ErrNotImplemented
|
||||
}
|
||||
|
||||
// WriteTo is not currently implemented on this platform.
|
||||
func (p *packetConn) WriteTo(b []byte, addr net.Addr) (int, error) {
|
||||
return 0, ErrNotImplemented
|
||||
}
|
||||
|
||||
// Close is not currently implemented on this platform.
|
||||
func (p *packetConn) Close() error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
// LocalAddr is not currently implemented on this platform.
|
||||
func (p *packetConn) LocalAddr() net.Addr {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetDeadline is not currently implemented on this platform.
|
||||
func (p *packetConn) SetDeadline(t time.Time) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
// SetReadDeadline is not currently implemented on this platform.
|
||||
func (p *packetConn) SetReadDeadline(t time.Time) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
// SetWriteDeadline is not currently implemented on this platform.
|
||||
func (p *packetConn) SetWriteDeadline(t time.Time) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
// SetBPF is not currently implemented on this platform.
|
||||
func (p *packetConn) SetBPF(filter []bpf.RawInstruction) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
// SetPromisc is not currently implemented on this platform.
|
||||
func (p *packetConn) SetPromiscuous(b bool) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
// Stats is not currently implemented on this platform.
|
||||
func (p *packetConn) Stats() (*Stats, error) {
|
||||
return nil, ErrNotImplemented
|
||||
}
|
20
vendor/github.com/mdlayher/raw/timeval.go
generated
vendored
Normal file
20
vendor/github.com/mdlayher/raw/timeval.go
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
// +build !darwin,!arm,!windows,!mipsle,!mips
|
||||
|
||||
package raw
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
// newTimeval transforms a duration into a syscall.Timeval struct.
|
||||
// An error is returned in case of zero time value.
|
||||
func newTimeval(timeout time.Duration) (*syscall.Timeval, error) {
|
||||
if timeout < time.Microsecond {
|
||||
return nil, &timeoutError{}
|
||||
}
|
||||
return &syscall.Timeval{
|
||||
Sec: int64(timeout / time.Second),
|
||||
Usec: int64(timeout % time.Second / time.Microsecond),
|
||||
}, nil
|
||||
}
|
20
vendor/github.com/mdlayher/raw/timeval32.go
generated
vendored
Normal file
20
vendor/github.com/mdlayher/raw/timeval32.go
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
// +build arm mipsle mips
|
||||
|
||||
package raw
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
// newTimeval transforms a duration into a syscall.Timeval struct.
|
||||
// An error is returned in case of zero time value.
|
||||
func newTimeval(timeout time.Duration) (*syscall.Timeval, error) {
|
||||
if timeout < time.Microsecond {
|
||||
return nil, &timeoutError{}
|
||||
}
|
||||
return &syscall.Timeval{
|
||||
Sec: int32(timeout / time.Second),
|
||||
Usec: int32(timeout % time.Second / time.Microsecond),
|
||||
}, nil
|
||||
}
|
20
vendor/github.com/mdlayher/raw/timeval_darwin.go
generated
vendored
Normal file
20
vendor/github.com/mdlayher/raw/timeval_darwin.go
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
// +build darwin
|
||||
|
||||
package raw
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
// newTimeval transforms a duration into a syscall.Timeval struct.
|
||||
// An error is returned in case of zero time value.
|
||||
func newTimeval(timeout time.Duration) (*syscall.Timeval, error) {
|
||||
if timeout < time.Microsecond {
|
||||
return nil, &timeoutError{}
|
||||
}
|
||||
return &syscall.Timeval{
|
||||
Sec: int64(timeout / time.Second),
|
||||
Usec: int32(timeout % time.Second / time.Microsecond),
|
||||
}, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue