You are not logged in.

#1 2007-08-11 17:27:26

Defre
Member
Registered: 2007-08-11
Posts: 7

netconf - select network profiles

Hi,

I am new to Archlinux, and pretty satisfied of this distribution.
I found the concept of netcfg useful but too limited, so I programmed my own network profiles management: netconf.
It allows to completely manage network configuration (and if needed network deamons) using profiles, and it uses the same syntax as netcfg (except -c switch, see below):

netconf v0.2

usage: netconf <profile_name>
       netconf --stop <interface|profile>
       netconf --menu [--timeout <secs>]
       netconf --stopall

Network profiles are stored in /etc/network-profiles

It supports old profiles syntax, so it can work with old profiles out of the box, just symlink netconf to netcfg (no need to modify initscripts and have bad surprise).

So what is the interests of replacing netcfg by netconf?

Dependencies
Profiles may require other profiles to be turned on or off, restarted, or two of them may simply be not compatible.
For instance, a profile to share connection between an ethernet card and a wireless lan requires both card profile and wifi profile to be turned on. The activation of an ADSL profile may require br2684ctl to be switched on and PPPoE to be restarted.

At interfaces level, profiles may provide support for one or more interfaces. Two profiles providing the same interface can't be simultaneously enabled. Also, there is an "alias" between profiles and provided interfaces. This way, netconf --stop eth1 will automatically stop last profile associated to eth1.

Modes
To customize behavior of your profile it may be useful to execute custom commands, not possible with netcfg.
At different moment of the activation or disactivation process, netconf loader executes various functions ( pre/set/post - up|down ). But having to provide such functions in each profile isn't cool, so modes have been introduced.
Currently, only old mode have been developed: it allows to load and unload old style profiles (it is the default mode in order to maintain compatibility with netcfg). But ppp, wifi, deamons, bridge profiles may be developped.

Menu
The menu switch --menu have been improved. It now allows to switch one or off multiple profiles at the same time.

How it works
Entirely programmed in bash script.
The tool behind netconf is netconf-loader. It is executed to enable or disable profile and validate "transactions". Transactions allow multiple actions to be executed, while checking dependencies satisfaction.
netconf-loader

usage: netconf-loader <action> <profile or interface>
       netconf-loader begin
       netconf-loader finish <[O] or 1>

actions:
  load  Load specified profile
  auto  Autoload specified profile
        (will automatically be unloaded)
  unload        Unload specified profile
  loaded        True (0) if specified profile is loaded
                False (1) otherwise
  desc  Echo profile description

  begin Begin transaction
  finish [0]    Transaction finished correctly, no error
  finish 1      Transaction failed

Network profiles are stored in /etc/network-profiles

Executing "netconf-loader finish 1" allow to disable all interfaces activated since transaction begins.
Transaction sample (automatically executed by netconf):
netconf-loader begin
netconf-loader load wlan0
netconf-loader load eth0
netconf-loader load forward_eth0
netconf-loader finish

Creating Profiles
A profile is simply a bash script initializing some global variables.
Needed variables:

MODES: array defining modes to load.
Default: MODES=(old).

DESCRIPTION: string containing description to be shown in menu.
Default: DESCRIPTION="" (hide)

Then, you must define all variables needed by specified modes.

Creating Modes
Modes are bash scripts contained in /usr/share/netconf/modes/.
They must define following functions, returning 0 if ok, >0 otherwise:

get-info() { ... }:
Must set global arrays DEPENDS and PROVIDES.
PROVIDES lists interfaces managed by this profile
e.g. : PROVIDES=(eth0 eth1)

DEPENDS syntax is a bit more tricky.
Example (where pN is a profile or an interface) :
DEPENDS=(p1 +p2 -p3 !p4 -!p5 @p6)
Which means:
p1: p1 is required, it must be activated before current profile.
+p2: p2 is required and if possible will be automatically managed (will be automatically stopped if unused, for instance will stopping current profile).
-p3: unload p3 immediately.
!p4: current profile and p4 can't be activated simultaneously. Thus p4 is blacklisted until end of current profile.
-!p5: syntactic sugar meaning -p5 !p5 "stop p5 and don't run it while current profile is enabled".
@p6: restart p6. p6 is immediately unloaded and will be reloaded after setting up current profile (useful for PPPoE deamons).

pre-up() { ... }:
Called at the beginning of the activation action.
set-up() { ... }:
Main profile activation function. Called after dependencies check.
post-up() { ... }:
Called at the end if everything worked fine. Useful to execute action after reloading a profile using @profile dependence.

Following functions can set FORCE global variable to 1 to don't stop process if problems happen.
pre-down() { ... }:
Called at the beginning of the disactivation action.
set-down() { ... }:
Main profile disactivation function. Called after unloading profile dependencies.
post-down() { ... }:
Called at the end after updating blacklists infos and interfaces aliases.

Sorry to have taken so much of your time
I hope you've been a bit interested. If you want to try, i can send you sources via mail/pm.
Remember, it's an alpha version: need to be debugged; so it will be kind to test it, send bug reports etc, but don't use in a production environment, and keep a link to default netcfg.

Building package: don't know how to do. However, here are netconf files:
/usr/bin/netconf
/usr/bin/netconf-loader
/usr/share/netconf/netconf.conf
/usr/share/netconf/modes/old

Variables dirs:
/var/run/netconf/activated - global state
/var/run/netconf/loading - current transaction state

Very truly,
Fred

Offline

#2 2007-08-11 22:03:11

ristretto
Member
Registered: 2007-07-06
Posts: 50

Re: netconf - select network profiles

Hello Fred,  On my laptop, I've set up a bridged network in rc.conf.  It works fine.  However, I would like to set it up with profiles. 

Do I need to use netconf?  Or is this possible with netcfg?

I want to use profiles, so I can set up the bridged network over either a wired or wireless network.   (Or choose a non-bridged connection.)

Also, I use netfs to mount a samba share (when on my LAN.)  For some reason, during normal start up (no profiles), the bridged network comes up too slowly.  So netfs fails.  I have to then run netfs when I get a prompt.  I sort of hack fixed that with a 'sleep 5' line in /etc/rc.d/netfs.  I'm wondering if netconf can help there too?

I might be willing to run and test for you.  Just want to make sure I can't do this some other way first.

Offline

Board footer

Powered by FluxBB