[solved] uci: Parse error (invalid character in name field)

Hello, I'll preface by saying I'm not a networking guru (actually quite dumb when it comes to networking) but here I am because I'm tasked with figuring out what's going on.

This is what I think we're running with (copied from the overview page on the router)

GL-MT1300 Powered by LuCI openwrt-19.07 branch (git-21.189.23240-7b931da)](https://github.com/openwrt/luci) / OpenWrt 19.07.8 r11364-ef56c85848

I've created a dhcp file to upload and then clone to a whole bunch of GL-MT1300s but I've ran into an issue. In the dhcp file I use a hyphen "-" for readability of the hostname like so: P-WIFI-xxx-xxx and when I push the file to the router I noticed that Network > dhcp disappeared. Ok, I look around and check the file using uci show dhcp >/dev/null and get this error uci: Parse error (invalid character in name field) at line 32, byte 28 that happens to line up with the config host part of my dhcp entry, but I don't know why this is the case.

Everything I read and research says that "-" is a valid character to use for hostname. Conversely in the past these entries were separated by an _ which in those same readings and research should not be used in hostname. Yet confusingly when I revert the config host entry in my dhcp file to use _ instead of "-" this does not throw an error. With the parse error now moving to the next first instance of a "-" in a config host entry when I check again.

At a total loss for what to do or why this is happening. I'd like to use "-" as it is an accepted character that can be used in hostnames, but as it stands I seem to only be able to use "_" or I suppose anything else that would make everything less readable. These entries are sometimes read by people without much knowledge besides what they might need to know to try and troubleshoot a simple issue so readability is of high importance. I would also like to keep everything named according to accepted standards.

post command:

uci show dhcp

Hello, this returns the same error as when I use the other command I came across.

uci: Parse error (invalid character in name field) at line 39, byte 27

This of course is the first instance of a "-" in my dhcp file:

Screenshot 2023-08-15 at 12.30.35 PM

valid uci show dhcp please compare your

dhcp.@host[8]=host
dhcp.@host[8].name='P-LAN-194-11'
dhcp.@host[8].dns='1'
dhcp.@host[8].mac='00:00:00:00:00:00'
dhcp.@host[8].ip='192.168.8.78'
dhcp.@host[8].leasetime='12H'

1 Like

You don’t need a name or label on the config host line. You can remove it and be happy.

2 Likes

that's why I said to post the command:

uci show dhcp

and I know that this is complaining just remove:

config host 'P-LAN-194-11'

and

config host
2 Likes

Just to be clear, your screenshot shows lines 39 thru 44 - but not line 32.

1 Like

Yeah sorry, after I reverted back to an _ for the name the parse error moved to line 39, the next instance of a "-" in my file.

1 Like

Would you mind helping me understand why this isn't necessary? I was simply going off what we had before which was not built by me but by someone who is no longer with the company, and the issue has somehow fallen into my lap. Just trying to learn :slight_smile:

https://openwrt.org/docs/guide-user/base-system/dhcp_configuration#static_leases

2 Likes

Cool!

Then this seems like it might be the issue then:

See: https://openwrt.org/docs/guide-user/base-system/dhcp#static_leases

2 Likes

Thank you both @ncompact and @lleachii for the information.

One last question you mention this @ncompact:

So would I not pass along:

dhcp.@host[8]=host

at all in the terminal when creating this new record?

1 Like
uci add dhcp host
uci set dhcp.@host[-1].name="P-LAN-194-11"
uci set dhcp.@host[-1].dns='1'
uci set dhcp.@host[-1].mac="00:11:22:33:44:55"
uci set dhcp.@host[-1].ip="192.168.1.22"
uci commit dhcp
/etc/init.d/dnsmasq restart
3 Likes

Echo…

You would run uci commands like:

uci add dhcp host
uci set dhcp.@host[-1].name='P-LAN-194-11'
uci set dhcp.@host[-1].dns='1'
uci set dhcp.@host[-1].mac='00:00:00:00:00:00'
uci set dhcp.@host[-1].ip='192.168.8.78'
uci set dhcp.@host[-1].leasetime='365d'
uci commit dhcp
3 Likes

We are not talking about a hostname here (the "name" field), but about an uci config section name on line 39...
Hyphen '-' is not valid for a uci section name. (Not really documented anywhere except in the uci sources, I think)
Underscore '_' is allowed.

  67  * validate strings for names and types, reject special characters
  68  * for names, only alphanum and _ is allowed (shell compatibility)
  69  * for types, we allow more characters

EDIT: I added a note to uci docs: https://openwrt.org/docs/guide-user/base-system/uci#elements

6 Likes

Underscores in hostnames aren't RFC compliant (and thus disallowed) period. Some Linux systems begrudgingly allow them, Windows and RFC-compliant DNS servers absolutely do not.

^^^ Corrected the above - dashes ARE allowed, underscores are not, so my observation was wrong and also unhelpful once corrected. My bad! :slight_smile:

4 Likes

I think I found a wrong wikipedia page (Italian version only), the English version seems to be correct ...

For our generic purposes, dnsmasq accepts dashes and underscores.

4 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.