Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network: DHCPv4 client- add support to send arbitary option and data #13663

Merged
merged 2 commits into from
Oct 16, 2019

Conversation

ssahani
Copy link
Contributor

@ssahani ssahani commented Sep 26, 2019

Closes #5134

Copy link
Member

@keszybz keszybz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... I think this is needlessly complicated.
Instead of defining a separate section, what about the following:
DHCPOption=NNN: XYZXYZ
The syntax would be: a number, a colon, and a c-escaped string.
This would simplify parsing a lot, because it would be possible to have the whole option at once, without the need to define a separate section and whatnot.
This will be also much more concise, so nicer for the user.

If the same option is defined multiple times, that's OK. Just keep them in a list and attach in the order specified by the user. For some cases, the order may matter, and since it's simpler to keep the order, let's just do that.

This will allow the hashing and comparison functions and separate DHCPOption structure to be dropped.

src/libsystemd-network/sd-dhcp-client.c Outdated Show resolved Hide resolved
src/network/networkd-dhcp4.h Outdated Show resolved Hide resolved
@keszybz
Copy link
Member

keszybz commented Oct 1, 2019

Oh, and just please say Closes #5134 since it does and this will allow github to know this.

@ssahani
Copy link
Contributor Author

ssahani commented Oct 1, 2019

Oh, and just please say Closes #5134 since it does and this will allow github to know this.

done

So... I think this is needlessly complicated.
Instead of defining a separate section, what about the following:
DHCPOption=NNN: XYZXYZ
The syntax would be: a number, a colon, and a c-escaped string.
This would simplify parsing a lot, because it would be possible to have the whole option at once, without the need to define a separate section and whatnot.
This will be also much more concise, so nicer for the user.

If the same option is defined multiple times, that's OK. Just keep them in a list and attach in the order specified by the user. For some cases, the order may matter, and since it's simpler to keep the order, let's just do that.

This will allow the hashing and comparison functions and separate DHCPOption structure to be dropped.

Do we have such such parsing before ? I thought of that dropped as could not find.

@keszybz
Copy link
Member

keszybz commented Oct 2, 2019

Do we have such such parsing before?

Pretty much any option which takes multiple values. SystemCallFilter= as good example.

@ssahani
Copy link
Contributor Author

ssahani commented Oct 3, 2019

Do we have such such parsing before?

Pretty much any option which takes multiple values. SystemCallFilter= as good example.
yes then we can do that.

@keszybz
Copy link
Member

keszybz commented Oct 3, 2019

https://tools.ietf.org/html/rfc2131#section-3.5 says:

Options may appear only once, unless
otherwise specified in the options document. The client concatenates
the values of multiple instances of the same option into a single
parameter list for configuration.

and https://tools.ietf.org/html/rfc2132#section-9 doesn't list any options which would be allowed multiple times. So yeah, it seems that you are right, and only allowing each given option once would be appropriate.

So... you may either use a OrderedHashmap to store the options (option number => sd_dhcp_option), or a array. If you use a hashmap, then the hashing function should only use the option number (trivial_hash_ops should work fine). If you use an array, then when inserting to the array, each new option should either replace the existing one with the same number or be appended at the end.

@ssahani
Copy link
Contributor Author

ssahani commented Oct 3, 2019

Thanks for review @keszybz . Updated.

Copy link
Member

@keszybz keszybz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better, but there's still confusion as to if options are allowed multiple times. The sort order is also lost.

src/libsystemd-network/sd-dhcp-client.c Show resolved Hide resolved
src/libsystemd-network/sd-dhcp-client.c Outdated Show resolved Hide resolved
src/network/networkd-dhcp4.c Outdated Show resolved Hide resolved
src/network/networkd-dhcp4.c Outdated Show resolved Hide resolved
src/network/networkd-dhcp4.c Outdated Show resolved Hide resolved
src/network/networkd-dhcp4.c Outdated Show resolved Hide resolved
src/network/networkd-dhcp4.c Outdated Show resolved Hide resolved
src/network/networkd-dhcp4.c Outdated Show resolved Hide resolved
@keszybz keszybz added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 8, 2019
@ssahani ssahani force-pushed the dhcp-send-option-data branch 3 times, most recently from 470ed1e to 774706d Compare October 8, 2019 16:11
@yuwata yuwata removed the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 9, 2019
Copy link

@flo-wer flo-wer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that multiple option assignments should be allowed in one line?
I think it'd be simpler to always require just one option setting per line.

Of course you only want to consider the first one. The question is whether to allow one word on the rhs or multiple words.

I would consider one assignment per line because the main use-case is binary data as values. But I'm not sure what the best way to encode this is.

Was not the previous code doing that ? Now I am confused . : separation has a issue. How you send the IP addresses ? May be just consider the first one .

If I understand you correctly, you ask about how to use multiple IP addresses as the value of a single option. I think we do not have to consider this case, as no official options consists of the DHCP client sending IP addresses and if it is a proprietary extension, you would have to encode this as single bytes.

I would rather provide a more convenient way to encode a byte-string than to think of any possible encoding of IPs, strings, integers, etc.

man/systemd.network.xml Outdated Show resolved Hide resolved
man/systemd.network.xml Outdated Show resolved Hide resolved
@yuwata
Copy link
Member

