Revision 62e64905 sysdep/bsd/krt-sock.c

View differences:

sysdep/bsd/krt-sock.c
193 193
  struct ks_msg msg;
194 194
  char *body = (char *)msg.buf;
195 195
  sockaddr gate, mask, dst;
196
  ip_addr gw;
197 196

  
198 197
  DBG("krt-sock: send %I/%d via %I\n", net->n.prefix, net->n.pxlen, a->gw);
199 198

  
......
223 222
    msg.rtm.rtm_flags |= RTF_BLACKHOLE;
224 223
#endif
225 224

  
226
  /* This is really very nasty, but I'm not able
227
   * to add "(reject|blackhole)" route without
228
   * gateway set
225
  /*
226
   * This is really very nasty, but I'm not able to add reject/blackhole route
227
   * without gateway address.
229 228
   */
230
  if(!i)
229
  if (!i)
231 230
  {
232
    i = HEAD(iface_list);
233

  
234 231
    WALK_LIST(j, iface_list)
235 232
    {
236 233
      if (j->flags & IF_LOOPBACK)
......
239 236
        break;
240 237
      }
241 238
    }
242
  }
243 239

  
244
  gw = a->nh.gw;
245

  
246
  /* Embed interface ID to link-local address */
247
  if (ipa_is_link_local(gw))
248
    _I0(gw) = 0xfe800000 | (i->index & 0x0000ffff);
240
    if (!i)
241
    {
242
      log(L_ERR "KRT: Cannot find loopback iface");
243
      return -1;
244
    }
245
  }
249 246

  
250 247
  int af = AF_UNSPEC;
251 248

  
......
261 258
      return -1;
262 259
  }
263 260

  
264

  
265 261
  sockaddr_fill(&dst,  af, net_prefix(net->n.addr), NULL, 0);
266 262
  sockaddr_fill(&mask, af, net_pxmask(net->n.addr), NULL, 0);
267
  sockaddr_fill(&gate, af, gw, NULL, 0);
268 263

  
269 264
  switch (a->dest)
270 265
  {
271
    case RTD_UNICAST:
272
      if (ipa_zero(gw))
273
      {
274
	if(i)
275
	{
276
#ifdef RTF_CLONING
277
	  if (cmd == RTM_ADD && (i->flags & IF_MULTIACCESS) != IF_MULTIACCESS)	/* PTP */
278
	    msg.rtm.rtm_flags |= RTF_CLONING;
279
#endif
266
  case RTD_UNICAST:
267
    if (ipa_nonzero(a->nh.gw))
268
    {
269
      ip_addr gw = a->nh.gw;
280 270

  
281
	  if(!i->addr) {
282
	    log(L_ERR "KRT: interface %s has no IP addess", i->name);
283
	    return -1;
284
	  }
285

  
286
	  sockaddr_fill(&gate, ipa_is_ip4(i->addr->ip) ? AF_INET : AF_INET6, i->addr->ip, NULL, 0);
287
	  msg.rtm.rtm_addrs |= RTA_GATEWAY;
288
	}
289
      } else {
290
	msg.rtm.rtm_flags |= RTF_GATEWAY;
291
	msg.rtm.rtm_addrs |= RTA_GATEWAY;
292
      }
271
      /* Embed interface ID to link-local address */
272
      if (ipa_is_link_local(gw))
273
	_I0(gw) = 0xfe800000 | (i->index & 0x0000ffff);
274

  
275
      sockaddr_fill(&gate, af, gw, NULL, 0);
276
      msg.rtm.rtm_flags |= RTF_GATEWAY;
277
      msg.rtm.rtm_addrs |= RTA_GATEWAY;
293 278
      break;
279
    }
294 280

  
295 281
#ifdef RTF_REJECT
296
    case RTD_UNREACHABLE:
282
  case RTD_UNREACHABLE:
297 283
#endif
298 284
#ifdef RTF_BLACKHOLE
299
    case RTD_BLACKHOLE:
285
  case RTD_BLACKHOLE:
300 286
#endif
301
    default:
302
      bug("krt-sock: unknown flags, but not filtered");
287
  {
288
    /* Fallback for all other valid cases */
289
    if (!i->addr)
290
    {
291
      log(L_ERR "KRT: interface %s has no IP addess", i->name);
292
      return -1;
293
    }
294

  
295
#ifdef RTF_CLONING
296
    if (cmd == RTM_ADD && (i->flags & IF_MULTIACCESS) != IF_MULTIACCESS)	/* PTP */
297
      msg.rtm.rtm_flags |= RTF_CLONING;
298
#endif
299

  
300
    sockaddr_fill(&gate, ipa_is_ip4(i->addr->ip) ? AF_INET : AF_INET6, i->addr->ip, NULL, 0);
301
    msg.rtm.rtm_addrs |= RTA_GATEWAY;
302
  }
303

  
304
  default:
305
    bug("krt-sock: unknown flags, but not filtered");
303 306
  }
304 307

  
305 308
  msg.rtm.rtm_index = i->index;
......
497 500
    }
498 501

  
499 502
  a.dest = RTD_UNICAST;
500
  a.nh.next = NULL;
501 503
  if (flags & RTF_GATEWAY)
502 504
  {
503 505
    neighbor *ng;
......
520 522
	return;
521 523
      }
522 524
  }
523
  else
524
    a.nh.gw = IPA_NONE;
525 525

  
526 526
 done:
527 527
  e = rte_get_temp(&a);

Also available in: Unified diff