当前位置: 首页>>代码示例>>C++>>正文


C++ zlog_warn函数代码示例

本文整理汇总了C++中zlog_warn函数的典型用法代码示例。如果您正苦于以下问题:C++ zlog_warn函数的具体用法?C++ zlog_warn怎么用?C++ zlog_warn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了zlog_warn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ifam_read

/* Interface's address information get. */
int
ifam_read (struct ifa_msghdr *ifam)
{
  struct interface *ifp = NULL;
  union sockunion addr, mask, brd;
  char ifname[INTERFACE_NAMSIZ];
  short ifnlen = 0;
  char isalias = 0;
  int flags = 0;
  
  ifname[0] = ifname[INTERFACE_NAMSIZ - 1] = '\0';
  
  /* Allocate and read address information. */
  ifam_read_mesg (ifam, &addr, &mask, &brd, ifname, &ifnlen);
  
  if ((ifp = if_lookup_by_index(ifam->ifam_index)) == NULL)
    {
      zlog_warn ("%s: no interface for ifname %s, index %d", 
                 __func__, ifname, ifam->ifam_index);
      return -1;
    }
  
  if (ifnlen && strncmp (ifp->name, ifname, INTERFACE_NAMSIZ))
    isalias = 1;
  
  /* N.B. The info in ifa_msghdr does not tell us whether the RTA_BRD
     field contains a broadcast address or a peer address, so we are forced to
     rely upon the interface type. */
  if (if_is_pointopoint(ifp))
    SET_FLAG(flags, ZEBRA_IFA_PEER);

#if 0
  /* it might seem cute to grab the interface metric here, however
   * we're processing an address update message, and so some systems
   * (e.g. FBSD) dont bother to fill in ifam_metric. Disabled, but left
   * in deliberately, as comment.
   */
  ifp->metric = ifam->ifam_metric;
#endif

  /* Add connected address. */
  switch (sockunion_family (&addr))
    {
    case AF_INET:
      if (ifam->ifam_type == RTM_NEWADDR)
	connected_add_ipv4 (ifp, flags, &addr.sin.sin_addr, 
			    ip_masklen (mask.sin.sin_addr),
			    &brd.sin.sin_addr,
			    (isalias ? ifname : NULL));
      else
	connected_delete_ipv4 (ifp, flags, &addr.sin.sin_addr, 
			       ip_masklen (mask.sin.sin_addr),
			       &brd.sin.sin_addr);
      break;
#ifdef HAVE_IPV6
    case AF_INET6:
      /* Unset interface index from link-local address when IPv6 stack
	 is KAME. */
      if (IN6_IS_ADDR_LINKLOCAL (&addr.sin6.sin6_addr))
	SET_IN6_LINKLOCAL_IFINDEX (addr.sin6.sin6_addr, 0);

      if (ifam->ifam_type == RTM_NEWADDR)
	connected_add_ipv6 (ifp, flags, &addr.sin6.sin6_addr, 
			    ip6_masklen (mask.sin6.sin6_addr),
			    &brd.sin6.sin6_addr,
			    (isalias ? ifname : NULL));
      else
	connected_delete_ipv6 (ifp,
			       &addr.sin6.sin6_addr, 
			       ip6_masklen (mask.sin6.sin6_addr),
			       &brd.sin6.sin6_addr);
      break;
#endif /* HAVE_IPV6 */
    default:
      /* Unsupported family silently ignore... */
      break;
    }
  
  /* Check interface flag for implicit up of the interface. */
  if_refresh (ifp);

#ifdef SUNOS_5
  /* In addition to lacking IFANNOUNCE, on SUNOS IFF_UP is strange. 
   * See comments for SUNOS_5 in interface.c::if_flags_mangle.
   * 
   * Here we take care of case where the real IFF_UP was previously
   * unset (as kept in struct zebra_if.primary_state) and the mangled
   * IFF_UP (ie IFF_UP set || listcount(connected) has now transitioned
   * to unset due to the lost non-primary address having DELADDR'd.
   *
   * we must delete the interface, because in between here and next
   * event for this interface-name the administrator could unplumb
   * and replumb the interface.
   */
  if (!if_is_up (ifp))
    if_delete_update (ifp);
#endif /* SUNOS_5 */
  
  return 0;
//.........这里部分代码省略.........
开发者ID:ramarnat,项目名称:astaro-quagga,代码行数:101,代码来源:kernel_socket.c

示例2: open_dlpi_dev

static int open_dlpi_dev(struct isis_circuit *circuit)
{
	int fd = -1, unit, retval;
	char devpath[MAXPATHLEN];
	dl_info_ack_t *dia = (dl_info_ack_t *)dlpi_ctl;
	ssize_t acklen;

	/* Only broadcast-type are supported at the moment */
	if (circuit->circ_type != CIRCUIT_T_BROADCAST) {
		zlog_warn("%s: non-broadcast interface %s", __func__,
			  circuit->interface->name);
		return ISIS_WARNING;
	}

	/* Try the vanity node first, if permitted */
	if (getenv("DLPI_DEVONLY") == NULL) {
		(void)snprintf(devpath, sizeof(devpath), "/dev/net/%s",
			       circuit->interface->name);
		fd = dlpiopen(devpath, &acklen);
	}

	/* Now try as an ordinary Style 1 node */
	if (fd == -1) {
		(void)snprintf(devpath, sizeof(devpath), "/dev/%s",
			       circuit->interface->name);
		unit = -1;
		fd = dlpiopen(devpath, &acklen);
	}

	/* If that fails, try again as Style 2 */
	if (fd == -1) {
		char *cp;

		cp = devpath + strlen(devpath);
		while (--cp >= devpath && isdigit(*cp))
			;
		unit = strtol(cp, NULL, 0);
		*cp = '\0';
		fd = dlpiopen(devpath, &acklen);

		/* If that too fails, then the device really doesn't exist */
		if (fd == -1) {
			zlog_warn("%s: unknown interface %s", __func__,
				  circuit->interface->name);
			return ISIS_WARNING;
		}

		/* Double check the DLPI style */
		if (dia->dl_provider_style != DL_STYLE2) {
			zlog_warn(
				"open_dlpi_dev(): interface %s: %s is not style 2",
				circuit->interface->name, devpath);
			close(fd);
			return ISIS_WARNING;
		}

		/* If it succeeds, then we need to attach to the unit specified
		 */
		dlpiattach(fd, unit);

		/* Reget the information, as it may be different per node */
		if ((acklen = dlpiinfo(fd)) == -1) {
			close(fd);
			return ISIS_WARNING;
		}
	} else {
		/* Double check the DLPI style */
		if (dia->dl_provider_style != DL_STYLE1) {
			zlog_warn(
				"open_dlpi_dev(): interface %s: %s is not style 1",
				circuit->interface->name, devpath);
			close(fd);
			return ISIS_WARNING;
		}
	}

	/* Check that the interface we've got is the kind we expect */
	if ((dia->dl_sap_length != 2 && dia->dl_sap_length != -2)
	    || dia->dl_service_mode != DL_CLDLS
	    || dia->dl_addr_length != ETHERADDRL + 2
	    || dia->dl_brdcst_addr_length != ETHERADDRL) {
		zlog_warn("%s: unsupported interface type for %s", __func__,
			  circuit->interface->name);
		close(fd);
		return ISIS_WARNING;
	}
	switch (dia->dl_mac_type) {
	case DL_CSMACD:
	case DL_ETHER:
	case DL_100VG:
	case DL_100VGTPR:
	case DL_ETH_CSMA:
	case DL_100BT:
		break;
	default:
		zlog_warn("%s: unexpected mac type on %s: %lld", __func__,
			  circuit->interface->name,
			  (long long)dia->dl_mac_type);
		close(fd);
		return ISIS_WARNING;
//.........这里部分代码省略.........
开发者ID:Azure,项目名称:sonic-bcm-lkm,代码行数:101,代码来源:isis_dlpi.c

示例3: connected_add_ipv4

/* Add connected IPv4 route to the interface. */
void
connected_add_ipv4(struct interface *ifp, int flags, struct in_addr *addr,
		   u_char prefixlen, struct in_addr *broad, const char *label)
{
	struct prefix_ipv4 *p;
	struct connected *ifc;

	/* Make connected structure. */
	ifc = connected_new();
	ifc->ifp = ifp;
	ifc->flags = flags;
	/* If we get a notification from the kernel,
	 * we can safely assume the address is known to the kernel */
	SET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);

	/* Allocate new connected address. */
	p = prefix_ipv4_new();
	p->family = AF_INET;
	p->prefix = *addr;
	p->prefixlen = prefixlen;
	ifc->address = (struct prefix *)p;

	/* If there is broadcast or peer address. */
	if (broad) {
		p = prefix_ipv4_new();
		p->family = AF_INET;
		p->prefix = *broad;
		p->prefixlen = prefixlen;
		ifc->destination = (struct prefix *)p;

		/* validate the destination address */
		if (CONNECTED_PEER(ifc)) {
			if (IPV4_ADDR_SAME(addr, broad))
				zlog_warn
				    ("warning: interface %s has same local and peer "
				     "address %s, routing protocols may malfunction",
				     ifp->name, inet_ntoa(*addr));
		} else {
			if (broad->s_addr !=
			    ipv4_broadcast_addr(addr->s_addr, prefixlen)) {
				char buf[2][INET_ADDRSTRLEN];
				struct in_addr bcalc;
				bcalc.s_addr =
				    ipv4_broadcast_addr(addr->s_addr,
							prefixlen);
				zlog_warn
				    ("warning: interface %s broadcast addr %s/%d != "
				     "calculated %s, routing protocols may malfunction",
				     ifp->name, inet_ntop(AF_INET, broad,
							  buf[0],
							  sizeof(buf[0])),
				     prefixlen, inet_ntop(AF_INET, &bcalc,
							  buf[1],
							  sizeof(buf[1])));
			}
		}

	} else {
		if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_PEER)) {
			zlog_warn("warning: %s called for interface %s "
				  "with peer flag set, but no peer address supplied",
				  __func__, ifp->name);
			UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER);
		}

		/* no broadcast or destination address was supplied */
		if ((prefixlen == IPV4_MAX_PREFIXLEN) && if_is_pointopoint(ifp))
			zlog_warn
			    ("warning: PtP interface %s with addr %s/%d needs a "
			     "peer address", ifp->name, inet_ntoa(*addr),
			     prefixlen);
	}

	/* Label of this address. */
	if (label)
		ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label);

	/* For all that I know an IPv4 address is always ready when we receive
	 * the notification. So it should be safe to set the REAL flag here. */
	SET_FLAG(ifc->conf, ZEBRA_IFC_REAL);

	connected_update(ifp, ifc);
}
开发者ID:yubo,项目名称:quagga,代码行数:84,代码来源:connected.c