yuwata commented Oct 13, 2019

@keszybz and @ssahani I updated this PR. PTAL. I will try to add a test case.

@ssahani Your original version is saved at https://github.com/yuwata/systemd/commits/pr-13663-backup. If you do not like this. Please revert this and restore your original one.

@ssahani
Copy link
Contributor Author

ssahani commented Oct 14, 2019

@yuwata Thanks for working on it. LGTM.

@yuwata
Copy link
Member

yuwata commented Oct 14, 2019

Hmm, dnsmasq does not logs the sent data. @ssahani Do you have any idea to test this PR?

@ssahani
Copy link
Contributor Author

ssahani commented Oct 14, 2019

Yes we can test it tcpdump . Please see https://src.fedoraproject.org/fork/ssahani/rpms/lldpad/c/451044af05e03da3ac08b154efbb8d0915e7bb73

We have to create a service

[Unit]
Description=TCPDumpd
After=multi-user.target network.target

[Service]
Type=simple
ExecStart=/usr/sbin/tcpdump -pnnli port 67 or port 68 -e -n  -vvv -w "/tmp/dhcp-tcp-dump.pcap"

[Install]
WantedBy=multi-user.target
def CaptureLLDPPackets(self):            
 def FindLLDPFieldsinTCPDump(self, **kwargs):            
"""Look attributes in lldpad logs."""            
  ontents = subprocess.check_output(['tcpdump', '-v', '-r', LLDPAD_TCP_DUMP_FILE]).rstrip().decode('utf-8')            
          if kwargs is not None:            
            for key in kwargs:            
                     self.assertRegex(contents, kwargs[key])               

@yuwata
Copy link
Member

yuwata commented Oct 14, 2019

@ssahani Excellent! But that needs relatively huge work. Let's do that in another PR.

Copy link
Member

@keszybz keszybz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this version is much more consistent then the previous ones.

We only allow one setting for a given option number, and use the earliest value. Is this intentional?

src/libsystemd-network/sd-dhcp-client.c Show resolved Hide resolved
src/libsystemd-network/sd-dhcp-client.c Outdated Show resolved Hide resolved
src/libsystemd-network/sd-dhcp-client.c Outdated Show resolved Hide resolved
src/network/networkd-dhcp4.c Outdated Show resolved Hide resolved
src/network/networkd-dhcp4.c Outdated Show resolved Hide resolved
src/network/networkd-dhcp4.c Show resolved Hide resolved
@keszybz keszybz added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 14, 2019
@yuwata
Copy link
Member

yuwata commented Oct 14, 2019

@keszybz Thank you for the review. I've force-pushed a revised version. I hope all your comments are addressed.

We only allow one setting for a given option number, and use the earliest value. Is this intentional?

Yes, based on your investigation #13663 (comment).

@yuwata yuwata removed the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 14, 2019
@keszybz
Copy link
Member

keszybz commented Oct 14, 2019

@keszybz Thank you for the review. I've force-pushed a revised version. I hope all your comments are addressed.

Thanks, I'll look again tomorrow.

We only allow one setting for a given option number, and use the earliest value. Is this intentional?

Yes, based on your investigation #13663 (comment).

Yep, one setting is OK. But why take the earliest value? This goes against our usual override rules:

DHCPOption = foo:bar
DHCPOption = bar:foo
DHCPOption = foo:barbar

→ I'd expect "foo:barbar bar:foo" to be the options sent to the server.

Copy link
Member

@keszybz keszybz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there ;)

src/network/networkd-dhcp4.c Show resolved Hide resolved
src/libsystemd-network/sd-dhcp-client.c Show resolved Hide resolved
src/network/networkd-dhcp4.c Show resolved Hide resolved
src/network/networkd-dhcp4.c Show resolved Hide resolved
@keszybz
Copy link
Member

keszybz commented Oct 16, 2019

OK, let's mereg.

@keszybz keszybz merged commit c8966bf into systemd:master Oct 16, 2019
@ssahani ssahani deleted the dhcp-send-option-data branch October 16, 2019 10:37
@ssahani
Copy link
Contributor Author

ssahani commented Oct 16, 2019

Thanks @yuwata and @keszybz .

@egberts
Copy link

egberts commented Nov 19, 2019

Not there yet...

https://github.com/egberts/systemd-dhclient

Some of the limitation of systemd's DHCP client is that there is no DHCP-Options.

Hence the need to use ISC DHCP client despite pervasiveness of systemd's own built-in DHCP client.

I also like Dynamic DNS update which is those fancy communication between BIND9 DNS server and DHCP server. systemd-ddns is also nice but it didn't have other things (described in next section). Again, my gateway had too much invested into the usages of ISC BIND9 and ISC DHCP server.

systemd-dhcp-server also cannot do custom database interfaces.

systemd-dhcp-server cannot do dynamic hostname replacement regardless of MAC address.

systemd-dhcp-server cannot do failover and high-redundancy.

@q2dg
Copy link

q2dg commented May 19, 2020

Maybe these issues you say, @egberts, could be written as a Github issue each one, don't you think?

@egberts
Copy link

egberts commented May 19, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

Send dhcp options with networkd
7 participants