예제 #1
0
static int aggregation_enable(struct ubus_context *ctx, struct ubus_object *obj,
		      struct ubus_request_data *req, const char *method,
		      struct blob_attr *msg)
{
	struct blob_attr *tb[__AGGREGATION_MAX];
	bool en;
	int fds[2];

	blobmsg_parse(aggregation_enable_policy, ARRAY_SIZE(aggregation_enable_policy), tb, blob_data(msg), blob_len(msg));
	
	if(!tb[AGGREGATION_MODULE_ENABLE])
		return UBUS_STATUS_INVALID_ARGUMENT;

	en = blobmsg_get_bool(tb[AGGREGATION_MODULE_ENABLE]);

	// TODO:check aggregation module is found, set enable status to require.
	DEBUG("%s received enable message:%s\n", obj->name, en?"true":"false");

	{
		int resCode = LR_SUCCESS;
		char msg[100];
		char *pmsg = msg;
		//	TODO: add other attr


		sprintf(msg,"set aggregation module to %s", en ? "true":"false");

		blob_buf_init(&b, 0);
		//blobmsg_add_u8(&b, "module_en",en);
		blobmsg_add_string(&b, "msg", pmsg);
		blobmsg_add_u16(&b, "resCode", resCode);

		req->deferred = false;
		ubus_send_reply(ctx, req, b.head);


	}
#if 0
	if(pipe(fds) == -1) {
		fprintf(stderr, "Failed to create pipe\n");
		return -1;
	}

	ubus_request_set_fd(ctx, req, fds[0]);
	ubus_complete_deferred_request(ctx, req, 0);

	{
		char data[100]={0};
		sprintf(data, "module %s\n", en ? "enable" : "disable" );
		if(write(fds[1], data, strlen(data) ) < 0) {
			close(fds[1]);
			free(req);
			return 0;
		} 
	}
#endif

	return 0;
}
예제 #2
0
파일: proto.c 프로젝트: hschaa/netifd
static struct device_addr *
parse_address_item(struct blob_attr *attr, bool v6, bool ext)
{
	struct device_addr *addr;
	struct blob_attr *tb[__ADDR_MAX];
	struct blob_attr *cur;

	if (blobmsg_type(attr) != BLOBMSG_TYPE_TABLE)
		return NULL;

	addr = alloc_device_addr(v6, ext);
	if (!addr)
		return NULL;

	blobmsg_parse(proto_ip_addr, __ADDR_MAX, tb, blobmsg_data(attr), blobmsg_data_len(attr));

	addr->mask = v6 ? 128 : 32;
	if ((cur = tb[ADDR_MASK])) {
		unsigned int new_mask;

		new_mask = parse_netmask_string(blobmsg_data(cur), v6);
		if (new_mask > addr->mask)
			goto error;

		addr->mask = new_mask;
	}

	cur = tb[ADDR_IPADDR];
	if (!cur)
		goto error;

	if (!inet_pton(v6 ? AF_INET6 : AF_INET, blobmsg_data(cur), &addr->addr))
		goto error;

	if ((cur = tb[ADDR_OFFLINK]) && blobmsg_get_bool(cur))
		addr->flags |= DEVADDR_OFFLINK;

	if (!v6) {
		if ((cur = tb[ADDR_BROADCAST]) &&
		    !inet_pton(AF_INET, blobmsg_data(cur), &addr->broadcast))
			goto error;
		if ((cur = tb[ADDR_PTP]) &&
		    !inet_pton(AF_INET, blobmsg_data(cur), &addr->point_to_point))
			goto error;
	} else {
		time_t now = system_get_rtime();
		if ((cur = tb[ADDR_PREFERRED])) {
			int64_t preferred = blobmsg_get_u32(cur);
			int64_t preferred_until = preferred + (int64_t)now;
			if (preferred_until <= LONG_MAX && preferred != 0xffffffffLL)
				addr->preferred_until = preferred_until;
		}

		if ((cur = tb[ADDR_VALID])) {
			int64_t valid = blobmsg_get_u32(cur);
			int64_t valid_until = valid + (int64_t)now;
			if (valid_until <= LONG_MAX && valid != 0xffffffffLL)
				addr->valid_until = valid_until;

		}

		if (addr->valid_until) {
			if (!addr->preferred_until)
				addr->preferred_until = addr->valid_until;
			else if (addr->preferred_until > addr->valid_until)
				goto error;
		}

		if ((cur = tb[ADDR_CLASS]))
			addr->pclass = strdup(blobmsg_get_string(cur));
	}

	return addr;

error:
	free(addr);
	return NULL;
}
예제 #3
0
파일: vlan.c 프로젝트: sevennothing/lros
static int vlan_mstp(struct ubus_context *ctx, struct ubus_object *obj,
		struct ubus_request_data *req, const char *method,
		struct blob_attr *msg)
{
	struct blob_attr *tb[__VLAN_MSTP_MAX];

