~brightbox/bird/debian-packaging

« back to all changes in this revision

Viewing changes to sysdep/bsd/krt-sock.c

  • Committer: Ondřej Surý
  • Date: 2013-11-25 14:59:24 UTC
  • Revision ID: git-v1:a3c058b8752bd98df2231ac88d94931fdb4e0c65
New upstream version 1.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
654
654
 
655
655
  if ((masklen = ipa_mklen(imask)) < 0)
656
656
  {
657
 
    log("Invalid masklen");
 
657
    log(L_ERR "KIF: Invalid masklen %I for %s", imask, iface->name);
658
658
    return;
659
659
  }
660
660
 
 
661
#ifdef IPV6
 
662
  /* Clean up embedded interface ID returned in link-local address */
 
663
 
 
664
  if (ipa_has_link_scope(iaddr))
 
665
    _I0(iaddr) = 0xfe800000;
 
666
 
 
667
  if (ipa_has_link_scope(ibrd))
 
668
    _I0(ibrd) = 0xfe800000;
 
669
#endif
 
670
 
 
671
 
661
672
  bzero(&ifa, sizeof(ifa));
662
 
 
663
673
  ifa.iface = iface;
664
 
 
665
 
  memcpy(&ifa.ip, &iaddr, sizeof(ip_addr));
 
674
  ifa.ip = iaddr;
666
675
  ifa.pxlen = masklen;
667
 
  memcpy(&ifa.brd, &ibrd, sizeof(ip_addr));
668
676
 
669
677
  scope = ipa_classify(ifa.ip);
670
678
  if (scope < 0)
674
682
  }
675
683
  ifa.scope = scope & IADDR_SCOPE_MASK;
676
684
 
677
 
#ifdef IPV6
678
 
  /* Clean up embedded interface ID returned in link-local address */
679
 
 
680
 
  if (ipa_has_link_scope(ifa.ip))
681
 
    _I0(ifa.ip) = 0xfe800000;
682
 
 
683
 
  if (ipa_has_link_scope(ifa.brd))
684
 
    _I0(ifa.brd) = 0xfe800000;
685
 
#endif
686
 
 
687
685
  if (masklen < BITS_PER_IP_ADDRESS)
688
686
  {
689
687
    ifa.prefix = ipa_and(ifa.ip, ipa_mkmask(masklen));
696
694
      ifa.opposite = ipa_opposite_m2(ifa.ip);
697
695
#endif
698
696
 
 
697
    if (iface->flags & IF_BROADCAST)
 
698
      ifa.brd = ibrd;
 
699
 
699
700
    if (!(iface->flags & IF_MULTIACCESS))
700
 
      ifa.opposite = ifa.brd;
 
701
      ifa.opposite = ibrd;
701
702
  }
702
 
  else if (!(iface->flags & IF_MULTIACCESS) && ipa_nonzero(ifa.brd))
 
703
  else if (!(iface->flags & IF_MULTIACCESS) && ipa_nonzero(ibrd))
703
704
  {
704
 
    ifa.prefix = ifa.opposite = ifa.brd;
 
705
    ifa.prefix = ifa.opposite = ibrd;
705
706
    ifa.flags |= IA_PEER;
706
707
  }
707
708
  else
1057
1058
  krt_buffer_release(&p->p);
1058
1059
}
1059
1060
 
 
1061
 
 
1062
struct ifa *
 
1063
kif_get_primary_ip(struct iface *i)
 
1064
{
 
1065
#ifndef IPV6
 
1066
  static int fd = -1;
 
1067
  
 
1068
  if (fd < 0)
 
1069
    fd = socket(AF_INET, SOCK_DGRAM, 0);
 
1070
 
 
1071
  struct ifreq ifr;
 
1072
  memset(&ifr, 0, sizeof(ifr));
 
1073
  strncpy(ifr.ifr_name, i->name, IFNAMSIZ);
 
1074
 
 
1075
  int rv = ioctl(fd, SIOCGIFADDR, (char *) &ifr);
 
1076
  if (rv < 0)
 
1077
    return NULL;
 
1078
 
 
1079
  ip_addr addr;
 
1080
  struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr;
 
1081
  memcpy(&addr, &sin->sin_addr.s_addr, sizeof(ip_addr));
 
1082
  ipa_ntoh(addr);
 
1083
 
 
1084
  struct ifa *a;
 
1085
  WALK_LIST(a, i->addrs)
 
1086
  {
 
1087
    if (ipa_equal(a->ip, addr))
 
1088
      return a;
 
1089
  }
 
1090
#endif
 
1091
 
 
1092
  return NULL;
 
1093
}