Skip to content

Commit

Permalink
appconfig: move extension prototypes to extension.h
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomaschewski committed Jan 24, 2023
1 parent 5306f63 commit 2c7025f
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 181 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ wicked_headers = \
dhcp6/tester.h \
dhcp.h \
duid.h \
extension.h \
firmware.h \
iaid.h \
ibft.h \
Expand Down
120 changes: 32 additions & 88 deletions src/appconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <dlfcn.h>
#include <netinet/if_ether.h>

#include <wicked/util.h>
Expand All @@ -25,6 +24,7 @@
#include "netinfo_priv.h"
#include "util_priv.h"
#include "appconfig.h"
#include "extension.h"
#include "xml-schema.h"
#include "dhcp.h"
#include "duid.h"
Expand All @@ -46,12 +46,10 @@ static ni_bool_t ni_config_parse_objectmodel_extension(ni_extension_t **, xml_no
static ni_bool_t ni_config_parse_objectmodel_netif_ns(ni_extension_t **, xml_node_t *);
static ni_bool_t ni_config_parse_objectmodel_firmware_discovery(ni_extension_t **, xml_node_t *);
static ni_bool_t ni_config_parse_system_updater(ni_extension_t **, xml_node_t *);
static ni_bool_t ni_config_parse_extension(ni_extension_t *, xml_node_t *);
static ni_bool_t ni_config_parse_sources(ni_config_t *, xml_node_t *);
static ni_bool_t ni_config_parse_rtnl_event(ni_config_rtnl_event_t *, xml_node_t *);
static ni_bool_t ni_config_parse_bonding(ni_config_bonding_t *, const xml_node_t *);
static ni_bool_t ni_config_parse_teamd(ni_config_teamd_t *, const xml_node_t *);
static ni_c_binding_t * ni_c_binding_new(ni_c_binding_t **, const char *name, const char *lib, const char *symbol);
static const char * ni_config_build_include(char *, size_t, const char *, const char *);
static unsigned int ni_config_addrconf_update_mask_all(void);
static unsigned int ni_config_addrconf_update_mask_dhcp4(void);
Expand Down Expand Up @@ -1313,37 +1311,6 @@ ni_config_parse_fslocation(ni_config_fslocation_t *fsloc, xml_node_t *node)
ni_parse_uint(attrval, &fsloc->mode, 8);
}

/*
* Object model extensions let you implement parts of a dbus interface separately
* from the main wicked body of code; either through a shared library or an
* external command/shell script
*
* <extension interface="org.opensuse.Network.foobar">
* <action name="dbusMethodName" command="/some/shell/scripts some-args"/>
* <builtin name="dbusOtherMethodName" library="/usr/lib/libfoo.so" symbol="c_method_impl_name"/>
*
* <putenv name="WICKED_OBJECT_PATH" value="$object-path"/>
* <putenv name="WICKED_INTERFACE_NAME" value="$property:name"/>
* <putenv name="WICKED_INTERFACE_INDEX" value="$property:index"/>
* </extension>
*/
ni_bool_t
ni_config_parse_objectmodel_extension(ni_extension_t **list, xml_node_t *node)
{
ni_extension_t *ex;
const char *name;

if (!(name = xml_node_get_attr(node, "interface"))) {
ni_error("%s: <%s> element lacks interface attribute",
node->name, xml_node_location(node));
return FALSE;
}

ex = ni_extension_new(list, name);

return ni_config_parse_extension(ex, node);
}

static ni_bool_t
ni_config_parse_extension(ni_extension_t *ex, xml_node_t *node)
{
Expand Down Expand Up @@ -1396,6 +1363,37 @@ ni_config_parse_extension(ni_extension_t *ex, xml_node_t *node)
return TRUE;
}

