Ejemplo n.º 1
0
static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info,
				     const u16 *s, u32 attr, u32 cnt,
				     u32 d_pitch, u32 s_pitch, u32 cellsize,
				     struct fb_image *image, u8 *buf, u8 *dst)
{
	u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
	u32 idx = vc->vc_font.width >> 3;
	u8 *src;

	while (cnt--) {
		src = vc->vc_font.data + (scr_readw(s++)&
					  charmask)*cellsize;

		if (attr) {
			update_attr(buf, src, attr, vc);
			src = buf;
		}

		if (likely(idx == 1))
			__fb_pad_aligned_buffer(dst, d_pitch, src, idx,
						image->height);
		else
			fb_pad_aligned_buffer(dst, d_pitch, src, idx,
					      image->height);

		dst += s_pitch;
	}

	info->fbops->fb_imageblit(info, image);
}
Ejemplo n.º 2
0
static inline void bit_putcs_unaligned(struct vc_data *vc,
				       struct fb_info *info, const u16 *s,
				       u32 attr, u32 cnt, u32 d_pitch,
				       u32 s_pitch, u32 cellsize,
				       struct fb_image *image, u8 *buf,
				       u8 *dst)
{
	u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
	u32 shift_low = 0, mod = vc->vc_font.width % 8;
	u32 shift_high = 8;
	u32 idx = vc->vc_font.width >> 3;
	u8 *src;

	while (cnt--) {
		src = vc->vc_font.data + (scr_readw(s++)&
					  charmask)*cellsize;

		if (attr) {
			update_attr(buf, src, attr, vc);
			src = buf;
		}

		fb_pad_unaligned_buffer(dst, d_pitch, src, idx,
					image->height, shift_high,
					shift_low, mod);
		shift_low += mod;
		dst += (shift_low >= 8) ? s_pitch : s_pitch - 1;
		shift_low &= 7;
		shift_high = 8 - shift_low;
	}

	info->fbops->fb_imageblit(info, image);

}
Ejemplo n.º 3
0
static void
proc_read(void)
{
    FILE *  fd;
    char    buf[512], *p, *s;
    int     w;
	intf_t *i;

    if (!(fd = fopen(c_path, "r")))
        quit("Unable to open file %s: %s\n", c_path, strerror(errno));

    fgets(buf, sizeof(buf), fd);
    fgets(buf, sizeof(buf), fd);

    for (; fgets(buf, sizeof(buf), fd);) {
		b_cnt_t rx_errors, rx_drop, rx_fifo, rx_frame, rx_compressed;
		b_cnt_t rx_multicast, tx_errors, tx_drop, tx_fifo, tx_frame;
		b_cnt_t tx_compressed, tx_multicast;

        if (buf[0] == '\r' || buf[0] == '\n')
            continue;

        if (!(p = strchr(buf, ':')))
            continue;

        *p = '\0';
        s = (p + 1);

        for (p = &buf[0]; *p == ' '; p++);

		/*
		 * XXX: get_show_only_running
		 */

        if ((i = lookup_intf(get_local_node(), p, 0, 0)) == NULL)
            continue;

        w = sscanf(s, "%llu %llu %llu %llu %llu %llu %llu %llu %llu %llu "
                "%llu %llu %llu %llu %llu %llu\n",
            &i->i_rx_bytes.r_total,
            &i->i_rx_packets.r_total,
            &rx_errors,
            &rx_drop,
            &rx_fifo,
            &rx_frame,
            &rx_compressed,
            &rx_multicast,
            &i->i_tx_bytes.r_total,
            &i->i_tx_packets.r_total,
            &tx_errors,
            &tx_drop,
            &tx_fifo,
            &tx_frame,
            &tx_compressed,
            &tx_multicast);

        if (w != 16)
            continue;

		update_attr(i, ERRORS, rx_errors, tx_errors, RX_PROVIDED|TX_PROVIDED);
		update_attr(i, DROP, rx_drop, tx_drop, RX_PROVIDED|TX_PROVIDED);
		update_attr(i, FIFO, rx_fifo, tx_fifo, RX_PROVIDED|TX_PROVIDED);
		update_attr(i, FRAME, rx_frame, tx_frame, RX_PROVIDED|TX_PROVIDED);
		update_attr(i, COMPRESSED, rx_compressed, tx_compressed, RX_PROVIDED|TX_PROVIDED);
		update_attr(i, MULTICAST, rx_multicast, tx_multicast, RX_PROVIDED|TX_PROVIDED);

		notify_update(i);
		increase_lifetime(i, 1);
    }

    fclose(fd);
}
Ejemplo n.º 4
0
int
main(int argc, char **argv)
{
	cib_t *	the_cib = NULL;
	enum cib_errors rc = cib_ok;
	
	int cib_opts = cib_sync_call;
	int argerr = 0;
	int flag;

	int option_index = 0;

	crm_system_name = basename(argv[0]);
	crm_set_options("V?$GDQqN:U:u:s:n:v:l:t:i:!r:d:", "command -n attribute [options]", long_options,
			"Manage node's attributes and cluster options."
			"\n\nAllows node attributes and cluster options to be queried, modified and deleted.\n");

	if(argc < 2) {
		crm_help('?', LSB_EXIT_EINVAL);
	}
	
	while (1) {
		flag = crm_get_option(argc, argv, &option_index);
		if (flag == -1)
			break;

		switch(flag) {
			case 'V':
				cl_log_enable_stderr(TRUE);
				alter_debug(DEBUG_INC);
				break;
			case '$':
			case '?':
			    crm_help(flag, LSB_EXIT_OK);
			    break;
			case 'D':
			case 'G':
			case 'v':
				command = flag;
				attr_value = optarg;
				break;
			case 'q':
			case 'Q':
				BE_QUIET = TRUE;
				break;
			case 'U':
			case 'N':
				dest_uname = crm_strdup(optarg);
				break;
			case 'u':
				dest_node = crm_strdup(optarg);
				break;
			case 's':
				set_name = crm_strdup(optarg);
				break;
			case 'l':
			case 't':
				type = optarg;
				break;
			case 'n':
				attr_name = crm_strdup(optarg);
				break;
			case 'i':
				attr_id = crm_strdup(optarg);
				break;
			case 'r':
				rsc_id = optarg;
				break;
			case 'd':
				attr_default = optarg;
				break;
			case '!':
				crm_warn("Inhibiting notifications for this update");
				cib_opts |= cib_inhibit_notify;
				break;
			default:
				printf("Argument code 0%o (%c) is not (?yet?) supported\n", flag, flag);
				++argerr;
				break;
		}
	}

	if(BE_QUIET == FALSE) {
	    crm_log_init(basename(argv[0]), LOG_ERR, FALSE, FALSE, argc, argv);
	} else {
	    crm_log_init(basename(argv[0]), LOG_ERR, FALSE, FALSE, 0, NULL);
	}
	
	if (optind < argc) {
		printf("non-option ARGV-elements: ");
		while (optind < argc)
			printf("%s ", argv[optind++]);
		printf("\n");
	}

	if (optind > argc) {
		++argerr;
	}

	if (argerr) {
		crm_help('?', LSB_EXIT_GENERIC);
	}

	the_cib = cib_new();
	rc = the_cib->cmds->signon(the_cib, crm_system_name, cib_command);

	if(rc != cib_ok) {
	    fprintf(stderr, "Error signing on to the CIB service: %s\n", cib_error2string(rc));
	    return rc;
	}	

	if(safe_str_eq(type, "reboot")) {
	    type = XML_CIB_TAG_STATUS;

	} else if(safe_str_eq(type, "forever")) {
	    type = XML_CIB_TAG_NODES;
	}

	if(type == NULL && dest_uname == NULL) {
	    /* we're updating cluster options - dont populate dest_node */
	    type = XML_CIB_TAG_CRMCONFIG;
	    
	} else {
	    determine_host(the_cib, &dest_uname, &dest_node);
	}
	
	if(rc != cib_ok) {
	    crm_info("Error during setup of %s=%s update", attr_name, command=='D'?"<none>":attr_value);
	    
	} else if( (command=='v' || command=='D')
		   && safe_str_eq(type, XML_CIB_TAG_STATUS)
		   && attrd_lazy_update(command, dest_uname, attr_name, attr_value, type, set_name, NULL)) {
	    crm_info("Update %s=%s sent via attrd", attr_name, command=='D'?"<none>":attr_value);
	    
	} else if(command=='D') {
		rc = delete_attr(the_cib, cib_opts, type, dest_node, set_name,
				 attr_id, attr_name, attr_value, TRUE);

		if(rc == cib_NOTEXISTS) {
		    /* Nothing to delete...
		     * which means its not there...
		     * which is what the admin wanted
		     */
		    rc = cib_ok;
		} else if(rc != cib_missing_data
			  && safe_str_eq(crm_system_name, "crm_failcount")) {
			char *now_s = NULL;
			time_t now = time(NULL);
			now_s = crm_itoa(now);
			update_attr(the_cib, cib_sync_call,
				    XML_CIB_TAG_CRMCONFIG, NULL, NULL, NULL,
				    "last-lrm-refresh", now_s, TRUE);
			crm_free(now_s);
		}
			
	} else if(command=='v') {
		CRM_DEV_ASSERT(type != NULL);
		CRM_DEV_ASSERT(attr_name != NULL);
		CRM_DEV_ASSERT(attr_value != NULL);

		rc = update_attr(the_cib, cib_opts, type, dest_node, set_name,
				 attr_id, attr_name, attr_value, TRUE);

	} else /* query */ {
		char *read_value = NULL;
		rc = read_attr(the_cib, type, dest_node, set_name,
			       attr_id, attr_name, &read_value, TRUE);

		if(rc == cib_NOTEXISTS && attr_default) {
			read_value = crm_strdup(attr_default);
			rc = cib_ok;
		}
		
		crm_info("Read %s=%s %s%s",
			 attr_name, crm_str(read_value),
			 set_name?"in ":"", set_name?set_name:"");

		if(rc == cib_missing_data) {
		    rc = cib_ok;
		    
		} else if(BE_QUIET == FALSE) {
			fprintf(stdout, "%s%s %s%s %s%s value=%s\n",
				type?"scope=":"", type?type:"",
				attr_id?"id=":"", attr_id?attr_id:"",
				attr_name?"name=":"", attr_name?attr_name:"",
				read_value?read_value:"(null)");

		} else if(read_value != NULL) {
			fprintf(stdout, "%s\n", read_value);
		}
	}

	the_cib->cmds->signoff(the_cib);
	if(rc == cib_missing_data) {
		    printf("Please choose from one of the matches above and suppy the 'id' with --attr-id\n");
	} else if(rc != cib_ok) {
		fprintf(stderr, "Error performing operation: %s\n",
			cib_error2string(rc));
	}
	return rc;
}
Ejemplo n.º 5
0
static void bit_cursor(struct vc_data *vc, struct fb_info *info, int mode,
		       int softback_lines, int fg, int bg)
{
	struct fb_cursor cursor;
	struct fbcon_ops *ops = info->fbcon_par;
	unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
	int w = DIV_ROUND_UP(vc->vc_font.width, 8), c;
	int y = real_y(ops->p, vc->vc_y);
	int attribute, use_sw = (vc->vc_cursor_type & 0x10);
	int err = 1;
	char *src;

	cursor.set = 0;

	if (softback_lines) {
		if (y + softback_lines >= vc->vc_rows) {
			mode = CM_ERASE;
			ops->cursor_flash = 0;
			return;
		} else
			y += softback_lines;
	}

 	c = scr_readw((u16 *) vc->vc_pos);
	attribute = get_attribute(info, c);
	src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height));

	if (ops->cursor_state.image.data != src ||
	    ops->cursor_reset) {
	    ops->cursor_state.image.data = src;
	    cursor.set |= FB_CUR_SETIMAGE;
	}

	if (attribute) {
		u8 *dst;

		dst = kmalloc(w * vc->vc_font.height, GFP_ATOMIC);
		if (!dst)
			return;
		kfree(ops->cursor_data);
		ops->cursor_data = dst;
		update_attr(dst, src, attribute, vc);
		src = dst;
	}

	if (ops->cursor_state.image.fg_color != fg ||
	    ops->cursor_state.image.bg_color != bg ||
	    ops->cursor_reset) {
		ops->cursor_state.image.fg_color = fg;
		ops->cursor_state.image.bg_color = bg;
		cursor.set |= FB_CUR_SETCMAP;
	}

	if ((ops->cursor_state.image.dx != (vc->vc_font.width * vc->vc_x)) ||
	    (ops->cursor_state.image.dy != (vc->vc_font.height * y)) ||
	    ops->cursor_reset) {
		ops->cursor_state.image.dx = vc->vc_font.width * vc->vc_x;
		ops->cursor_state.image.dy = vc->vc_font.height * y;
		cursor.set |= FB_CUR_SETPOS;
	}

	if (ops->cursor_state.image.height != vc->vc_font.height ||
	    ops->cursor_state.image.width != vc->vc_font.width ||
	    ops->cursor_reset) {
		ops->cursor_state.image.height = vc->vc_font.height;
		ops->cursor_state.image.width = vc->vc_font.width;
		cursor.set |= FB_CUR_SETSIZE;
	}

	if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
	    ops->cursor_reset) {
		ops->cursor_state.hot.x = cursor.hot.y = 0;
		cursor.set |= FB_CUR_SETHOT;
	}

	if (cursor.set & FB_CUR_SETSIZE ||
	    vc->vc_cursor_type != ops->p->cursor_shape ||
	    ops->cursor_state.mask == NULL ||
	    ops->cursor_reset) {
		char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC);
		int cur_height, size, i = 0;
		u8 msk = 0xff;

		if (!mask)
			return;

		kfree(ops->cursor_state.mask);
		ops->cursor_state.mask = mask;

		ops->p->cursor_shape = vc->vc_cursor_type;
		cursor.set |= FB_CUR_SETSHAPE;

		switch (ops->p->cursor_shape & CUR_HWMASK) {
		case CUR_NONE:
			cur_height = 0;
			break;
		case CUR_UNDERLINE:
			cur_height = (vc->vc_font.height < 10) ? 1 : 2;
			break;
		case CUR_LOWER_THIRD:
			cur_height = vc->vc_font.height/3;
			break;
		case CUR_LOWER_HALF:
			cur_height = vc->vc_font.height >> 1;
			break;
		case CUR_TWO_THIRDS:
			cur_height = (vc->vc_font.height << 1)/3;
			break;
		case CUR_BLOCK:
		default:
			cur_height = vc->vc_font.height;
			break;
		}
		size = (vc->vc_font.height - cur_height) * w;
		while (size--)
			mask[i++] = ~msk;
		size = cur_height * w;
		while (size--)
			mask[i++] = msk;
	}
