Re: hostname-mode : short vs fqdn name

2020-04-08 Thread Thomas HUMMEL

On 4/8/20 4:18 PM, Thomas HUMMEL wrote:

 >> b) : NM just don't play with the transient name and sets a static 
hostname

 >> coming from /etc/sysconfig/network
 >
 > NM sets the transient host name. It doesn't know about
 > /etc/sysconfig/network. The hostname is determined in this way:

But man says "none: NetworkManager will not manage the transient 
hostname and will never set it."

Makes me wonder what exactly is the transient hostname.

Besides, trace for 'none' confirms hostname is "unmanaged"

So where does the short hostname I see in this case b) come from if not 
dhcp (none) neither the sysconfig/network file ?


Or maybe for this case (hostname-mode=none) NM does not change the 
transient hostname but dhcp has initially changed it in step1 (dhcp NM 
profile), without NM being involed. So it is kept this way in step2 
(manual profile activation) ?

___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


Wireless Connection Help

2020-04-08 Thread Romano Pauli
Hello all,
I am looking for some help with using NetworkManager in a c++ application.

I am able to use network manager to scan the list of ap's and also go
through the list of connections.  I think if the network is already listed
in the connection list I need to activate it instead of trying to add it.

However what I am missing is how do I activate the wireless connection and
how do I set the WPA2 key (or other key depending on the security used) I
have not found any code examples on how to use ActivateConnection or
AddAndActivateConnection2 methods.

Below was an attempt I made at setting up the connection (borrowed heavily
from
https://github.com/lcp/NetworkManager/blob/master/examples/C/glib/add-connection-libnm-glib.c
 )

gboolean NetworkSettings::add_connection(NMRemoteSettings *settings,
GMainLoop *loop, const char *con_name, std::string SSID, std::string sKey)
{
   NMConnection *connection;
   NMSettingConnection *s_con;
   NMSettingWireless *s_wireless;
   NMSettingIP4Config *s_ip4;
   char *uuid;
   gboolean success;

   // Create a new connection object
   connection = nm_connection_new();

   // Build up the 'connection' Setting
   s_con = (NMSettingConnection *)nm_setting_connection_new();
   uuid = nm_utils_uuid_generate();
   g_object_set(G_OBJECT(s_con),
 NM_SETTING_CONNECTION_UUID, uuid,
 NM_SETTING_CONNECTION_ID, con_name,
 NM_SETTING_CONNECTION_TYPE, "802-11-wireless",
 NULL);
   g_free(uuid);
   nm_connection_add_setting(connection, NM_SETTING(s_con));

   // Build up the 'wireless' Setting
   s_wireless = (NMSettingWireless *)nm_setting_wireless_new();
   g_object_set(G_OBJECT(s_wireless),
  NM_SETTING_WIRELESS_SSID, SSID.c_str(),
  NM_SETTING_WIRELESS_SEC, sKey.c_str(),
  NULL);
   nm_connection_add_setting(connection, NM_SETTING(s_wireless));

   // Build up the 'ipv4' Setting
   s_ip4 = (NMSettingIP4Config *)nm_setting_ip4_config_new();
   g_object_set(G_OBJECT(s_ip4),
 NM_SETTING_IP4_CONFIG_METHOD,
NM_SETTING_IP4_CONFIG_METHOD_AUTO,
 NULL);
   nm_connection_add_setting(connection, NM_SETTING(s_ip4));

   // Ask the settings service to add the new connection; we'll quit the
   // mainloop and exit when the callback is called.
   success = nm_remote_settings_add_connection(settings, connection,
NetworkSettings::added_cb, loop);
   if(!success)
  g_print("Error adding connection\n");

   g_object_unref(connection);
   return success;
}
___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: hostname-mode : short vs fqdn name

2020-04-08 Thread Thomas HUMMEL

Hello, thanks for your answer

On 4/8/20 10:25 AM, Beniamino Galvani wrote:

>> - step2 (I guess) puts HOSTNAME=maestro-1000 in /etc/sysconfig/network
>
> AFAIK, NetworkManager doesn't do that.

Although I saw that it was the postscript which wrote into this file, I 
thought NetworkManager was considering it because it is mentionned in 
man 5 nm-settings-ifcfg-rh


> Yes, it uses the SetHostname D-Bus call of systemd-hostnamed, which
> changes the transient (kernel) hostname.

Talking about D-Bus, I see this in the begining of all 3 (default, none, 
dhcp) traces :


Apr 08 14:53:29 maestro-1000.maestro.pasteur.fr NetworkManager[25235]: 
 [1586350409.2521] policy: get-hostname: 
"maestro-1000.maestro.pasteur.fr" (from dbus)
Apr 08 14:53:29 maestro-1000.maestro.pasteur.fr NetworkManager[25235]: 
 [1586350409.2521] policy: hostname-original: set to 
"maestro-1000.maestro.pasteur.fr"


how is this hostname fully qualified who sets it ? The original hostname 
always seems to be this one.


>> a) default : what's described above (fqdn)
>> b) none : hostname == short name
>> c) dhcp : same as a) (fqdn)
>>
>> I can elaborate on that like this :
>>
>> a) as man said NM sets hostname "with the one provided via DHCP", 
which is
>> first the short one (step1) then as a static profile is activated, 
it falls