	int resCode = LR_SUCCESS;
	const char *pmsg =  getJsonMsg(LR_INVALID_PARAM);

	u8 mstid = 0;
	u8 portid = 0;
	u8 portState = 0;
	bool newMSTI = false;
	bool delMSTI = false;
	bool setPortState = false;
	bool flushFids = false;

	blobmsg_parse(vlan_mstp_policy, ARRAY_SIZE(vlan_mstp_policy), tb, blob_data(msg), blob_len(msg));

	if(tb[VLAN_MSTP_FLUSH_FIDS]){
		flushFids = blobmsg_get_bool(tb[VLAN_MSTP_FLUSH_FIDS]);
		if(flushFids){
			/* flush all FIDs */
			resCode = delete_all_vlan_in_vlanDatabase();
			goto process3;
		}

	}

	if(!tb[VLAN_MSTP_MSTID]){
		resCode = LR_INVALID_PARAM;
		goto returnMsg;
	}

	mstid = blobmsg_get_u8(tb[VLAN_MSTP_MSTID]);
	
	if(tb[VLAN_MSTP_NEW_MSTI]){
		newMSTI = blobmsg_get_bool(tb[VLAN_MSTP_NEW_MSTI]);
		if(newMSTI){
			/* create new msti */
			resCode = add_msti_to_hw(mstid);
			goto process2;
		}
	}

	if(tb[VLAN_MSTP_DELETE_MSTI]){
		delMSTI = blobmsg_get_bool(tb[VLAN_MSTP_DELETE_MSTI]);
		if(delMSTI){
			/* delete  msti */
			resCode = delete_msti_to_hw(mstid);
		}

	}

process2:
	if(tb[VLAN_MSTP_SET_PORT_STATE]){
		setPortState = blobmsg_get_bool(tb[VLAN_MSTP_SET_PORT_STATE]);
		if(setPortState){
			/* set port state for msti */
			if(!tb[VLAN_MSTP_PORTID] || !tb[VLAN_MSTP_PORT_STATE]){
				resCode = LR_INVALID_PARAM;
				goto returnMsg;
			}
			portid = blobmsg_get_u8(tb[VLAN_MSTP_PORTID]);
			portState = blobmsg_get_u8(tb[VLAN_MSTP_PORT_STATE]);
			resCode = set_port_state_for_msti(mstid, portid, portState);
		}

	}

process3:

	pmsg = getJsonMsg(resCode);
	

returnMsg:
	blob_buf_init(&b, 0);
	blobmsg_add_string(&b, "msg",pmsg);
	blobmsg_add_u16(&b,"resCode", resCode);

	req->deferred = false;
	ubus_send_reply(ctx, req, b.head);

	return UBUS_STATUS_OK;

}
예제 #4
0
파일: vlan.c 프로젝트: sevennothing/lros
static int vlan_port(struct ubus_context *ctx, struct ubus_object *obj,
		struct ubus_request_data *req, const char *method,
		struct blob_attr *msg)
{
	struct blob_attr *tb[__VLAN_PORT_MAX];

	int resCode = LR_SUCCESS;
	const char *pmsg =  getJsonMsg(LR_INVALID_PARAM);

	u16 vid = 0;
	u8 portid = 0;
	bool bind = false;

	blobmsg_parse(vlan_port_policy, ARRAY_SIZE(vlan_port_policy), tb, blob_data(msg), blob_len(msg));