/*
	DCノード開始処理
*/
void
do_dc_takeover(long long action,
	       enum crmd_fsa_cause cause,
	       enum crmd_fsa_state cur_state,
	       enum crmd_fsa_input current_input,
	       fsa_data_t *msg_data)
{
	int rc = cib_ok;
	xmlNode *cib = NULL;
	static const char *cluster_type = NULL;
	
	if(cluster_type == NULL) {
	    cluster_type = getenv("HA_cluster_type");
	}
	if(cluster_type == NULL) {
	    cluster_type = "Heartbeat";
	}
	
	crm_info("Taking over DC status for this partition");
	/* -------- ★★★★★★★★フラグ的な意味あいでの、DCノードはここでセット --------- */
	set_bit_inplace(fsa_input_register, R_THE_DC);

#if SUPPORT_AIS
	if(is_openais_cluster()) {
	    send_ais_text(crm_class_quorum, NULL, TRUE, NULL, crm_msg_ais);
	}
#endif
	
	if(voted != NULL) {
		/* votedハッシュテーブルを破棄する */
		crm_debug_2("Destroying voted hash");
		g_hash_table_destroy(voted);
		voted = NULL;
	}
	
	/* R_JOIN_OK, R_INVOKE_PEフラグセット */
	set_bit_inplace(fsa_input_register, R_JOIN_OK);
	set_bit_inplace(fsa_input_register, R_INVOKE_PE);
	
	/* CIBのset_master処理を実行する */
	fsa_cib_conn->cmds->set_master(fsa_cib_conn, cib_scope_local);
	
	/* 初期CIBのXMLを生成する */
	cib = create_xml_node(NULL, XML_TAG_CIB);
	/* 生成したXMLにCRM_FEATURE_SETをセットする */
	crm_xml_add(cib, XML_ATTR_CRM_VERSION, CRM_FEATURE_SET);
	/* CIBを生成した初期XMLで更新する */
	fsa_cib_update(XML_TAG_CIB, cib, cib_quorum_override, rc);
	/* 更新コールバックをセットする */
	add_cib_op_callback(fsa_cib_conn, rc, FALSE, NULL, feature_update_callback);

	/* CIBの"dc-version","cluster-infrastructure"属性を更新する */
	update_attr(fsa_cib_conn, cib_none, XML_CIB_TAG_CRMCONFIG,
		    NULL, NULL, NULL, "dc-version", VERSION"-"BUILD_VERSION, FALSE);

	update_attr(fsa_cib_conn, cib_none, XML_CIB_TAG_CRMCONFIG,
		    NULL, NULL, NULL, "cluster-infrastructure", cluster_type, FALSE);
	
	/* config_readトリガーを叩く */
	mainloop_set_trigger(config_read);
	
	free_xml(cib);
}
Ejemplo n.º 7
0
static gboolean
crmd_ais_dispatch(AIS_Message * wrapper, char *data, int sender)
{
    int seq = 0;
    xmlNode *xml = NULL;
    const char *seq_s = NULL;

    xml = string2xml(data);
    if (xml == NULL) {
        crm_err("Could not parse message content (%d): %.100s", wrapper->header.id, data);
        return TRUE;
    }

    switch (wrapper->header.id) {
        case crm_class_members:
            seq_s = crm_element_value(xml, "id");
            seq = crm_int_helper(seq_s, NULL);
            set_bit_inplace(fsa_input_register, R_PEER_DATA);
            post_cache_update(seq);

            /* fall through */
        case crm_class_quorum:
            crm_update_quorum(crm_have_quorum, FALSE);
            if (AM_I_DC) {
                const char *votes = crm_element_value(xml, "expected");

                if (votes == NULL || check_number(votes) == FALSE) {
                    crm_log_xml_err(xml, "Invalid quorum/membership update");

                } else {
                    int rc = update_attr(fsa_cib_conn,
                                         cib_quorum_override | cib_scope_local | cib_inhibit_notify,
                                         XML_CIB_TAG_CRMCONFIG, NULL, NULL, NULL, NULL,
                                         XML_ATTR_EXPECTED_VOTES, votes, FALSE);

                    crm_info("Setting expected votes to %s", votes);
                    if (cib_ok > rc) {
                        crm_err("Quorum update failed: %s", cib_error2string(rc));
                    }
                }
            }
            break;

        case crm_class_cluster:
            crm_xml_add(xml, F_ORIG, wrapper->sender.uname);
            crm_xml_add_int(xml, F_SEQ, wrapper->id);
            crmd_ha_msg_filter(xml);
            break;

        case crm_class_rmpeer:
            /* Ignore */
            break;

        case crm_class_notify:
        case crm_class_nodeid:
            crm_err("Unexpected message class (%d): %.100s", wrapper->header.id, data);
            break;

        default:
            crm_err("Invalid message class (%d): %.100s", wrapper->header.id, data);
    }

    free_xml(xml);
    return TRUE;
}
Ejemplo n.º 8
0
static int
process_intf(struct distr_msg_hdr *hdr, const char *nodename,
             struct distr_msg_intf *intf, char *from)
{
    char *intfname;
    int remaining, offset;

