Revision f4a60a9b nest/rt-dev.c

View differences:

nest/rt-dev.c
24 24
#include "lib/resource.h"
25 25
#include "lib/string.h"
26 26

  
27

  
27 28
static void
28
dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad)
29
dev_ifa_notify(struct proto *P, uint flags, struct ifa *ad)
29 30
{
30
  struct rt_dev_config *P = (void *) p->cf;
31
  struct rt_dev_proto *p = (void *) P;
32
  struct rt_dev_config *cf = (void *) P->cf;
33
  struct channel *c;
31 34

  
32
  if (!EMPTY_LIST(P->iface_list) &&
33
      !iface_patt_find(&P->iface_list, ad->iface, ad->iface->addr))
35
  if (!EMPTY_LIST(cf->iface_list) &&
36
      !iface_patt_find(&cf->iface_list, ad->iface, ad->iface->addr))
34 37
    /* Empty list is automagically treated as "*" */
35 38
    return;
36 39

  
......
40 43
  if (ad->scope <= SCOPE_LINK)
41 44
    return;
42 45

  
43
  if (c & IF_CHANGE_DOWN)
46
  if (ad->prefix.type == NET_IP4)
47
    c = p->ip4_channel;
48
  else if (ad->prefix.type == NET_IP6)
49
    c = p->ip6_channel;
50
  else
51
    return;
52

  
53
  if (!c)
54
    return;
55

  
56
  if (flags & IF_CHANGE_DOWN)
44 57
    {
45 58
      net *n;
46 59

  
47 60
      DBG("dev_if_notify: %s:%I going down\n", ad->iface->name, ad->ip);
48
      n = net_find(p->table, &ad->prefix);
61
      n = net_find(c->table, &ad->prefix);
49 62
      if (!n)
50 63
	{
51 64
	  DBG("dev_if_notify: device shutdown: prefix not found\n");
......
53 66
	}
54 67

  
55 68
      /* Use iface ID as local source ID */
56
      struct rte_src *src = rt_get_source(p, ad->iface->index);
57
      rte_update2(p->main_ahook, n, NULL, src);
69
      struct rte_src *src = rt_get_source(P, ad->iface->index);
70
      rte_update2(c, n, NULL, src);
58 71
    }
59
  else if (c & IF_CHANGE_UP)
72
  else if (flags & IF_CHANGE_UP)
60 73
    {
61 74
      rta *a;
62 75
      net *n;
......
65 78
      DBG("dev_if_notify: %s:%I going up\n", ad->iface->name, ad->ip);
66 79

  
67 80
      /* Use iface ID as local source ID */
68
      struct rte_src *src = rt_get_source(p, ad->iface->index);
81
      struct rte_src *src = rt_get_source(P, ad->iface->index);
69 82

  
70 83
      rta a0 = {
71 84
	.src = src,
......
77 90
      };
78 91

  
79 92
      a = rta_lookup(&a0);
80
      n = net_get(p->table, &ad->prefix);
93
      n = net_get(c->table, &ad->prefix);
81 94
      e = rte_get_temp(a);
82 95
      e->net = n;
83 96
      e->pflags = 0;
84
      rte_update2(p->main_ahook, n, e, src);
97
      rte_update2(c, n, e, src);
85 98
    }
86 99
}
87 100

  
88 101
static struct proto *
89
dev_init(struct proto_config *c)
102
dev_init(struct proto_config *CF)
90 103
{
91
  struct proto *p = proto_new(c, sizeof(struct proto));
104
  struct proto *P = proto_new(CF);
105
  struct rt_dev_proto *p = (void *) P;
106
  // struct rt_dev_config *cf = (void *) CF;
92 107

  
93
  p->ifa_notify = dev_ifa_notify;
94
  return p;
108
  proto_configure_channel(P, &p->ip4_channel, proto_cf_find_channel(CF, NET_IP4));
109
  proto_configure_channel(P, &p->ip6_channel, proto_cf_find_channel(CF, NET_IP6));
110

  
111
  P->ifa_notify = dev_ifa_notify;
112

  
113
  return P;
95 114
}
96 115

  
97 116
static int
98
dev_reconfigure(struct proto *p, struct proto_config *new)
117
dev_reconfigure(struct proto *P, struct proto_config *CF)
99 118
{
100
  struct rt_dev_config *o = (struct rt_dev_config *) p->cf;
101
  struct rt_dev_config *n = (struct rt_dev_config *) new;
119
  struct rt_dev_proto *p = (void *) P;
120
  struct rt_dev_config *o = (void *) P->cf;
121
  struct rt_dev_config *n = (void *) CF;
122

  
123
  if (!iface_patts_equal(&o->iface_list, &n->iface_list, NULL))
124
    return 0;
125

  
126
  return
127
    proto_configure_channel(P, &p->ip4_channel, proto_cf_find_channel(CF, NET_IP4)) &&
128
    proto_configure_channel(P, &p->ip6_channel, proto_cf_find_channel(CF, NET_IP6));
102 129

  
103
  return iface_patts_equal(&o->iface_list, &n->iface_list, NULL);
130
  return 1;
104 131
}
105 132

  
106 133
static void
107 134
dev_copy_config(struct proto_config *dest, struct proto_config *src)
108 135
{
109
  struct rt_dev_config *d = (struct rt_dev_config *) dest;
110
  struct rt_dev_config *s = (struct rt_dev_config *) src;
136
  struct rt_dev_config *d = (void *) dest;
137
  struct rt_dev_config *s = (void *) src;
111 138

  
112 139
  /*
113 140
   * We copy iface_list as ifaces can be shared by more direct protocols.
......
120 147
struct protocol proto_device = {
121 148
  .name = 		"Direct",
122 149
  .template = 		"direct%d",
123
  .preference = 	DEF_PREF_DIRECT,
150
  .preference =		DEF_PREF_DIRECT,
151
  .channel_mask =	NB_IP,
152
  .proto_size =		sizeof(struct rt_dev_proto),
124 153
  .config_size =	sizeof(struct rt_dev_config),
125 154
  .init = 		dev_init,
126 155
  .reconfigure = 	dev_reconfigure,

Also available in: Unified diff