Skip to content

Commit

Permalink
nanny: Do not update <client-into> and client-state> by default
Browse files Browse the repository at this point in the history
Update only when new policy is to be applied by nanny
(device is explicitly enabled). Thus nanny update states
when it is responsible for configuration, and does not
update when ifup is doing it's job.
  • Loading branch information
wipawel committed Feb 24, 2014
1 parent 8f9bedc commit fd5ee43
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions nanny/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ void
ni_managed_device_apply_policy(ni_managed_device_t *mdev, ni_managed_policy_t *mpolicy)
{
ni_ifworker_t *w = mdev->worker;
ni_fsm_t *fsm = mdev->nanny->fsm;
const char *type_name;
const ni_fsm_policy_t *policy = mpolicy->fsm_policy;
xml_node_t *config = NULL;
Expand Down Expand Up @@ -167,6 +168,10 @@ ni_managed_device_apply_policy(ni_managed_device_t *mdev, ni_managed_policy_t *m

ni_debug_nanny("%s: using policy %s", w->name, ni_fsm_policy_name(policy));

/* Set FSM and current ifworker as writable, nanny can update wickedd structures */
w->readonly = FALSE;
fsm->readonly = FALSE;

/* This returns "modem" or "interface" */
type_name = ni_ifworker_type_to_string(w->type);

Expand Down
11 changes: 11 additions & 0 deletions nanny/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,20 @@ void
babysit(void)
{
ni_nanny_t *mgr;
ni_fsm_t *fsm;

mgr = ni_nanny_new();

if (ni_init_ex("nanny", ni_nanny_config_callback, mgr) < 0)
ni_fatal("error in configuration file");

ni_nanny_start(mgr);
fsm = mgr->fsm;

/* Nanny should not update neither <client-info> nor <client-state>,
* unless it is told to configure a device by 'wicked enable'.
*/
fsm->readonly = TRUE;

if (!opt_foreground) {
if (ni_server_background(program_name) < 0)
Expand All @@ -214,6 +221,10 @@ babysit(void)
ni_nanny_down_do(mgr);

ni_fsm_do(mgr->fsm, &timeout);

/* Set back the FSM to readonly after job is done */
fsm->readonly = TRUE;

if (ni_socket_wait(timeout) != 0)
ni_fatal("ni_socket_wait failed");
}
Expand Down
2 changes: 1 addition & 1 deletion src/fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2383,6 +2383,7 @@ ni_fsm_recv_new_netif(ni_fsm_t *fsm, ni_dbus_object_t *object, ni_bool_t refresh
if (!found) {
ni_debug_application("received new device %s (%s)", dev->name, object->path);
found = ni_ifworker_new(fsm, NI_IFWORKER_TYPE_NETDEV, dev->name);
found->readonly = fsm->readonly;
if (dev->client_info)
ni_ifworker_refresh_client_info(found, dev->client_info);
if (dev->client_state)
Expand All @@ -2395,7 +2396,6 @@ ni_fsm_recv_new_netif(ni_fsm_t *fsm, ni_dbus_object_t *object, ni_bool_t refresh
found->device = ni_netdev_get(dev);
found->ifindex = dev->link.ifindex;
found->object = object;
found->readonly = fsm->readonly;

/* Don't touch devices we're done with */

Expand Down

0 comments on commit fd5ee43

Please sign in to comment.