LinkedIn Sourceforge Twitter

Vincent's Blog

Pleasure in the job puts perfection in the work (Aristote)

New nmctl : network manager for openbsd: nmctl-0.5.0

Posted on 2018-09-19 22:45:00 from Vincent in Open Bsd nmctl

It's now several weeks I'm using the "auto-join" features of OpenBSD-current. I'll explain why I'm yet back to my nmctl script. This version 0.5 of nmctl it a total re-write of nmctl 0.4.x.


No more the last post concerning nmctl. Please check the category nmctl

Introduction

As said in my previous blogs, I'm travelling with my OpenBSD's laptop and because my laziness to always adapt my /etc/hostname.if files.

When I saw the commit of Peter Hessler with "auto-join", I jump on it immediately. And I thought that I could drop my nmctl script which do the same.

Before explaining why I come back to nmctl, let me first share my feedbacks about "auto-join".

My feedback on auto-join

This new feature committed some weeks ago is a great feature for people having to connect their machine to different wifi's AP.

Every time you will trigger /etc/netstart, OpenBSD will check if one of the nwid around you is configured in your /etc/hostname.if file via a"join" command. If it match it will automatically connect it.

Saying that the feature sounds really cool.

But

In my case, there is a but :-(.

The auto-join does not allow me to switch between cable and wifi connections. To allow such, nice and smooth, switch you have to use the trunk element.

And the problems come when you want to switch between 2 nwid, in the same area. For example, switching from the "corporate wifi" to the "Guest wifi". In such case, if I'm correct, "auto-join will take the first listed in /etc/hostname.if.

So, in some case to connect to the nwid I want, I was back to command line to type the ifconfig commands with the good parameters. But I'm lazy and don't like to do that.

Be sure that I do not ask people to go away from the "auto-join". This feature is really good. But, hope you have understood, that in my case, it does not facilitate my task.

So, I've jump once again in nmctl.

Why I'm back with nmctl ?

One of the feature of nmctl is equivalent to the "auto-join" feature.

By typing "nmctl -r", you ask nmctl to try every network config described in /etc/nmctl.conf. nmctl loops around all config until one succeed to perform a connection (in other words doing a ping to 8.8.8.8). This is were nmctl is equivalent to 'auto-join".

What nmctl offers too, is the possibility to define different network config for the same interface. For example, you could have a config to connect one wifi via DHCP. But you could also have a config to connect the same wifi, but with a static IP address.

And you could have such network config for cable connections too. And here, without nmctl, you are back to the command lines.

All in all nmctl has the features of auto-join, but I keep lot of flexibility with my network configs.
That's the main reason why I'm back to nmctl and why I review it (and in fact re-write it).

Download and install nmctl

If you want to give nmctl a try, you can download it here.
The code is locate here

As pre-requisites, you have to install python3 and python-tkinter if you want to use the gui part.

To install nmctl, just type "doas make".

I remind that you have to add nmctl in you doas.conf. Something like this should work: "permit nopass keepenv -userid- as root cmd nmctl"
Replace -userid- by your userid and keep "keepenv" for the gui part.

If this tool helps someone, do not hesitate to let me know it ;-).

Short description of what nmctl provides

The global philosophy of nmctl has not changed, but let me remind you what nmctl offers.

First, you have to define your different network configs in /etc/nmctl.conf.

Each network config has a name and a physical interface associated to it. Then you must describe the list of commands you want to apply. Those lines are very close to what you type in your /etc/hostname.if file.

You can trigger one of your network config by typing his name: nmctl home . In this case "home" is the name of my wifi network at home where I connect it via dhcp.

The "auto-join like" feature is still present. You could ask nmctl to find himself which network interface work for you (in the location you are). In this case just type: nmctl -r

For those who are willing to better understand this "automatic discovery" process, I post the detailed log file here bellow.

If you have defined several network config for one wifi AP (for example), you can ask nmctl to display you the one you are currently using. Just type: nmctl -c

And, for lazy people like me, there is a gui interface allowing you to perform those selections by just clicking on the correct button. In my case, I must click on one icon of my tint2 (very cool application) bar and nmctl -g is triggered

All in all, you configure once for all the network parameters in /etc/nmctl.conf and the rest comes easily.

All this "magic" is possible because of OpenBSD's tools present in "base" like : ifconfig and dhclient. For the gui part, you must install python-tkinter.

Open wifi