>> back to "hostname from the reverse lookup of the IP address" (which DNS
>> resolves in the fqdn)
>
> Right.

>> b) : NM just don't play with the transient name and sets a static 
hostname

>> coming from /etc/sysconfig/network
>
> NM sets the transient host name. It doesn't know about
> /etc/sysconfig/network. The hostname is determined in this way:

But man says "none: NetworkManager will not manage the transient 
hostname and will never set it."

Makes me wonder what exactly is the transient hostname.

Besides, trace for 'none' confirms hostname is "unmanaged"

So where does the short hostname I see in this case b) come from if not 
dhcp (none) neither the sysconfig/network file ?


>
> 
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/1.20.0/src/nm-policy.c#L744


ok. But what does exactly "set outside of NetworkManager" mean ?


> No, it only takes the short hostname from DHCP.

ok, makes sens as this is what's sent


> I don't know why it is setting the FQDN in your case. Could you please
> put level=trace in the [logging] section of
> /etc/NetworkManager/NetworkManager.conf, disabled journald
> ratelimiting, reproduce the issue and attach the journal log of a boot
> with hostname-mode=dhcp?

Please find the 3 traces here:

http://dl.pasteur.fr/fop/P3H6bSGV/NM-hostname-mode.tar.gz

So basically, I still don't understand the 2 following cases

- none (end up with short name) : if dhcp, NM seems to still manage the 
hostname despite none


- dhcp (end up with fqdn).


Thanks for your help.

--
Thomas HUMMEL

___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: hostname-mode : short vs fqdn name

2020-04-08 Thread Beniamino Galvani via networkmanager-list
On Tue, Apr 07, 2020 at 10:48:28PM +0200, Thomas HUMMEL wrote:
> Hello,
> 
> I'm trying to figure out how exactly my stateless HPC nodes (CentOS
> 8.1/NetworkManager-1.20.0) get their hostnames.
> 
> As a matter of fact, they can either get a "short" (non fqdn - something
> like 'maestro-1000') hostname or a fqdn hostname
> (maestro-1000.maestro.pasteur.fr). This is related to the process network is
> configured according to the following procedure :
> 
> 1. node PXE boots the stateless osimage and ends up having a dhcp NM profile
> 2. a postscript is run on the node which uses NM to create an additional
> profile with higher autoconnect priority which main goal is to statically
> set the ip address retrieved in step 1.
> 
> - if only step 1. is performed  hostname == short name
> - if step 1 + 2. are performed, hostname == fqdn
> 
> Note :
> 
> - DNS is configured on each node, both for forward and reverse zone
> 
> - I checked with tcpdump that DHCP option 12 "Host-Name" always stores the
> short name (and of course the domain 'maestro.pasteur.fr' in option 15)
> 
> - step2 (I guess) puts HOSTNAME=maestro-1000 in /etc/sysconfig/network

AFAIK, NetworkManager doesn't do that.

> - node never have a /etc/hostname file
> 
> - no hostname-mode is specified in NetworkManager.conf
> 
> - finally, when step 1+2 are performed, I can see:
> 
> Apr 07 20:13:19 maestro-1000 systemd-hostnamed[14516]: Changed host name to
> 'maestro-1000'
> Apr 07 20:13:33 maestro-1000.maestro.pasteur.fr systemd-hostnamed[14516]:
> Changed host name to 'maestro-1000.maestro.pasteur.fr'
> 
> which I reckon matches step1 then step2
> 
> Here are my questions :
> 
> - I am assuming NetworkManager uses systemd-hostnamed when it is in charge
> to set the hostname : is this correct ?

Yes, it uses the SetHostname D-Bus call of systemd-hostnamed, which
changes the transient (kernel) hostname.

> - I am assuming what I see is related to hostname-mode setting as I didn't
> see any hostname or hostnamectl et sethostname call in the postscript.
> Playing with its possible valued in NM config, I experienced the following
> after step 1+2 :
> 
> a) default : what's described above (fqdn)
> b) none : hostname == short name
> c) dhcp : same as a) (fqdn)
> 
> I can elaborate on that like this :
> 
> a) as man said NM sets hostname "with the one provided via DHCP", which is
> first the short one (step1) then as a static profile is activated, it falls
> back to "hostname from the reverse lookup of the IP address" (which DNS
> resolves in the fqdn)

Right.

> 
> b) : NM just don't play with the transient name and sets a static hostname
> coming from /etc/sysconfig/network

NM sets the transient host name. It doesn't know about
/etc/sysconfig/network. The hostname is determined in this way:

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/1.20.0/src/nm-policy.c#L744


> c) confuses me as the manual says NM
> 
> "will update the transient hostname only with information coming from DHCP"
> but with no fallback
> So I was expecting after step 2 to have localhost.localdomain or only the
> short name but not the fqdn
> 
> Or maybe it builds a fqdn from host-name + domain coming from DHCP ?

No, it only takes the short hostname from DHCP.

I don't know why it is setting the FQDN in your case. Could you please
put level=trace in the [logging] section of
/etc/NetworkManager/NetworkManager.conf, disabled journald
ratelimiting, reproduce the issue and attach the journal log of a boot
with hostname-mode=dhcp?

Beniamino

> 
> Can you help me figuring out my misunderstanding ?
> 
> Thanks for your help
> 
> --
> Thomas HUMMEL


signature.asc
Description: PGP signature
___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list