summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/dhcpv4.go
AgeCommit message (Collapse)Author
2023-03-27dhcpv4: change `NewRenewFromOffer` to `NewRenewFromAck`Dennis Marttinen
Signed-off-by: Dennis Marttinen <twelho@welho.tech>
2022-10-01dhcpv4: make NewInform() formatting consistent with neighborsDennis Marttinen
This is just a minor readability improvement that makes `NewInform()` consistent with the neighboring functions like `NewRequest()`, `NewReply()`, `NewRelease()` etc. Having the prepended modifiers on the same line helps with separating the modifiers that provided by the function from the modifiers passed in by the consumer of the function. Signed-off-by: Dennis Marttinen <twelho@welho.tech>
2022-07-27dhcpv4: add a client method to facilitate lease renewalsDennis Marttinen
Signed-off-by: Dennis Marttinen <twelho@welho.tech>
2022-07-15dhcpv4: enable deletion of options and add modifier for itDennis Marttinen
Signed-off-by: Dennis Marttinen <twelho@welho.tech>
2022-05-03Documentation: Description is inverse of realitykayos
Signed-off-by: kayos@tcp.direct <kayos@tcp.direct>
2021-12-09dhcpv4: remove server IP from REQUEST messagesChris Koch
RFC 2131 Section 4.4.1 specifies that REQUEST messages should set 'siaddr' to 0. Signed-off-by: Chris Koch <chrisko@google.com>
2021-05-28Break circular dependency on u-rootChris Koch
u-root -> dhcp -> u-root is the circular dependency. Which is fine, except we messed up modules in u-root big time. We need to break the circular dep for now. Signed-off-by: Chris Koch <chrisko@google.com>
2021-04-28[dhcpv4] remove NewOffer commentPablo Mazzini
2021-03-10Improve ipv4 compatibilityEugene Burkov
Signed-off-by: Eugene Burkov <e.burkov@adguard.com>
2021-03-06Pad packets after the 'end' option to be more conformantMarcel Moolenaar
RFC 2131 gives two examples of padding in section 4.1. For both the examples, the 'end' option preceeds the padding with the 'pad' option. These examples relate to overloading pre-defined fields for options, not padding the packet for a minimal size. Older versions of the U-Boot firmware support DHCP, but do not expect the 'pad' option. The firmware logs the following warning for each occurence: *** Unhandled DHCP Option in OFFER/ACK: 0 This warning disappears when the 'end' option preceeds the 'pad' option. Signed-off-by: Marcel Moolenaar <mmoolena@amazon.com>
2020-09-16nclient4: respect NAKsChris Koch
Signed-off-by: Chris Koch <chrisko@google.com>
2020-07-18- change to WithOptionCopied in NewReleaseFromACKHu Jun
Signed-off-by: Hu Jun <hujun.work@gmail.com>
2020-07-18move NewReleaseFromAck to where all NewXXFromYY areHu Jun
Signed-off-by: Hu Jun <hujun.work@gmail.com>
2020-07-17fix doc of NewReleaseFromACKHu Jun
Signed-off-by: Hu Jun <hujun.work@gmail.com>
2020-07-17- change NewRleaseFromLease to NewRleaseFromACK, and move it to dhcpv4Hu Jun
Signed-off-by: Hu Jun <hujun.work@gmail.com>
2020-06-23Merge branch 'master' of https://github.com/insomniacslk/dhcp into ↵Hu Jun
dhcpv4_release
2020-06-20dhcpv4: Remove hlen parameter special case in ToBytes()Anatole Denis
There is a special case for when ClientHwAddr is empty, which seems to only apply when creating a packet with New(), which defaults to HWType==Ethernet but doesn't assign the ClientHwAddr field. All the other New*() constructors assign a hardware address and don't use this codepath Remove this special case and instead make New() generate an almost-correct packet in the first place, so that ToBytes() can stay more generic Signed-off-by: Anatole Denis <natolumin@unverle.fr>
2020-06-20dhcpv4: Avoid a panic in ToBytes() with long stringsAnatole Denis
When BootFileName is longer than 128 bytes or ServerHostName is longer than 64 bytes, trying to null-terminate the strings when writing out the packet causes a panic. Since the ToBytes() function cannot return errors, silently truncate the string instead (we do the same with ClientHWAddr if it is longer than 16 bytes for example) Signed-off-by: Anatole Denis <natolumin@unverle.fr>
2020-06-17fix some lint errorsHu Jun
Signed-off-by: Hu Jun <hujun.work@gmail.com>
2020-06-17add lease&release support for nclient4Hu Jun
Signed-off-by: Hu Jun <hujun.work@gmail.com>
2019-12-03dhcpv4: add Client Identifier option; respect RFC 6842Chris Koch
Signed-off-by: Chris Koch <chrisko@google.com>
2019-11-20Update function name in NewReplyFromRequestkevin
Signed-off-by: kevin <kworm@missouri-telecom.com>
2019-11-20Add support for copying relay optionskevin
Signed-off-by: kevin <kworm@missouri-telecom.com>
2019-09-16dhcpv4: Mark all options as requested absent PRL (#315)Anatole Denis
In DHCPv4, when the ParameterRequestList option is not present in a request, it should be assumed that the client wants to receive all the options that the server is able to send. This changes the IsOptionRequested method of dhcpv4.DHCPv4 to return true for any request in that situation. The reasoning is based on this wording in [RFC2131§3.5](https://tools.ietf.org/html/rfc2131#section-3.5): > Not all clients require initialization of all parameters listed in > Appendix A. Two techniques are used to reduce the number of > parameters transmitted from the server to the client. [...] Second, in > its initial DHCPDISCOVER or DHCPREQUEST message, a client may provide > the server with a list of specific parameters the client is interested > in. Signed-off-by: Anatole Denis <natolumin@unverle.fr>
2019-07-05v4 discover: don't ask for broadcastChris Koch
Usually this is used for clients that don't know how to receive any other packets. We can deal with both a unicast or broadcast response packet, so let's let the server decide on its own. Signed-off-by: Chris Koch <chrisko@google.com>
2019-06-27dhcpv4: actually use random number timeoutChris Koch
Signed-off-by: Chris Koch <chrisko@google.com>
2019-06-19dhcpv4: make the short stringer more usefulChris Koch
Nobody gives a hoot about the hardware type. Signed-off-by: Chris Koch <chrisko@google.com>
2019-05-14Improve compatibility with some ipv4 networks.Loic Prylli
- dnsmasq has been seen to null-terminate the bootfile option, similar treament can occur for tftp-servername (although tftp-servername option usage is less common). - for the gateway information to be present in final packet, the Router option should be queried again in request as in discover (which matches behavior of udhcpc/dhclient). Tested: pxeboot with u-root on dnsmask/ipv4 client. Signed-off-by: Loic Prylli <lprylli@netflix.com>
2019-05-09NewReplyFromRequest: copy gw ipPablo Mazzini
2019-05-08[CI] Added lintersAndrea Barberio
Now the CI will also run golangci-lint Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-04-04dhcpv4: add RFC3442 route optionsChristopher Koch
Signed-off-by: Christopher Koch <chrisko@google.com>
2019-04-03Use cancellable crypto RNG from u-rootAndrea Barberio
Fixes #246 Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-04-03Modifying the writeIP function to always write IPv4 in 4 byte long format.Akshay Navale
2019-03-29dhcpv4: pad v4 messages to a 300 byte minimumChristopher Koch
Certain older DHCP servers and relay agents follow the RFC 951 BOOTP standard in which BOOTP/DHCP messages have a 300 byte minimum length. Signed-off-by: Christopher Koch <chrisko@google.com>
2019-03-27client4: add a new DHCPv4 client.Christopher Koch
- Able to send UDP packets before interface is configured. - Able to use any net.PacketConn. - RFC2131-compliant retransmission logic. - Tests. - Race-condition-averse. Previous clients (both mine and the ones here) are prone to race condition errors. Having one and only one place that calls receive on the socket "continuously" without having to coordinate hand-offs makes the logic way easier to follow, and allows for multiple requests in flux at a time. Signed-off-by: Christopher Koch <chrisko@google.com>
2019-03-13[dhcpv4] simplify userclass handling (#249)Pablo Mazzini
2019-01-26dhcpv6: introduce TransactionID typeChristopher Koch
2019-01-24dhcpv4: getters instead of gettersChristopher Koch
From: r := GetRouter(d.Options) To: r := d.Router()
2019-01-24dhcpv4: nicer API for option parsing.Christopher Koch
From: r := d.GetOneOption(OptionRouter).(*OptRouter).Routers d.UpdateOption(&OptRouter{Routers: []net.IP{net.IP{192, 168, 0, 1}}}) To: r := GetRouter(d.Options) d.UpdateOption(OptRouter(net.IP{192, 168, 0, 1}, ...))
2019-01-20dhcpv4: fix TransactionID in SummaryChristopher Koch
2019-01-20dhcpv4: add Stringer for XIDChristopher Koch
2019-01-19dhcpv4: build more packets with modifiersChristopher Koch
Also drop unnecessary return value of Modifier.
2019-01-15dhcpv4: conform to RFC 2131 with respect to options.Christopher Koch
Removes AddOption and GetOption. RFC 2131 specifies that options may only appear once (Section 4.1). If an option does appear more than once, its byte values must be concatenated. RFC 3396 further specifies that to send options longer than 255 bytes, one option may be split into multiple option codes, which must be concatenated back together by the receiver. Both of these are concerned with the byte representation of options. Fact is, based on both RFCs one can say that an option may only appear once, but may be composed of multiple values. Because an option may appear only once logically in any case, we remove the AddOption and GetOption functions and leave only UpdateOption and GetOneOption. Also remove all additions & checks of the End option - the marshaling and unmarshaling code is exclusively responsible for that now.
2019-01-14iana: rename HwTypeType to HWType, add package comment.Christopher Koch
2019-01-11dhcpv4: simplify marshaling options to binary.Christopher Koch
- Consolidate writing the option code and length to Options.Marshal rather than doing it in each individual option. - Use uio in marshaling code.
2019-01-10dhcpv4: remote OptionGetter interface in favor of Options type.Christopher Koch
2019-01-10dhcpv4: simplify option parsing.Christopher Koch
option's codes and lengths were being parsed twice: once in ParseOption and once in each option type's Parse implementation. Consolidate such that it only happens once. Additionally, only pass data to options that they should parse -- we know the length before the Parse function is called, so the option only gets to see the data it needs to see. Also, use uio.Lexer to simplify parsing code in general. Easier to read and reason about.
2019-01-09dhcpv4: export packet members; remove setters and getters.Christopher Koch
2019-01-09dhcpv4: simplify host name and boot file handling.Christopher Koch
2019-01-09dhcpv4: simplify handling of client MAC.Christopher Koch