/*
* Object model extensions let you implement parts of a dbus interface separately
* from the main wicked body of code; either through a shared library or an
* external command/shell script
*
* <extension interface="org.opensuse.Network.foobar">
* <action name="dbusMethodName" command="/some/shell/scripts some-args"/>
* <builtin name="dbusOtherMethodName" library="/usr/lib/libfoo.so" symbol="c_method_impl_name"/>
*
* <putenv name="WICKED_OBJECT_PATH" value="$object-path"/>
* <putenv name="WICKED_INTERFACE_NAME" value="$property:name"/>
* <putenv name="WICKED_INTERFACE_INDEX" value="$property:index"/>
* </extension>
*/
ni_bool_t
ni_config_parse_objectmodel_extension(ni_extension_t **list, xml_node_t *node)
{
ni_extension_t *ex;
const char *name;

if (!(name = xml_node_get_attr(node, "interface"))) {
ni_error("%s: <%s> element lacks interface attribute",
node->name, xml_node_location(node));
return FALSE;
}

ex = ni_extension_new(list, name);

return ni_config_parse_extension(ex, node);
}

/*
* Object model naming extensions let you implement alternative ways of specifying
* a network interface. This should help avoid all the messy udev tricks with renaming
Expand Down Expand Up @@ -1716,60 +1714,6 @@ ni_config_find_system_updater(ni_config_t *conf, const char *name)
return ni_extension_list_find(conf->updater_extensions, name);
}

/*
* Handle methods implemented via C bindings
*/
static ni_c_binding_t *
ni_c_binding_new(ni_c_binding_t **list, const char *name, const char *library, const char *symbol)
{
ni_c_binding_t *binding, **pos;

for (pos = list; (binding = *pos) != NULL; pos = &binding->next)
;

binding = xcalloc(1, sizeof(*binding));
ni_string_dup(&binding->name, name);
ni_string_dup(&binding->library, library);
ni_string_dup(&binding->symbol, symbol);

*pos = binding;
return binding;
}

void
ni_c_binding_free(ni_c_binding_t *binding)
{
ni_string_free(&binding->name);
ni_string_free(&binding->library);
ni_string_free(&binding->symbol);
free(binding);
}

void *
ni_c_binding_get_address(const ni_c_binding_t *binding)
{
void *handle;
void *addr;

handle = dlopen(binding->library, RTLD_LAZY);
if (handle == NULL) {
ni_error("invalid binding for %s - cannot dlopen(%s): %s",
binding->name, binding->library?: "<main>", dlerror());
return NULL;
}

addr = dlsym(handle, binding->symbol);
dlclose(handle);

if (addr == NULL) {
ni_error("invalid binding for %s - no such symbol in %s: %s",
binding->name, binding->library?: "<main>", binding->symbol);
return NULL;
}

return addr;
}