	if(!tb[VLAN_PORT_VLANID] || !tb[VLAN_PORT_PORTID]){
		resCode = LR_INVALID_PARAM;
		goto returnMsg;
	}
	portid = blobmsg_get_u8(tb[VLAN_PORT_PORTID]);
	vid = blobmsg_get_u16(tb[VLAN_PORT_VLANID]);

	if(tb[VLAN_PORT_BIND]){
		bind = blobmsg_get_bool(tb[VLAN_PORT_BIND]);	
		if(bind){
			BASE_VLAN_PORT port;
			PORT_LINK_TYPE linktype;
			u16 pvid = 1;
			if(!tb[VLAN_PORT_LINKTYPE]){
				linktype = (gDevPorts+portid)->linktype;
			}else{
				linktype = blobmsg_get_u8(tb[VLAN_PORT_LINKTYPE]);	
			}
			get_port_pvid(portid, &pvid);

			port.portid = portid;
			if(linktype ==  PORT_LINK_TYPE_ACCESS){
				if(vid != pvid){
					resCode = LR_ILLEGAL_OPR;
					goto process2;

				}
				port.portAttr.egress = EGRESS_UNTAGGED;
			}else if(linktype == PORT_LINK_TYPE_TRUNK){
				if(vid == pvid)
					port.portAttr.egress = EGRESS_UNTAGGED;
				else
					port.portAttr.egress = EGRESS_TAGGED;
			}else if(linktype == PORT_LINK_TYPE_HYBRID){
				//TODO: hybrid mode
			}else if(linktype == PORT_LINK_TYPE_QINQ){
				//TODO: QinQ mode

			}else{
				resCode = LR_INVALID_PARAM;
				goto returnMsg;
			}
			resCode = bind_vlan_to_port(vid, port);

			goto process2;
		}else{
			resCode = unbind_vlan_from_port(vid, portid);
			goto process2;
		}

	}


process2:

	pmsg = getJsonMsg(resCode);

returnMsg:
	blob_buf_init(&b, 0);
	blobmsg_add_string(&b, "msg",pmsg);
	blobmsg_add_u16(&b,"resCode", resCode);

	req->deferred = false;
	ubus_send_reply(ctx, req, b.head);