    uint32_t handle = 0;
    int parent = 0, level = 0, link = 0, index = 0;

    intf_t *local_intf;
    node_t *remote_node;

    intfname = ((char *) intf) + sizeof(*intf);

    if (c_debug)
        fprintf(stderr, "Processing interface %s (offset: %d " \
                "optslen: %d namelen: %d hdrsize: %d)\n",
                intfname ? intfname : "null", ntohs(intf->i_offset),
                intf->i_optslen, intf->i_namelen, sizeof(*intf));

    if (intf->i_namelen < 4 || intf->i_namelen > IFNAME_MAX) {
        if (c_debug)
            fprintf(stderr, "Discarding malformed packet (invalid namelen %d)\n",
                    intf->i_namelen);
        return -1;
    }

    if ('\0' == *intfname) {
        if (c_debug)
            fprintf(stderr, "Discarding malformed packet (empty linkname)\n");
        return -1;
    }

    index = ntohs(intf->i_index);

    if (intf->i_optslen) {
        offset = sizeof(*intf) + intf->i_namelen;
        remaining = intf->i_optslen;

        while (remaining > 0) {
            struct distr_msg_ifopt *opt;

            opt = (struct distr_msg_ifopt *) (((char *) intf) + offset);

            if (opt->io_len > (remaining - sizeof(*opt))) {
                if (c_debug)
                    fprintf(stderr, "Discarding malformed packet (invalid opt len)\n");
                return -1;
            }

            switch (opt->io_type) {
            case IFOPT_HANDLE:
                if (opt->io_len != sizeof(uint32_t)) {
                    if (c_debug)
                        fprintf(stderr, "Discarding malformed packet " \
                                "(invalid opt len for handle)\n");
                    return -1;
                }

                handle = ntohl(*(uint32_t *) (((char *) opt) + sizeof (*opt)));
                break;

            case IFOPT_PARENT:
                parent = ntohs(opt->io_pad);
                break;

            case IFOPT_LEVEL:
                level = ntohs(opt->io_pad);
                break;

            case IFOPT_LINK:
                link = ntohs(opt->io_pad);
                break;
            }

            remaining -= (sizeof(*opt) + opt->io_len);
            offset += (sizeof(*opt) + opt->io_len);
        }

        if (remaining < 0)
            if (c_debug)
                fprintf(stderr, "Leftover from options: %d\n", abs(remaining));
    }

