Revision 9a158361 sysdep/unix/krt-iface.c

View differences:

sysdep/unix/krt-iface.c
30 30
static void
31 31
scan_ifs(struct ifreq *r, int cnt)
32 32
{
33
  struct iface i;
33
  struct iface i, *pi;
34
  struct ifa a;
34 35
  char *err;
35 36
  unsigned fl;
36 37
  ip_addr netmask;
......
40 41
  for (cnt /= sizeof(struct ifreq); cnt; cnt--, r++)
41 42
    {
42 43
      bzero(&i, sizeof(i));
44
      bzero(&a, sizeof(a));
43 45
      DBG("%s\n", r->ifr_name);
44 46
      if (strchr(r->ifr_name, ':'))
45 47
	{
......
48 50
	  continue;
49 51
	}
50 52
      strncpy(i.name, r->ifr_name, sizeof(i.name) - 1);
51
      get_sockaddr((struct sockaddr_in *) &r->ifr_addr, &i.ip, NULL);
52
      if (ipa_nonzero(i.ip))
53
      get_sockaddr((struct sockaddr_in *) &r->ifr_addr, &a.ip, NULL);
54
      if (ipa_nonzero(a.ip))
53 55
	{
54
	  l = ipa_classify(i.ip);
56
	  l = ipa_classify(a.ip);
55 57
	  if (l < 0 || !(l & IADDR_HOST))
56 58
	    {
57 59
	      log(L_ERR "%s: Invalid interface address", i.name);
58
	      i.ip = IPA_NONE;
60
	      a.ip = IPA_NONE;
61
	    }
62
	  else
63
	    {
64
	      a.scope = l & IADDR_SCOPE_MASK;
65
	      if (a.scope == SCOPE_HOST)
66
		i.flags |= IF_LOOPBACK | IF_IGNORE;
59 67
	    }
60
	  else if ((l & IADDR_SCOPE_MASK) == SCOPE_HOST)
61
	    i.flags |= IF_LOOPBACK | IF_IGNORE;
62 68
	}
63 69

  
64 70
      if (ioctl(if_scan_sock, SIOCGIFFLAGS, r) < 0)
......
83 89
	  log(L_ERR "%s: Invalid netmask", i.name);
84 90
	  goto bad;
85 91
	}
86
      i.pxlen = l;
92
      a.pxlen = l;
87 93

  
88 94
      if (fl & IFF_POINTOPOINT)
89 95
	{
90 96
	  i.flags |= IF_UNNUMBERED;
91
	  i.pxlen = BITS_PER_IP_ADDRESS;
97
	  a.pxlen = BITS_PER_IP_ADDRESS;
92 98
	  if (ioctl(if_scan_sock, SIOCGIFDSTADDR, r) < 0)
93 99
	    { err = "SIOCGIFDSTADDR"; goto faulty; }
94
	  get_sockaddr((struct sockaddr_in *) &r->ifr_addr, &i.opposite, NULL);
100
	  get_sockaddr((struct sockaddr_in *) &r->ifr_addr, &a.opposite, NULL);
95 101
	}
96 102
      if (fl & IFF_LOOPBACK)
97 103
	i.flags |= IF_LOOPBACK | IF_IGNORE;
......
100 106
#endif
101 107
	i.flags |= IF_MULTICAST;
102 108

  
103
      i.prefix = ipa_and(i.ip, ipa_mkmask(i.pxlen));
104
      if (i.pxlen < 32)
109
      a.prefix = ipa_and(a.ip, ipa_mkmask(a.pxlen));
110
      if (a.pxlen < 32)
105 111
	{
106
	  i.brd = ipa_or(i.prefix, ipa_not(ipa_mkmask(i.pxlen)));
107
	  if (ipa_equal(i.ip, i.prefix) || ipa_equal(i.ip, i.brd))
112
	  a.brd = ipa_or(a.prefix, ipa_not(ipa_mkmask(a.pxlen)));
113
	  if (ipa_equal(a.ip, a.prefix) || ipa_equal(a.ip, a.brd))
108 114
	    {
109 115
	      log(L_ERR "%s: Using network or broadcast address for interface", i.name);
110 116
	      goto bad;
111 117
	    }
112 118
	  if (fl & IFF_BROADCAST)
113 119
	    i.flags |= IF_BROADCAST;
114
	  if (i.pxlen < 30)
120
	  if (a.pxlen < 30)
115 121
	    i.flags |= IF_MULTIACCESS;
116 122
	  else
117
	    i.opposite = ipa_opposite(i.ip);
123
	    a.opposite = ipa_opposite(a.ip);
118 124
	}
119 125
      else
120
	i.brd = i.opposite;
126
	a.brd = a.opposite;
121 127

  
122 128
      if (ioctl(if_scan_sock, SIOCGIFMTU, r) < 0)
123 129
	{ err = "SIOCGIFMTU"; goto faulty; }
......
132 138
      /* FIXME: What else? Guess ifindex (we need it at least for OSPF on unnumbered links)? */
133 139
#endif
134 140

  
135
      if_update(&i);
141
      pi = if_update(&i);
142
      a.iface = pi;
143
      ifa_update(&a);
136 144
    }
137 145
  if_end_update();
138 146
}

Also available in: Unified diff