	return UBUS_STATUS_OK;


}
예제 #5
0
void
iprule_add(struct blob_attr *attr, bool v6)
{
	struct interface *iif = NULL, *oif = NULL;
	struct blob_attr *tb[__RULE_MAX], *cur;
	struct interface *iface;
	struct iprule *rule;
	int af = v6 ? AF_INET6 : AF_INET;

	blobmsg_parse(rule_attr, __RULE_MAX, tb, blobmsg_data(attr), blobmsg_data_len(attr));

	rule = calloc(1, sizeof(*rule));
	if (!rule)
		return;

	rule->flags = v6 ? IPRULE_INET6 : IPRULE_INET4;
	rule->order = iprules_counter[rule->flags]++;

	if ((cur = tb[RULE_INVERT]) != NULL)
		rule->invert = blobmsg_get_bool(cur);

	if ((cur = tb[RULE_INTERFACE_IN]) != NULL) {
		iif = vlist_find(&interfaces, blobmsg_data(cur), iface, node);

		if (!iif || !iif->l3_dev.dev) {
			DPRINTF("Failed to resolve device of network: %s\n", (char *) blobmsg_data(cur));
			goto error;
		}

		memcpy(rule->in_dev, iif->l3_dev.dev->ifname, sizeof(rule->in_dev));
		rule->flags |= IPRULE_IN;
	}

	if ((cur = tb[RULE_INTERFACE_OUT]) != NULL) {
		oif = vlist_find(&interfaces, blobmsg_data(cur), iface, node);

		if (!oif || !oif->l3_dev.dev) {
			DPRINTF("Failed to resolve device of network: %s\n", (char *) blobmsg_data(cur));
			goto error;
		}

		memcpy(rule->out_dev, oif->l3_dev.dev->ifname, sizeof(rule->out_dev));
		rule->flags |= IPRULE_OUT;
	}

	if ((cur = tb[RULE_SRC]) != NULL) {
		if (!parse_ip_and_netmask(af, blobmsg_data(cur), &rule->src_addr, &rule->src_mask)) {
			DPRINTF("Failed to parse rule source: %s\n", (char *) blobmsg_data(cur));
			goto error;
		}
		rule->flags |= IPRULE_SRC;
	}

	if ((cur = tb[RULE_DEST]) != NULL) {
		if (!parse_ip_and_netmask(af, blobmsg_data(cur), &rule->dest_addr, &rule->dest_mask)) {
			DPRINTF("Failed to parse rule destination: %s\n", (char *) blobmsg_data(cur));
			goto error;
		}
		rule->flags |= IPRULE_DEST;
	}

	if ((cur = tb[RULE_PRIORITY]) != NULL) {
		rule->priority = blobmsg_get_u32(cur);
		rule->flags |= IPRULE_PRIORITY;
	}

	if ((cur = tb[RULE_TOS]) != NULL) {
		if ((rule->tos = blobmsg_get_u32(cur)) > 255) {
			DPRINTF("Invalid TOS value: %u\n", blobmsg_get_u32(cur));
			goto error;
		}
		rule->flags |= IPRULE_TOS;
	}

	if ((cur = tb[RULE_FWMARK]) != NULL) {
		if (!iprule_parse_mark(blobmsg_data(cur), rule)) {
			DPRINTF("Failed to parse rule fwmark: %s\n", (char *) blobmsg_data(cur));
			goto error;
		}
		/* flags set by iprule_parse_mark() */
	}

	if ((cur = tb[RULE_LOOKUP]) != NULL) {
		if (!system_resolve_rt_table(blobmsg_data(cur), &rule->lookup)) {
			DPRINTF("Failed to parse rule lookup table: %s\n", (char *) blobmsg_data(cur));
			goto error;
		}
		rule->flags |= IPRULE_LOOKUP;
	}

	if ((cur = tb[RULE_ACTION]) != NULL) {
		if (!system_resolve_iprule_action(blobmsg_data(cur), &rule->action)) {
			DPRINTF("Failed to parse rule action: %s\n", (char *) blobmsg_data(cur));
			goto error;
		}
		rule->flags |= IPRULE_ACTION;
	}

	if ((cur = tb[RULE_GOTO]) != NULL) {
		rule->gotoid = blobmsg_get_u32(cur);
		rule->flags |= IPRULE_GOTO;
	}

	vlist_add(&iprules, &rule->node, &rule->flags);
	return;

error:
	free(rule);
}
예제 #6
-1
static int watchdog_set(struct ubus_context *ctx, struct ubus_object *obj,
			struct ubus_request_data *req, const char *method,
			struct blob_attr *msg)
{
	struct blob_attr *tb[__WDT_MAX];
	const char *status;

	if (!msg)
		return UBUS_STATUS_INVALID_ARGUMENT;

	blobmsg_parse(watchdog_policy, __WDT_MAX, tb, blob_data(msg), blob_len(msg));
	if (tb[WDT_FREQUENCY]) {
		unsigned int timeout = watchdog_timeout(0);
		unsigned int freq = blobmsg_get_u32(tb[WDT_FREQUENCY]);

		if (freq) {
			if (freq > timeout / 2)
				freq = timeout / 2;
			watchdog_frequency(freq);
		}
	}

	if (tb[WDT_TIMEOUT]) {
		unsigned int timeout = blobmsg_get_u32(tb[WDT_TIMEOUT]);
		unsigned int frequency = watchdog_frequency(0);

		if (timeout <= frequency)
			timeout = frequency * 2;
		 watchdog_timeout(timeout);
	}

	if (tb[WDT_STOP])
		watchdog_set_stopped(blobmsg_get_bool(tb[WDT_STOP]));

	if (watchdog_fd() == NULL)
		status = "offline";
	else if (watchdog_get_stopped())
		status = "stopped";
	else
		status = "running";

	blob_buf_init(&b, 0);
	blobmsg_add_string(&b, "status", status);
	blobmsg_add_u32(&b, "timeout", watchdog_timeout(0));
	blobmsg_add_u32(&b, "frequency", watchdog_frequency(0));
	ubus_send_reply(ctx, req, b.head);

	return 0;
}