    remote_node = lookup_node(nodename, 1);

    if (NULL == remote_node) {
        if (c_debug)
            fprintf(stderr, "Could not create node entry for remote node\n");
        return -1;
    }

    if (remote_node->n_from)
        xfree((void *) remote_node->n_from);
    remote_node->n_from = strdup(from);

    local_intf = lookup_intf(remote_node, intfname, handle, parent);

    if (NULL == local_intf) {
        if (c_debug)
            fprintf(stderr, "Could not crate interface for remote interface\n");
        return -1;
    }

    offset = sizeof(*intf) + intf->i_optslen + intf->i_namelen;
    remaining = ntohs(intf->i_offset) - offset;

    while (remaining > 0) {
        struct distr_msg_attr *attr;
        attr = (struct distr_msg_attr *) (((char *) intf) + offset);

        if (c_debug)
            fprintf(stderr, "Attribute type %d %llu %llu\n",
                    attr->a_type, attr->a_rx, attr->a_tx);

        if (attr->a_type >= ATTR_MAX)
            goto skip;

        if (attr->a_type == BYTES) {
            local_intf->i_rx_bytes.r_total = attr->a_rx;
            local_intf->i_tx_bytes.r_total = attr->a_tx;
            local_intf->i_rx_bytes.r_overflows = attr->a_rx_overflows;
            local_intf->i_tx_bytes.r_overflows = attr->a_tx_overflows;
        } else if (attr->a_type == PACKETS) {
            local_intf->i_rx_packets.r_total = attr->a_rx;
            local_intf->i_tx_packets.r_total = attr->a_tx;
            local_intf->i_rx_packets.r_overflows = attr->a_rx_overflows;
            local_intf->i_tx_packets.r_overflows = attr->a_tx_overflows;
        } else {
            int flags = (attr->a_flags & ATTR_RX_PROVIDED ? RX_PROVIDED : 0) |
                        (attr->a_flags & ATTR_TX_PROVIDED ? TX_PROVIDED : 0);

            update_attr(local_intf, attr->a_type, attr->a_rx, attr->a_tx,
                        flags);
        }

skip:
        remaining -= sizeof(*attr);
        offset += sizeof(*attr);
    }