/*
* Query the default update mask
*/
Expand Down
58 changes: 24 additions & 34 deletions src/appconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ typedef struct ni_config_fslocation {
struct ni_extension {
ni_extension_t * next;

/* Name of the extension, such as "dhcp4". */
/* Name of the extension */
char * name;

/* Supported dbus interface */
char * interface;

/* Format type. Only in use by system-updater. */
/* Format type used by system-updater */
char * format;

/* Shell commands */
Expand Down Expand Up @@ -170,13 +170,13 @@ typedef struct ni_config {
ni_config_fslocation_t backupdir;

struct {
unsigned int default_allow_update;
unsigned int default_allow_update;

ni_config_dhcp4_t dhcp4;
ni_config_dhcp6_t dhcp6;
ni_config_dhcp4_t dhcp4;
ni_config_dhcp6_t dhcp6;

ni_config_auto4_t auto4;
ni_config_auto6_t auto6;
ni_config_auto4_t auto4;
ni_config_auto6_t auto6;

} addrconf;

Expand All @@ -199,40 +199,30 @@ typedef struct ni_config {
ni_config_teamd_t teamd;
} ni_config_t;

extern ni_config_t * ni_config_new();
extern void ni_config_free(ni_config_t *);
extern ni_config_t * ni_config_parse(const char *, ni_init_appdata_callback_t *, void *);
extern ni_extension_t * ni_config_find_extension(ni_config_t *, const char *);
extern ni_extension_t * ni_config_find_system_updater(ni_config_t *, const char *);
extern unsigned int ni_config_addrconf_update_mask(ni_addrconf_mode_t, unsigned int);
extern unsigned int ni_config_addrconf_update(const char *, ni_addrconf_mode_t, unsigned int);
extern ni_config_t * ni_config_new();
extern void ni_config_free(ni_config_t *);
extern ni_config_t * ni_config_parse(const char *, ni_init_appdata_callback_t *, void *);
extern ni_extension_t * ni_config_find_extension(ni_config_t *, const char *);
extern ni_extension_t * ni_config_find_system_updater(ni_config_t *, const char *);
extern unsigned int ni_config_addrconf_update_mask(ni_addrconf_mode_t, unsigned int);
extern unsigned int ni_config_addrconf_update(const char *, ni_addrconf_mode_t, unsigned int);

extern const ni_config_dhcp4_t * ni_config_dhcp4_find_device(const char *);
extern const char * ni_config_dhcp4_cid_type_format(ni_config_dhcp4_cid_type_t);
extern ni_bool_t ni_config_dhcp4_cid_type_parse(ni_config_dhcp4_cid_type_t *, const char *);
extern const ni_config_dhcp6_t * ni_config_dhcp6_find_device(const char *);
extern const ni_config_dhcp4_t *ni_config_dhcp4_find_device(const char *);
extern const char * ni_config_dhcp4_cid_type_format(ni_config_dhcp4_cid_type_t);
extern ni_bool_t ni_config_dhcp4_cid_type_parse(ni_config_dhcp4_cid_type_t *, const char *);
extern const ni_config_dhcp6_t *ni_config_dhcp6_find_device(const char *);

extern ni_config_bonding_ctl_t ni_config_bonding_ctl(void);

extern ni_bool_t ni_config_teamd_enable(ni_config_teamd_ctl_t);
extern ni_bool_t ni_config_teamd_disable(void);
extern ni_bool_t ni_config_teamd_enabled(void);
extern ni_bool_t ni_config_teamd_enable(ni_config_teamd_ctl_t);
extern ni_bool_t ni_config_teamd_disable(void);
extern ni_bool_t ni_config_teamd_enabled(void);
extern ni_config_teamd_ctl_t ni_config_teamd_ctl(void);
extern const char * ni_config_teamd_ctl_type_to_name(ni_config_teamd_ctl_t);
extern const char * ni_config_teamd_ctl_type_to_name(ni_config_teamd_ctl_t);

extern ni_extension_t * ni_extension_list_find(ni_extension_t *, const char *);
extern void ni_extension_list_destroy(ni_extension_t **);
extern ni_extension_t * ni_extension_new(ni_extension_t **, const char *);
extern void ni_extension_free(ni_extension_t *);
extern void ni_config_fslocation_init(ni_config_fslocation_t *, const char *, unsigned int);
extern void ni_config_fslocation_destroy(ni_config_fslocation_t *);

extern void ni_c_binding_free(ni_c_binding_t *);
extern void * ni_c_binding_get_address(const ni_c_binding_t *);

extern ni_shellcmd_t * ni_extension_script_new(ni_extension_t *, const char *name, const char *command);
extern ni_shellcmd_t * ni_extension_script_find(ni_extension_t *, const char *);
extern const ni_c_binding_t *ni_extension_find_c_binding(const ni_extension_t *, const char *name);
extern void ni_config_fslocation_init(ni_config_fslocation_t *, const char *, unsigned int);
extern void ni_config_fslocation_destroy(ni_config_fslocation_t *);
typedef struct ni_global {
int initialized;
char * config_path;
Expand Down
1 change: 1 addition & 0 deletions src/dbus-objects/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "xml-schema.h"
#include "model.h"
#include "appconfig.h"
#include "extension.h"
#include "debug.h"
#include "dbus-connection.h"
#include "process.h"
Expand Down
1 change: 1 addition & 0 deletions src/dbus-objects/naming.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "dbus-common.h"
#include "model.h"
#include "appconfig.h"
#include "extension.h"
#include "debug.h"

static unsigned int ni_objectmodel_ns_count;
Expand Down
Loading

0 comments on commit 2c7025f

Please sign in to comment.