Re: How to add a plugin for NM



On Tue, 2010-03-23 at 20:55 +0800, Mu Qiao wrote:
> Hello,
> 
> I need to develop a plugin for NM to read local configuration files
> just like RH and Ubuntu do. (I'm not sure whether the plugin is
> ifcfg-rh and ifupdown)

Great!

> Where should I start? Where can I find documentations for developing
> plugin and source code of ifcfg-rh and ifupdown?

The C interface is documented in:

http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/src/system-settings/nm-system-config-interface.h

The 'keyfile' connection is probably the best example so far as it's
most complete:

http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/system-settings/plugins/keyfile

But the ifcfg-suse plugin is actually the simplest one that just
provides persistent hostname support.

Basically, you have a GObject subclass that implements
NM_TYPE_SYSTEM_CONFIG_INTERFACE, which is the first link I pasted.  That
implements the actual plugin, which has a number of properties that
NetworkManager asks for like hostname and capabilities.

That object then parses the config files, and for each distinct saved
network "profile" or whatever on your distro, you create an object
that's a subclass of NMSysconfigConnection as you can see in:

http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/system-settings/plugins/keyfile/nm-keyfile-connection.h

NMSysconfigConnection provides a number of helpful class functions that
make your implementation a bit easier.  In any case, your connection
subclass just wraps each distinct saved connection profile and watches
that profile for changes.  The actual read/write work I usually put into
separate files since they are easier to link into the unit test
programs, plus the connection subclass can easily use them anyway.

If you need more pointers, let me know.  It does get somewhat
complicated when you do everything like reading and writing connections,
but starting simple and expanding from there should be an easier way to
go.

Dan




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]