示例4: ifm_read


//.........这里部分代码省略.........
        {
          if (IS_ZEBRA_DEBUG_KERNEL)
            zlog_debug ("%s: ifp name %s doesnt match sdl name %s",
                        __func__, ifp->name, ifname);
          ifp = NULL;
        }
    }
  
  /* 
   * If we dont have an ifp, try looking up by name.  Particularly as some
   * systems (Solaris) have a 1:many mapping of ifindex:ifname - the ifname
   * is therefore our unique handle to that interface.
   *
   * Interfaces specified in the configuration file for which the ifindex
   * has not been determined will have ifindex == IFINDEX_INTERNAL, and such
   * interfaces are found by this search, and then their ifindex values can
   * be filled in.
   */
  if ( (ifp == NULL) && ifnlen)
    ifp = if_lookup_by_name (ifname);

  /*
   * If ifp still does not exist or has an invalid index (IFINDEX_INTERNAL),
   * create or fill in an interface.
   */
  if ((ifp == NULL) || (ifp->ifindex == IFINDEX_INTERNAL))
    {
      /*
       * To create or fill in an interface, a sockaddr_dl (via
       * RTA_IFP) is required.
       */
      if (!ifnlen)
	{
	  zlog_warn ("Interface index %d (new) missing ifname\n",
		     ifm->ifm_index);
	  return -1;
	}

#ifndef RTM_IFANNOUNCE
      /* Down->Down interface should be ignored here.
       * See further comment below.
       */
      if (!CHECK_FLAG (ifm->ifm_flags, IFF_UP))
        return 0;
#endif /* !RTM_IFANNOUNCE */
      
      if (ifp == NULL)
        {
	  /* Interface that zebra was not previously aware of, so create. */ 
	  ifp = if_create (ifname, ifnlen);
	  if (IS_ZEBRA_DEBUG_KERNEL)
	    zlog_debug ("%s: creating ifp for ifindex %d", 
	                __func__, ifm->ifm_index);
        }

      if (IS_ZEBRA_DEBUG_KERNEL)
        zlog_debug ("%s: updated/created ifp, ifname %s, ifindex %d",
                    __func__, ifp->name, ifp->ifindex);
      /* 
       * Fill in newly created interface structure, or larval
       * structure with ifindex IFINDEX_INTERNAL.
       */
      ifp->ifindex = ifm->ifm_index;
      
#ifdef HAVE_BSD_LINK_DETECT /* translate BSD kernel msg for link-state */
      bsd_linkdetect_translate(ifm);
开发者ID:ramarnat,项目名称:astaro-quagga,代码行数:67,代码来源:kernel_socket.c

示例5: smux_parse

/* Parse SMUX message. */
int
smux_parse (char *ptr, size_t len)
{
  /* This buffer we'll use for SOUT message. We could allocate it with
     malloc and save only static pointer/lenght, but IMHO static
     buffer is a faster solusion. */
  static u_char sout_save_buff[SMUXMAXPKTSIZE];
  static int sout_save_len = 0;

  int len_income = len; /* see note below: YYY */
  u_char type;
  u_char rollback;

  rollback = ptr[2]; /* important only for SMUX_SOUT */

process_rest: /* see note below: YYY */

  /* Parse SMUX message type and subsequent length. */
  ptr = asn_parse_header (ptr, &len, &type);

  if (debug_smux)
    zlog_debug ("SMUX message received type: %d rest len: %ld", type, len);

  switch (type)
    {
    case SMUX_OPEN:
      /* Open must be not send from SNMP agent. */
      zlog_warn ("SMUX_OPEN received: resetting connection.");
      return -1;
      break;
    case SMUX_RREQ:
      /* SMUX_RREQ message is invalid for us. */
      zlog_warn ("SMUX_RREQ received: resetting connection.");
      return -1;
      break;
    case SMUX_SOUT:
      /* SMUX_SOUT message is now valied for us. */
      if (debug_smux)
        zlog_debug ("SMUX_SOUT(%s)", rollback ? "rollback" : "commit");

      if (sout_save_len > 0)
        {
          smux_parse_set (sout_save_buff, sout_save_len, rollback ? FREE : COMMIT);
          sout_save_len = 0;
        }
      else
        zlog_warn ("SMUX_SOUT sout_save_len=%d - invalid", (int) sout_save_len);

      if (len_income > 3) 
        {
          /* YYY: this strange code has to solve the "slow peer"
             problem: When agent sends SMUX_SOUT message it doesn't
             wait any responce and may send some next message to
             subagent. Then the peer in 'smux_read()' will recieve
             from socket the 'concatenated' buffer, contaning both
             SMUX_SOUT message and the next one
             (SMUX_GET/SMUX_GETNEXT/SMUX_GET). So we should check: if
             the buffer is longer than 3 ( length of SMUX_SOUT ), we
             must process the rest of it.  This effect may be observed
             if 'debug_smux' is set to '1' */
          ptr++;
          len = len_income - 3;
          goto process_rest;
        }
      break;
    case SMUX_GETRSP:
      /* SMUX_GETRSP message is invalid for us. */
      zlog_warn ("SMUX_GETRSP received: resetting connection.");
      return -1;
      break;
    case SMUX_CLOSE:
      /* Close SMUX connection. */
      if (debug_smux)
	zlog_debug ("SMUX_CLOSE");
      smux_parse_close (ptr, len);
      return -1;
      break;
    case SMUX_RRSP:
      /* This is response for register message. */
      if (debug_smux)
	zlog_debug ("SMUX_RRSP");
      smux_parse_rrsp (ptr, len);
      break;
    case SMUX_GET:
      /* Exact request for object id. */
      if (debug_smux)
	zlog_debug ("SMUX_GET");
      smux_parse_get (ptr, len, 1);
      break;
    case SMUX_GETNEXT:
      /* Next request for object id. */
      if (debug_smux)
	zlog_debug ("SMUX_GETNEXT");
      smux_parse_get (ptr, len, 0);
      break;
    case SMUX_SET:
      /* SMUX_SET is supported with some limitations. */
      if (debug_smux)
	zlog_debug ("SMUX_SET");
//.........这里部分代码省略.........
开发者ID:Quagga,项目名称:people-jcollie,代码行数:101,代码来源:smux.c

示例6: sys_func_dl_prepare

static int sys_func_dl_prepare(int slot_id, uint64_t blk_start, uint64_t blk_num, uint32_t req_frag)
{
    int ret;
    sys_ctx_t* ctx = &sys_ctx;
    int repo_num = ctx->vault->repo_num;
    size_t cache_sz = SYS_CACHE_SIZE;
    int i, j;
    int interlace_sz = SYS_INTERLACE_SIZE;

    sys_cache_t* file_cache = ctx->file_cache;
    assert(file_cache);
    assert(file_cache->data);

    // get slot_sz
    ssize_t slot_sz;
    if (file_cache->slot_id == slot_id ) {
        slot_sz = file_cache->slot_sz;
    } else {
        slot_sz = dfv_vault_get_slotsize(ctx->vault, slot_id);
        if (slot_sz < 0) {
            zlog_error(sys_zc, "bad file size: slot_id=%d", slot_id);
            return(SPKERR_BADRES);
        }
    }

    // request region
    uint64_t req_start = blk_start * SYS_CACHE_SIZE;
    uint64_t req_end = (blk_num>0)?(req_start + blk_num * SYS_CACHE_SIZE):slot_sz;

    // frag region
    uint64_t frag_start = req_start + (uint64_t)req_frag * CMI_MAX_FRAGSIZE;
    uint64_t frag_end = frag_start + CMI_MAX_FRAGSIZE;

    // check if region is valid
    if (frag_start > slot_sz) {
        zlog_error(sys_zc, "illegal frag_start: slot_id=%d, slot_sz=%zu, "
                   "frag_start=%lu, req_frag=%u",
                   slot_id, slot_sz, frag_start, req_frag);
        return(SPKERR_PARAM);
    }

    if (frag_end > slot_sz) {
        zlog_warn(sys_zc, "truncate frag: slot_id=%d, slot_sz=%zu, "
                  "frag=%lu+%lu",
                  slot_id, slot_sz, frag_start, frag_end);
        frag_end = slot_sz;
    }

    // check cache hit
    int cache_hit = 0;
    do {
        if (file_cache->slot_id != slot_id) {
            // slot not match
            break;
        }
        if (frag_start < file_cache->offset ||
            frag_end > file_cache->offset + file_cache->len) {
            break;
        }
        cache_hit = 1;
    } while(0);

    if (cache_hit) {
        return(SPK_SUCCESS);
    }

    // do caching
    cache_sz = MIN(SYS_CACHE_SIZE, slot_sz - frag_start);
    size_t cache_sz_repo = cache_sz / repo_num;
    zlog_notice(sys_zc, "cache file: slot_id=%d, slot_sz=%zu, req_frag=%u, "
                "req=%lu+%lu, frag=%lu+%lu, cache_sz=%zu, blk=%lu+%lu",
                slot_id, slot_sz, req_frag,
                req_start, req_end-req_start,
                frag_start, frag_end-frag_start,
                cache_sz, blk_start, blk_num);

    struct dfv_file* file_ctx = NULL;
    void* file_buffer = memalign(SYS_INTERLACE_SIZE, cache_sz_repo);
    for (i=0; i<repo_num; i++) {
        struct dfv_repo * repo = ctx->vault->repo_tbl[i];
        assert(repo);

        file_ctx = dfv_file_open(repo, slot_id, SPK_DIR_READ, NULL, 12+4*i);
        if (!file_ctx) {
            ret = SPKERR_BADRES;
            goto out;
        }

        ret = dfv_file_seek(file_ctx, frag_start / repo_num);
        if (ret) {
            goto out;
        }

        ssize_t read_sz = dfv_file_read(file_ctx, file_buffer, cache_sz_repo);
        if (read_sz != cache_sz_repo) {
            ret = SPKERR_BADRES;
            goto out;
        }

        dfv_file_close(file_ctx);
//.........这里部分代码省略.........
开发者ID:Cai900205,项目名称:test,代码行数:101,代码来源:syslk_job.c

示例7: interface_list_ioctl

/* Interface looking up using infamous SIOCGIFCONF. */
static int
interface_list_ioctl (void)
{
  int ret;
  int sock;
#define IFNUM_BASE 32
  int ifnum;
  struct ifreq *ifreq;
  struct ifconf ifconf;
  struct interface *ifp;
  int n;
  int lastlen;

  /* Normally SIOCGIFCONF works with AF_INET socket. */
  sock = socket (AF_INET, SOCK_DGRAM, 0);
  if (sock < 0) 
    {
      zlog_warn ("Can't make AF_INET socket stream: %s", safe_strerror (errno));
      return -1;
    }

  /* Set initial ifreq count.  This will be double when SIOCGIFCONF
     fail.  Solaris has SIOCGIFNUM. */
#ifdef SIOCGIFNUM
  ret = ioctl (sock, SIOCGIFNUM, &ifnum);
  if (ret < 0)
    ifnum = IFNUM_BASE;
  else
    ifnum++;
#else
  ifnum = IFNUM_BASE;
#endif /* SIOCGIFNUM */

  ifconf.ifc_buf = NULL;

  lastlen = 0;
  /* Loop until SIOCGIFCONF success. */
  for (;;) 
    {
      ifconf.ifc_len = sizeof (struct ifreq) * ifnum;
      ifconf.ifc_buf = XREALLOC(MTYPE_TMP, ifconf.ifc_buf, ifconf.ifc_len);

      ret = ioctl(sock, SIOCGIFCONF, &ifconf);

      if (ret < 0) 
	{
	  zlog_warn ("SIOCGIFCONF: %s", safe_strerror(errno));
	  goto end;
	}
      /* Repeatedly get info til buffer fails to grow. */
      if (ifconf.ifc_len > lastlen)
	{
          lastlen = ifconf.ifc_len;
	  ifnum += 10;
	  continue;
	}
      /* Success. */
      break;
    }

  /* Allocate interface. */
  ifreq = ifconf.ifc_req;

#ifdef OPEN_BSD
  for (n = 0; n < ifconf.ifc_len; )
    {
      int size;

      ifreq = (struct ifreq *)((caddr_t) ifconf.ifc_req + n);
      ifp = if_get_by_name_len(ifreq->ifr_name,
			       strnlen(ifreq->ifr_name,
				       sizeof(ifreq->ifr_name)));
      if_add_update (ifp);
      size = ifreq->ifr_addr.sa_len;
      if (size < sizeof (ifreq->ifr_addr))
	size = sizeof (ifreq->ifr_addr);
      size += sizeof (ifreq->ifr_name);
      n += size;
    }
#else
  for (n = 0; n < ifconf.ifc_len; n += sizeof(struct ifreq))
    {
      ifp = if_get_by_name_len(ifreq->ifr_name,
			       strnlen(ifreq->ifr_name,
				       sizeof(ifreq->ifr_name)));
      if_add_update (ifp);
      ifreq++;
    }
#endif /* OPEN_BSD */

 end:
  close (sock);
  XFREE (MTYPE_TMP, ifconf.ifc_buf);

  return ret;
}
开发者ID:kkcloudy,项目名称:daemongroup,代码行数:97,代码来源:if_ioctl.c

示例8: netlink_link_change

static int
netlink_link_change (struct sockaddr_nl *snl, struct nlmsghdr *h)
{
  int len;
  struct ifinfomsg *ifi;
  struct rtattr *tb[IFLA_MAX + 1];
  struct interface *ifp;
  char *name;

  ifi = NLMSG_DATA (h);

  if (!(h->nlmsg_type == RTM_NEWLINK || h->nlmsg_type == RTM_DELLINK))
    {
      /* If this is not link add/delete message so print warning. */
      zlog_warn ("netlink_link_change: wrong kernel message %d\n",
                 h->nlmsg_type);
      return 0;
    }

  len = h->nlmsg_len - NLMSG_LENGTH (sizeof (struct ifinfomsg));
  if (len < 0)
    return -1;

  /* Looking up interface name. */
  memset (tb, 0, sizeof tb);
  netlink_parse_rtattr (tb, IFLA_MAX, IFLA_RTA (ifi), len);

#ifdef IFLA_WIRELESS
  /* check for wireless messages to ignore */
  if ((tb[IFLA_WIRELESS] != NULL) && (ifi->ifi_change == 0))
    {
      if (IS_DEBUG_HA(kroute, KROUTE))
        zlog_debug ("%s: ignoring IFLA_WIRELESS message", __func__);
      return 0;
    }
#endif /* IFLA_WIRELESS */
  
  if (tb[IFLA_IFNAME] == NULL)
    return -1;
  name = (char *) RTA_DATA (tb[IFLA_IFNAME]);

  /* Add interface. */
  if (h->nlmsg_type == RTM_NEWLINK)
    {
      ifp = if_lookup_by_name (name);

      if (ifp == NULL || !CHECK_FLAG (ifp->status, KROUTE_INTERFACE_ACTIVE))
        {
          if (ifp == NULL)
            ifp = if_get_by_name (name);

          set_ifindex(ifp, ifi->ifi_index);
          ifp->flags = ifi->ifi_flags & 0x0000fffff;
          ifp->mtu6 = ifp->mtu = *(int *) RTA_DATA (tb[IFLA_MTU]);
          ifp->metric = 1;

          netlink_interface_update_hw_addr (tb, ifp);

          /* If new link is added. */
          if_add_update (ifp);
        }
      else
        {
          /* Interface status change. */
          set_ifindex(ifp, ifi->ifi_index);
          ifp->mtu6 = ifp->mtu = *(int *) RTA_DATA (tb[IFLA_MTU]);
          ifp->metric = 1;

          netlink_interface_update_hw_addr (tb, ifp);

          if (if_is_operative (ifp))
            {
              ifp->flags = ifi->ifi_flags & 0x0000fffff;
              if (!if_is_operative (ifp))
                if_down (ifp);
	      else
		/* Must notify client daemons of new interface status. */
	        kroute_interface_up_update (ifp);
            }
          else
            {
              ifp->flags = ifi->ifi_flags & 0x0000fffff;
              if (if_is_operative (ifp))
                if_up (ifp);
            }
        }
    }
  else
    {
      /* RTM_DELLINK. */
      ifp = if_lookup_by_name (name);

      if (ifp == NULL)
        {
          zlog (NULL, LOG_WARNING, "interface %s is deleted but can't find",
                name);
          return 0;
        }

      if_delete_update (ifp);
//.........这里部分代码省略.........
开发者ID:rgmabs19357,项目名称:HA,代码行数:101,代码来源:rt_netlink.c

示例9: pim_if_addr_add

void pim_if_addr_add(struct connected *ifc)
{
  struct pim_interface *pim_ifp;
  struct interface *ifp;
  struct in_addr ifaddr;

  zassert(ifc);

  ifp = ifc->ifp;
  zassert(ifp);
  pim_ifp = ifp->info;
  if (!pim_ifp)
    return;

  if (!if_is_operative(ifp))
    return;

  /* if (PIM_DEBUG_ZEBRA) */ {
    char buf[BUFSIZ];
    prefix2str(ifc->address, buf, BUFSIZ);
    zlog_debug("%s: %s ifindex=%d connected IP address %s %s",
	       __PRETTY_FUNCTION__,
	       ifp->name, ifp->ifindex, buf,
	       CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY) ?
	       "secondary" : "primary");
  }

  ifaddr = ifc->address->u.prefix4;

  detect_address_change(ifp, 0, __PRETTY_FUNCTION__);

  if (PIM_IF_TEST_IGMP(pim_ifp->options)) {
    struct igmp_sock *igmp;

    /* lookup IGMP socket */
    igmp = pim_igmp_sock_lookup_ifaddr(pim_ifp->igmp_socket_list,
				       ifaddr);
    if (!igmp) {
      /* if addr new, add IGMP socket */
      pim_igmp_sock_add(pim_ifp->igmp_socket_list, ifaddr, ifp);
    }
  } /* igmp */

  if (PIM_IF_TEST_PIM(pim_ifp->options)) {

    /* Interface has a valid primary address ? */
    if (PIM_INADDR_ISNOT_ANY(pim_ifp->primary_address)) {

      /* Interface has a valid socket ? */
      if (pim_ifp->pim_sock_fd < 0) {
	if (pim_sock_add(ifp)) {
	  zlog_warn("Failure creating PIM socket for interface %s",
		    ifp->name);
	}
      }

    }
  } /* pim */

  if (PIM_MROUTE_IS_ENABLED) {
    /*
      PIM or IGMP is enabled on interface, and there is at least one
      address assigned, then try to create a vif_index.
    */
    if (pim_ifp->mroute_vif_index < 0) {
      pim_if_add_vif(ifp);
    }
  }
}
开发者ID:FujitsuNetworkCommunications,项目名称:Quagga-Graceful-Restart,代码行数:69,代码来源:pim_iface.c

示例10: if_get_addr

/* Interface address lookup by ioctl.  This function only looks up
   IPv4 address. */
int
if_get_addr (struct interface *ifp)
{
  int ret;
  struct ifreq ifreq;
  struct sockaddr_in addr;
  struct sockaddr_in mask;
  struct sockaddr_in dest;
  struct in_addr *dest_pnt;
  u_char prefixlen;

  /* Interface's name and address family. */
  strncpy (ifreq.ifr_name, ifp->name, IFNAMSIZ);
  ifreq.ifr_addr.sa_family = AF_INET;

  /* Interface's address. */
  ret = if_ioctl (SIOCGIFADDR, (caddr_t) &ifreq);
  if (ret < 0) 
    {
      if (errno != EADDRNOTAVAIL)
	{
	  zlog_warn ("SIOCGIFADDR fail: %s", safe_strerror (errno));
	  return ret;
	}
      return 0;
    }
  memcpy (&addr, &ifreq.ifr_addr, sizeof (struct sockaddr_in));

  /* Interface's network mask. */
  ret = if_ioctl (SIOCGIFNETMASK, (caddr_t) &ifreq);
  if (ret < 0) 
    {
      if (errno != EADDRNOTAVAIL) 
	{
	  zlog_warn ("SIOCGIFNETMASK fail: %s", safe_strerror (errno));
	  return ret;
	}
      return 0;
    }
#ifdef ifr_netmask
  memcpy (&mask, &ifreq.ifr_netmask, sizeof (struct sockaddr_in));
#else
  memcpy (&mask, &ifreq.ifr_addr, sizeof (struct sockaddr_in));
#endif /* ifr_netmask */
  prefixlen = ip_masklen (mask.sin_addr);

  /* Point to point or borad cast address pointer init. */
  dest_pnt = NULL;

  if (ifp->flags & IFF_POINTOPOINT) 
    {
      ret = if_ioctl (SIOCGIFDSTADDR, (caddr_t) &ifreq);
      if (ret < 0) 
	{
	  if (errno != EADDRNOTAVAIL) 
	    {
	      zlog_warn ("SIOCGIFDSTADDR fail: %s", safe_strerror (errno));
	      return ret;
	    }
	  return 0;
	}
      memcpy (&dest, &ifreq.ifr_dstaddr, sizeof (struct sockaddr_in));
      dest_pnt = &dest.sin_addr;
    }
  if (ifp->flags & IFF_BROADCAST)
    {
      ret = if_ioctl (SIOCGIFBRDADDR, (caddr_t) &ifreq);
      if (ret < 0) 
	{
	  if (errno != EADDRNOTAVAIL) 
	    {
	      zlog_warn ("SIOCGIFBRDADDR fail: %s", safe_strerror (errno));
	      return ret;
	    }
	  return 0;
	}
      memcpy (&dest, &ifreq.ifr_broadaddr, sizeof (struct sockaddr_in));
      dest_pnt = &dest.sin_addr;
    }


  /* Set address to the interface. */
  connected_add_ipv4 (ifp, 0, &addr.sin_addr, prefixlen, dest_pnt, NULL);

  return 0;
}
开发者ID:kkcloudy,项目名称:daemongroup,代码行数:88,代码来源:if_ioctl.c

示例11: pim_if_igmp_join_add

int pim_if_igmp_join_add(struct interface *ifp,
			 struct in_addr group_addr,
			 struct in_addr source_addr)
{
  struct pim_interface *pim_ifp;
  struct igmp_join *ij;

  pim_ifp = ifp->info;
  if (!pim_ifp) {
    zlog_warn("%s: multicast not enabled on interface %s",
	      __PRETTY_FUNCTION__, 
	      ifp->name);
    return -1;
  }

  if (!pim_ifp->igmp_join_list) {
    pim_ifp->igmp_join_list = list_new();
    if (!pim_ifp->igmp_join_list) {
      zlog_err("%s %s: failure: igmp_join_list=list_new()",
	       __FILE__, __PRETTY_FUNCTION__);
      return -2;
    }
    pim_ifp->igmp_join_list->del = (void (*)(void *)) igmp_join_free;
  }

  ij = igmp_join_find(pim_ifp->igmp_join_list, group_addr, source_addr);
  if (ij) {
    char group_str[100];
    char source_str[100];
    pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
    pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
    zlog_warn("%s: can't re-join existing IGMP group %s source %s on interface %s",
	      __PRETTY_FUNCTION__,
	      group_str, source_str, ifp->name);
    return -3;
  }

  ij = igmp_join_new(ifp, group_addr, source_addr);
  if (!ij) {
    char group_str[100];
    char source_str[100];
    pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
    pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
    zlog_warn("%s: igmp_join_new() failure for IGMP group %s source %s on interface %s",
	      __PRETTY_FUNCTION__,
	      group_str, source_str, ifp->name);
    return -4;
  }

  {
    char group_str[100];
    char source_str[100];
    pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
    pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
    zlog_debug("%s: issued static igmp join for channel (S,G)=(%s,%s) on interface %s",
	       __PRETTY_FUNCTION__,
	       source_str, group_str, ifp->name);
  }

  return 0;
}
开发者ID:FujitsuNetworkCommunications,项目名称:Quagga-Graceful-Restart,代码行数:61,代码来源:pim_iface.c

示例12: open_bpf_dev

static int
open_bpf_dev (struct isis_circuit *circuit)
{
    int i = 0, fd;
    char bpfdev[128];
    struct ifreq ifr;
    u_int16_t blen;
    int true = 1, false = 0;
    struct timeval timeout;
    struct bpf_program bpf_prog;

    do
    {
        (void) snprintf (bpfdev, sizeof (bpfdev), "/dev/bpf%d", i++);
        fd = open (bpfdev, O_RDWR);
    }
    while (fd < 0 && errno == EBUSY);

    if (fd < 0)
    {
        zlog_warn ("open_bpf_dev(): failed to create bpf socket: %s",
                   safe_strerror (errno));
        return ISIS_WARNING;
    }

    zlog_debug ("Opened BPF device %s", bpfdev);

    memcpy (ifr.ifr_name, circuit->interface->name, sizeof (ifr.ifr_name));
    if (ioctl (fd, BIOCSETIF, (caddr_t) & ifr) < 0)
    {
        zlog_warn ("open_bpf_dev(): failed to bind to interface: %s",
                   safe_strerror (errno));
        return ISIS_WARNING;
    }

    if (ioctl (fd, BIOCGBLEN, (caddr_t) & blen) < 0)
    {
        zlog_warn ("failed to get BPF buffer len");
        blen = circuit->interface->mtu;
    }

    readblen = blen;

    if (readbuff == NULL)
        readbuff = malloc (blen);

    zlog_debug ("BPF buffer len = %u", blen);

    /*  BPF(4): reads return immediately upon packet reception.
     *  Otherwise, a read will block until either the kernel
     *  buffer becomes full or a timeout occurs.
     */
    if (ioctl (fd, BIOCIMMEDIATE, (caddr_t) & true) < 0)
    {
        zlog_warn ("failed to set BPF dev to immediate mode");
    }

#ifdef BIOCSSEESENT
    /*
     * We want to see only incoming packets
     */
    if (ioctl (fd, BIOCSSEESENT, (caddr_t) & false) < 0)
    {
        zlog_warn ("failed to set BPF dev to incoming only mode");
    }
#endif

    /*
     * ...but all of them
     */
    if (ioctl (fd, BIOCPROMISC, (caddr_t) & true) < 0)
    {
        zlog_warn ("failed to set BPF dev to promiscuous mode");
    }

    /*
     * If the buffer length is smaller than our mtu, lets try to increase it
     */
    if (blen < circuit->interface->mtu)
    {
        if (ioctl (fd, BIOCSBLEN, &circuit->interface->mtu) < 0)
        {
            zlog_warn ("failed to set BPF buffer len (%u to %u)", blen,
                       circuit->interface->mtu);
        }
    }

    /*
     * Set a timeout parameter - hope this helps select()
     */
    timeout.tv_sec = 600;
    timeout.tv_usec = 0;
    if (ioctl (fd, BIOCSRTIMEOUT, (caddr_t) & timeout) < 0)
    {
        zlog_warn ("failed to set BPF device timeout");
    }

    /*
     * And set the filter
     */
//.........这里部分代码省略.........
开发者ID:kkcloudy,项目名称:daemongroup,代码行数:101,代码来源:isis_network.c

示例13: open_packet_socket

static int
open_packet_socket (struct isis_circuit *circuit)
{
    struct sockaddr_ll s_addr;
    int fd, retval = ISIS_OK;

    fd = socket (PF_PACKET, SOCK_DGRAM, htons (ETH_P_ALL));
    if (fd < 0)
    {
        zlog_warn ("open_packet_socket(): socket() failed %s",
                   safe_strerror (errno));
        return ISIS_WARNING;
    }

    /*
     * Bind to the physical interface
     */
    memset (&s_addr, 0, sizeof (struct sockaddr_ll));
    s_addr.sll_family = AF_PACKET;
    s_addr.sll_protocol = htons (ETH_P_ALL);
    s_addr.sll_ifindex = circuit->interface->ifindex;

    if (bind (fd, (struct sockaddr *) (&s_addr),
              sizeof (struct sockaddr_ll)) < 0)
    {
        zlog_warn ("open_packet_socket(): bind() failed: %s", safe_strerror (errno));
        return ISIS_WARNING;
    }

    circuit->fd = fd;

    if (circuit->circ_type == CIRCUIT_T_BROADCAST)
    {
        /*
         * Join to multicast groups
         * according to
         * 8.4.2 - Broadcast subnetwork IIH PDUs
         * FIXME: is there a case only one will fail??
         */
        if (circuit->circuit_is_type & IS_LEVEL_1)
        {
            /* joining ALL_L1_ISS */
            retval = isis_multicast_join (circuit->fd, 1,
                                          circuit->interface->ifindex);
            /* joining ALL_ISS */
            retval = isis_multicast_join (circuit->fd, 3,
                                          circuit->interface->ifindex);
        }
        if (circuit->circuit_is_type & IS_LEVEL_2)
            /* joining ALL_L2_ISS */
            retval = isis_multicast_join (circuit->fd, 2,
                                          circuit->interface->ifindex);
    }
    else
    {
        retval =
            isis_multicast_join (circuit->fd, 0, circuit->interface->ifindex);
    }

    return retval;
}
开发者ID:kkcloudy,项目名称:daemongroup,代码行数:61,代码来源:isis_network.c

示例14: buffer_flush_available

/* This function (unlike other buffer_flush* functions above) is designed
to work with non-blocking sockets.  It does not attempt to write out
all of the queued data, just a "big" chunk.  It returns 0 if it was
able to empty out the buffers completely, 1 if more flushing is
required later, or -1 on a fatal write error. */
buffer_status_t
buffer_flush_available(struct buffer *b, int fd)
{

/* These are just reasonable values to make sure a significant amount of
data is written.  There's no need to go crazy and try to write it all
in one shot. */
#ifdef IOV_MAX
#define MAX_CHUNKS ((IOV_MAX >= 16) ? 16 : IOV_MAX)
#else
#define MAX_CHUNKS 16
#endif
#define MAX_FLUSH 131072

  struct buffer_data *d;
  size_t written;
  struct iovec iov[MAX_CHUNKS];
  size_t iovcnt = 0;
  size_t nbyte = 0;

  for (d = b->head; d && (iovcnt < MAX_CHUNKS) && (nbyte < MAX_FLUSH);
       d = d->next, iovcnt++)
    {
      iov[iovcnt].iov_base = d->data+d->sp;
      nbyte += (iov[iovcnt].iov_len = d->cp-d->sp);
    }

  if (!nbyte)
    /* No data to flush: should we issue a warning message? */
    return BUFFER_EMPTY;

  /* only place where written should be sign compared */
  if ((ssize_t)(written = writev(fd,iov,iovcnt)) < 0)
    {
      if (ERRNO_IO_RETRY(errno))
	/* Calling code should try again later. */
        return BUFFER_PENDING;
      zlog_warn("%s: write error on fd %d: %s",
		__func__, fd, safe_strerror(errno));
      return BUFFER_ERROR;
    }

  /* Free printed buffer data. */
  while (written > 0)
    {
      struct buffer_data *d;
      if (!(d = b->head))
        {
          zlog_err("%s: corruption detected: buffer queue empty, "
		   "but written is %lu", __func__, (u_long)written);
	  break;
        }
      if (written < d->cp-d->sp)
        {
	  d->sp += written;
	  return BUFFER_PENDING;
	}

      written -= (d->cp-d->sp);
      if (!(b->head = d->next))
        b->tail = NULL;
      BUFFER_DATA_FREE(d);
    }

  return b->head ? BUFFER_PENDING : BUFFER_EMPTY;

#undef MAX_CHUNKS
#undef MAX_FLUSH
}
开发者ID:rgmabs19357,项目名称:HA,代码行数:74,代码来源:buffer.c

示例15: netlink_talk_filter

static int
netlink_talk_filter (struct sockaddr_nl *snl, struct nlmsghdr *h)
{
  zlog_warn ("netlink_talk: ignoring message type 0x%04x", h->nlmsg_type);
  return 0;
}
开发者ID:rgmabs19357,项目名称:HA,代码行数:6,代码来源:rt_netlink.c


注:本文中的zlog_warn函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。