    if (intf->i_flags & IF_IS_CHILD)
        local_intf->i_is_child = 1;
    local_intf->i_level = level;
    local_intf->i_link = link;

    notify_update(local_intf);
    increase_lifetime(local_intf, 1);

    if (remaining < 0)
        if (c_debug)
            fprintf(stderr, "Leftover from attributes: %d\n", abs(remaining));

    return 0;
}
Ejemplo n.º 9
0
static void sysctl_read(void)
{
	int mib[] = {CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0};
	size_t n;
	char *buf, *next, *lim;

	if (sysctl(mib, 6, NULL, &n, NULL, 0) < 0)
		quit("sysctl() failed");

	if (c_debug)
		fprintf(stderr, "sysctl 1-pass n=%d\n", (int) n);

	buf = xcalloc(1, n);

	if (sysctl(mib, 6, buf, &n, NULL, 0) < 0)
		quit("sysctl() failed");

	if (c_debug)
		fprintf(stderr, "sysctl 2-pass n=%d\n", (int) n);

	lim = buf + n;
	next = buf;

	while (next < lim) {
		char ifname[IFNAME_MAX];
		int iflen = sizeof(ifname) - 1;
		struct if_msghdr *ifm, *nextifm;
		struct sockaddr_dl *sdl;
		struct item *it;

		memset(ifname, 0, sizeof(ifname));

		ifm = (struct if_msghdr *) next;
		if (ifm->ifm_type != RTM_IFINFO)
			break;

		next += ifm->ifm_msglen;
		while (next < lim) {
			nextifm = (struct if_msghdr *) next;
			if (nextifm->ifm_type != RTM_NEWADDR)
				break;
			next += nextifm->ifm_msglen;
		}

		sdl = (struct sockaddr_dl *) (ifm + 1);

		if (sdl->sdl_family != AF_LINK)
			continue;

		if (cfg_show_only_running && !(ifm->ifm_flags & IFF_UP))
			continue;

		if (iflen > sd->sdl_nlen)
			iflen = sdl->sdl_nlen;

		memcpy(ifname, sdl->sdl_data, iflen);
		
		if (c_debug)
			fprintf(stderr, "Processing %s\n", ifname);

		it = lookup_item(get_local_node(), ifname, 0, 0);
		if (it == NULL)
			continue;

		set_item_attrs(it, ATTR(BYTES), ATTR(PACKETS), ATTR(BYTES));

		update_attr(it, ATTR(PACKETS),
			    ifm->ifm_data.ifi_ipackets,
			    ifm->ifm_data.ifi_opackets,
			    RX_PROVIDED | TX_PROVIDED);

		update_attr(it, ATTR(BYTES),
			    ifm->ifm_data.ifi_ibytes,
			    ifm->ifm_data.ifi_obytes,
			    RX_PROVIDED | TX_PROVIDED);

		update_attr(it, ATTR(ERRORS),
			    ifm->ifm_data.ifi_ierrors,
			    ifm->ifm_data.ifi_oerrors,
			    RX_PROVIDED | TX_PROVIDED);

		update_attr(it, ATTR(COLLISIONS),
			    0, ifm->ifm_data.ifi_collisions,
			    TX_PROVIDED);

		update_attr(it, ATTR(MULTICAST),
			    ifm->ifm_data.ifi_imcasts,
			    0,
			    RX_PROVIDED);

		update_attr(it, ATTR(DROP),
			    0,
			    ifm->ifm_data.ifi_iqdrops,
			    TX_PROVIDED);

		notify_update(it, NULL);
		increase_lifetime(it, 1);
	}

	xfree(buf);
}
Ejemplo n.º 10
0
static void
kstat_do_read(void)
{
	kstat_ctl_t *   kc;
	kstat_t *       kst;
	kstat_named_t * kn, *kn2;
	intf_t *        i;
	
	if (!(kc = kstat_open()))
		quit("kstat_open() failed");
	
	if ((kst = kstat_lookup(kc, NULL, -1, NULL))) {
		for (; kst; kst = kst->ks_next) {
			if (strcmp(kst->ks_class, "net"))
				continue;
			
			if (kstat_read(kc, kst, NULL) < 0)
				continue;

			if (!strcmp(kst->ks_name, "zero_copy"))
				continue;

			i = lookup_intf(get_local_node(), kst->ks_name, 0, 0);

			if (NULL == i)
				continue;

#define KSTAT_GET(S) (kstat_named_t *) kstat_data_lookup(kst, #S)

			if ((kn = KSTAT_GET(rbytes64))) {
				i->i_rx_bytes.r_total = kn->value.ui64;
				i->i_rx_bytes.r_is64bit = 1;
			} else if ((kn = KSTAT_GET(rbytes)))
				i->i_rx_bytes.r_total = kn->value.ui32;

			if ((kn = KSTAT_GET(ipackets64))) {
				i->i_rx_packets.r_total = kn->value.ui64;
				i->i_rx_packets.r_is64bit = 1;
			} else if ((kn = KSTAT_GET(ipackets)))
				i->i_rx_packets.r_total = kn->value.ui32;

			if ((kn = KSTAT_GET(obytes64)))
				i->i_tx_bytes.r_total = kn->value.ui64;
			else if ((kn = KSTAT_GET(obytes)))
				i->i_tx_bytes.r_total = kn->value.ui32;

			if ((kn = KSTAT_GET(opackets64)))
				i->i_tx_packets.r_total = kn->value.ui64;
			else if ((kn = KSTAT_GET(opackets)))
				i->i_tx_packets.r_total = kn->value.ui32;

			if ((kn = KSTAT_GET(ierror)) && (kn2 = KSTAT_GET(oerrors)))
				update_attr(i, ERRORS, kn->value.ui32, kn2->value.ui32,
					RX_PROVIDED | TX_PROVIDED);

			if ((kn = KSTAT_GET(multircv64)) && (kn2 = KSTAT_GET(multixmt64)))
				update_attr(i, MULTICAST, kn->value.ui64, kn2->value.ui64,
					RX_PROVIDED | TX_PROVIDED);
			else if ((kn = KSTAT_GET(multircv)) && (kn2 = KSTAT_GET(multixmt)))
				update_attr(i, MULTICAST, kn->value.ui32, kn2->value.ui32,
					RX_PROVIDED | TX_PROVIDED);

			if ((kn = KSTAT_GET(brdcstrcv)) && (kn2 = KSTAT_GET(brdcstxmt)))
				update_attr(i, BROADCAST, kn->value.ui32, kn2->value.ui32,
					RX_PROVIDED | TX_PROVIDED);

#undef KSTAT_GET

			notify_update(i);
			increase_lifetime(i, 1);
		}
	}
	
	kstat_close(kc);
}