In some rare cases (hotel, restaurants, ...) you can use nmctl to help you to have a connection with an "open wifi".

On the gui part, you just have to click on the button in order to scan the network around you. Then you click on the button close to the nwid you want to connect. This is nice add-on for very lazy persons ;-).

You can also perform the same action with the commands: nmctl -s and nmctl -o nwid. It's just a easier than with the ifconfig command.

Some screenshots

Here after some screen shots:

Some log file

By enabling the debug mode, you can follow ll action nmctl is doing:

Output after I trigger nmctl -r:

Mon Sep 17 20:52:49 2018: execute "ifconfig iwm0 up" : rc=0
Mon Sep 17 20:52:49 2018: execute "ifconfig iwm0 scan": stdout lenght= 782
Mon Sep 17 20:52:49 2018: Return scan data length: 2
Mon Sep 17 20:52:49 2018: NWID around you are: Linksys19594,WiFi-5.0-7DE0
Mon Sep 17 20:52:49 2018: We try cable
Mon Sep 17 20:52:50 2018: No carrier on em0. We skip cable
Mon Sep 17 20:52:50 2018: We try vacances
Mon Sep 17 20:52:50 2018: Livebox-446E not detected around you. We skip it
Mon Sep 17 20:52:50 2018: We try lgg6
Mon Sep 17 20:52:50 2018: G6_8070 not detected around you. We skip it
Mon Sep 17 20:52:50 2018: We try homewifi
Mon Sep 17 20:52:50 2018: execute "ifconfig iwm0 -group "homewifi_NM"" : rc=0
Mon Sep 17 20:52:50 2018: execute "ps ax": stdout lenght= 3350
Mon Sep 17 20:52:50 2018: execute "pkill dhclient" : rc=0
Mon Sep 17 20:52:50 2018: execute "ifconfig iwm0 delete" : rc=0
Mon Sep 17 20:52:50 2018: execute "ifconfig iwm0 down" : rc=0
Mon Sep 17 20:52:50 2018: execute "ifconfig iwm0 up" : rc=0
Mon Sep 17 20:52:50 2018: execute "route flush" : rc=0
Mon Sep 17 20:52:50 2018: execute "arp -a -d" : rc=0
Mon Sep 17 20:52:50 2018: execute "ifconfig iwm0 nwid Linksys19594  ..." : rc=0
Mon Sep 17 20:52:54 2018: execute "dhclient iwm0" : rc=0
Mon Sep 17 20:52:54 2018: Test connectivity on Linksys19594 via iwm0, timeout set to:None
Mon Sep 17 20:52:54 2018:   UP found on iwm0 interface
Mon Sep 17 20:52:54 2018:   Linksys19594 found on iwm0 interface
Mon Sep 17 20:52:56 2018: execute "ping -c3 -w5 8.8.8.8" : rc=0
Mon Sep 17 20:52:56 2018:   ping successfull: rc=0
Mon Sep 17 20:52:56 2018: Connected to homewifi via iwm0
Mon Sep 17 20:52:56 2018: execute "ifconfig iwm0 group "homewifi_NM"" : rc=0

Answer after a nmctl -c:

Mon Sep 17 21:33:02 2018: Connected on homewifi via iwm0

My /etc/nmctl.conf

As sample, here after my config file.

As you could guess, the "fixed IP" config are put at the end of the config because in the "automatic discovery" process, I prefer that nmctl find the config with dhcp.

This "fixed ip" config are there because in some cases I trigger them.

This config file could allow you to better understand some messages in the log here above.

iwm0:open
 !route flush
# !arp -a -d  
 <nwid> -wpa
 dhcp

em0:cable
 !route flush
 !arp -a -d
 dhcp

iwm0:vacances
 !route flush
 nwid Livebox-446E wpakey passphrase
 dhcp

iwm0:lgg6
 !route flush
 !arp -a -d
 nwid G6_8070 wpakey passphrase
 dhcp

iwm0:homewifi
 !route flush
 !arp -a -d
 nwid Linksys19594 wpakey passphrase
 dhcp

iwm0:college
 !route flush
 nwid COLLEGE wpakey passphrase
 dhcp

em0:cable_fixip
 !route flush
 !arp -a -d
 inet 192.168.3.3 netmask 0xffffff00
 !route add -host default 192.168.3.1

em0:cable_random
 !route flush
 !arp -a -d
 lladdr random
 dhcp


3, 0
displayed: 2183



How much does 4 plus 2 ?