Esempio n. 1
0
int ac_kmod_new_datasession(struct capwap_sessionid_element* sessionid, uint8_t binding, uint16_t mtu) {
	int result;
	struct nl_msg* msg;

	ASSERT(sessionid != NULL);

	/* */
	msg = nlmsg_alloc();
	if (!msg) {
		return -1;
	}

	/* */
	genlmsg_put(msg, 0, 0, g_ac.kmodhandle.nlsmartcapwap_id, 0, 0, NLSMARTCAPWAP_CMD_NEW_SESSION, 0);
	nla_put(msg, NLSMARTCAPWAP_ATTR_SESSION_ID, sizeof(struct capwap_sessionid_element), sessionid);
	nla_put_u16(msg, NLSMARTCAPWAP_ATTR_BINDING, binding);
	nla_put_u16(msg, NLSMARTCAPWAP_ATTR_MTU, mtu);

	/* */
	result = ac_kmod_send_and_recv_msg(msg, NULL, NULL);
	if (result) {
		log_printf(LOG_ERR, "Unable to create data session: %d", result);
	}

	/* */
	nlmsg_free(msg);
	return result;
}
Esempio n. 2
0
void send_msg(long int ip, long int puerto, char sentido){
	nla_put_u32( msg, ATTR_ADDR, ip);
	nla_put_u16( msg, ATTR_PORT, puerto);
	nla_put_u16( msg, ATTR_WAY, sentido);
	nl_send_auto_complete(sock, msg);
	printf("Peticion registrada :)");
}
Esempio n. 3
0
static int tcf_pedit_key_ex_dump(struct sk_buff *skb,
				 struct tcf_pedit_key_ex *keys_ex, int n)
{
	struct nlattr *keys_start = nla_nest_start(skb, TCA_PEDIT_KEYS_EX);

	if (!keys_start)
		goto nla_failure;
	for (; n > 0; n--) {
		struct nlattr *key_start;

		key_start = nla_nest_start(skb, TCA_PEDIT_KEY_EX);
		if (!key_start)
			goto nla_failure;

		if (nla_put_u16(skb, TCA_PEDIT_KEY_EX_HTYPE, keys_ex->htype) ||
		    nla_put_u16(skb, TCA_PEDIT_KEY_EX_CMD, keys_ex->cmd))
			goto nla_failure;

		nla_nest_end(skb, key_start);

		keys_ex++;
	}

	nla_nest_end(skb, keys_start);

	return 0;
nla_failure:
	nla_nest_cancel(skb, keys_start);
	return -EINVAL;
}
Esempio n. 4
0
File: ipip.c Progetto: 19Dan01/linux
static int ipip_fill_info(struct sk_buff *skb, const struct net_device *dev)
{
	struct ip_tunnel *tunnel = netdev_priv(dev);
	struct ip_tunnel_parm *parm = &tunnel->parms;

	if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) ||
	    nla_put_in_addr(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) ||
	    nla_put_in_addr(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) ||
	    nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) ||
	    nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos) ||
	    nla_put_u8(skb, IFLA_IPTUN_PMTUDISC,
		       !!(parm->iph.frag_off & htons(IP_DF))))
		goto nla_put_failure;

	if (nla_put_u16(skb, IFLA_IPTUN_ENCAP_TYPE,
			tunnel->encap.type) ||
	    nla_put_be16(skb, IFLA_IPTUN_ENCAP_SPORT,
			 tunnel->encap.sport) ||
	    nla_put_be16(skb, IFLA_IPTUN_ENCAP_DPORT,
			 tunnel->encap.dport) ||
	    nla_put_u16(skb, IFLA_IPTUN_ENCAP_FLAGS,
			tunnel->encap.flags))
		goto nla_put_failure;

	return 0;

nla_put_failure:
	return -EMSGSIZE;
}
Esempio n. 5
0
static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
	u32 seq, int flags, struct net_device *dev)
{
	void *hdr;
	struct wpan_phy *phy;

	pr_debug("%s\n", __func__);

	hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags,
		IEEE802154_LIST_IFACE);
	if (!hdr)
		goto out;

	phy = ieee802154_mlme_ops(dev)->get_phy(dev);
	BUG_ON(!phy);

	if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
	    nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) ||
	    nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
	    nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
		    dev->dev_addr) ||
	    nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR,
			ieee802154_mlme_ops(dev)->get_short_addr(dev)) ||
	    nla_put_u16(msg, IEEE802154_ATTR_PAN_ID,
			ieee802154_mlme_ops(dev)->get_pan_id(dev)))
		goto nla_put_failure;
	wpan_phy_put(phy);
	return genlmsg_end(msg, hdr);

nla_put_failure:
	wpan_phy_put(phy);
	genlmsg_cancel(msg, hdr);
out:
	return -EMSGSIZE;
}
Esempio n. 6
0
File: ip_gre.c Progetto: 3null/linux
static int ipgre_fill_info(struct sk_buff *skb, const struct net_device *dev)
{
	struct ip_tunnel *t = netdev_priv(dev);
	struct ip_tunnel_parm *p = &t->parms;

	if (nla_put_u32(skb, IFLA_GRE_LINK, p->link) ||
	    nla_put_be16(skb, IFLA_GRE_IFLAGS, tnl_flags_to_gre_flags(p->i_flags)) ||
	    nla_put_be16(skb, IFLA_GRE_OFLAGS, tnl_flags_to_gre_flags(p->o_flags)) ||
	    nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) ||
	    nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) ||
	    nla_put_be32(skb, IFLA_GRE_LOCAL, p->iph.saddr) ||
	    nla_put_be32(skb, IFLA_GRE_REMOTE, p->iph.daddr) ||
	    nla_put_u8(skb, IFLA_GRE_TTL, p->iph.ttl) ||
	    nla_put_u8(skb, IFLA_GRE_TOS, p->iph.tos) ||
	    nla_put_u8(skb, IFLA_GRE_PMTUDISC,
		       !!(p->iph.frag_off & htons(IP_DF))))
		goto nla_put_failure;

	if (nla_put_u16(skb, IFLA_GRE_ENCAP_TYPE,
			t->encap.type) ||
	    nla_put_u16(skb, IFLA_GRE_ENCAP_SPORT,
			t->encap.sport) ||
	    nla_put_u16(skb, IFLA_GRE_ENCAP_DPORT,
			t->encap.dport) ||
	    nla_put_u16(skb, IFLA_GRE_ENCAP_FLAGS,
			t->encap.dport))
		goto nla_put_failure;

	return 0;

nla_put_failure:
	return -EMSGSIZE;
}
Esempio n. 7
0
static int l2tp_nl_session_send(struct sk_buff *skb, u32 pid, u32 seq, int flags,
				struct l2tp_session *session)
{
	void *hdr;
	struct nlattr *nest;
	struct l2tp_tunnel *tunnel = session->tunnel;
	struct sock *sk = NULL;

	sk = tunnel->sock;

	hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags, L2TP_CMD_SESSION_GET);
	if (IS_ERR(hdr))
		return PTR_ERR(hdr);

	nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id);
	nla_put_u32(skb, L2TP_ATTR_SESSION_ID, session->session_id);
	nla_put_u32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id);
	nla_put_u32(skb, L2TP_ATTR_PEER_SESSION_ID, session->peer_session_id);
	nla_put_u32(skb, L2TP_ATTR_DEBUG, session->debug);
	nla_put_u16(skb, L2TP_ATTR_PW_TYPE, session->pwtype);
	nla_put_u16(skb, L2TP_ATTR_MTU, session->mtu);
	if (session->mru)
		nla_put_u16(skb, L2TP_ATTR_MRU, session->mru);

	if (session->ifname && session->ifname[0])
		nla_put_string(skb, L2TP_ATTR_IFNAME, session->ifname);
	if (session->cookie_len)
		nla_put(skb, L2TP_ATTR_COOKIE, session->cookie_len, &session->cookie[0]);
	if (session->peer_cookie_len)
		nla_put(skb, L2TP_ATTR_PEER_COOKIE, session->peer_cookie_len, &session->peer_cookie[0]);
	nla_put_u8(skb, L2TP_ATTR_RECV_SEQ, session->recv_seq);
	nla_put_u8(skb, L2TP_ATTR_SEND_SEQ, session->send_seq);
	nla_put_u8(skb, L2TP_ATTR_LNS_MODE, session->lns_mode);
#ifdef CONFIG_XFRM
	if ((sk) && (sk->sk_policy[0] || sk->sk_policy[1]))
		nla_put_u8(skb, L2TP_ATTR_USING_IPSEC, 1);
#endif
	if (session->reorder_timeout)
		nla_put_msecs(skb, L2TP_ATTR_RECV_TIMEOUT, session->reorder_timeout);

	nest = nla_nest_start(skb, L2TP_ATTR_STATS);
	if (nest == NULL)
		goto nla_put_failure;
	nla_put_u64(skb, L2TP_ATTR_TX_PACKETS, session->stats.tx_packets);
	nla_put_u64(skb, L2TP_ATTR_TX_BYTES, session->stats.tx_bytes);
	nla_put_u64(skb, L2TP_ATTR_TX_ERRORS, session->stats.tx_errors);
	nla_put_u64(skb, L2TP_ATTR_RX_PACKETS, session->stats.rx_packets);
	nla_put_u64(skb, L2TP_ATTR_RX_BYTES, session->stats.rx_bytes);
	nla_put_u64(skb, L2TP_ATTR_RX_SEQ_DISCARDS, session->stats.rx_seq_discards);
	nla_put_u64(skb, L2TP_ATTR_RX_OOS_PACKETS, session->stats.rx_oos_packets);
	nla_put_u64(skb, L2TP_ATTR_RX_ERRORS, session->stats.rx_errors);
	nla_nest_end(skb, nest);

	return genlmsg_end(skb, hdr);

 nla_put_failure:
	genlmsg_cancel(skb, hdr);
	return -1;
}
Esempio n. 8
0
static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 pid, u32 seq, int flags,
			       struct l2tp_tunnel *tunnel)
{
	void *hdr;
	struct nlattr *nest;
	struct sock *sk = NULL;
	struct inet_sock *inet;

	hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags,
			  L2TP_CMD_TUNNEL_GET);
	if (IS_ERR(hdr))
		return PTR_ERR(hdr);

	nla_put_u8(skb, L2TP_ATTR_PROTO_VERSION, tunnel->version);
	nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id);
	nla_put_u32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id);
	nla_put_u32(skb, L2TP_ATTR_DEBUG, tunnel->debug);
	nla_put_u16(skb, L2TP_ATTR_ENCAP_TYPE, tunnel->encap);

	nest = nla_nest_start(skb, L2TP_ATTR_STATS);
	if (nest == NULL)
		goto nla_put_failure;

	nla_put_u64(skb, L2TP_ATTR_TX_PACKETS, tunnel->stats.tx_packets);
	nla_put_u64(skb, L2TP_ATTR_TX_BYTES, tunnel->stats.tx_bytes);
	nla_put_u64(skb, L2TP_ATTR_TX_ERRORS, tunnel->stats.tx_errors);
	nla_put_u64(skb, L2TP_ATTR_RX_PACKETS, tunnel->stats.rx_packets);
	nla_put_u64(skb, L2TP_ATTR_RX_BYTES, tunnel->stats.rx_bytes);
	nla_put_u64(skb, L2TP_ATTR_RX_SEQ_DISCARDS, tunnel->stats.rx_seq_discards);
	nla_put_u64(skb, L2TP_ATTR_RX_OOS_PACKETS, tunnel->stats.rx_oos_packets);
	nla_put_u64(skb, L2TP_ATTR_RX_ERRORS, tunnel->stats.rx_errors);
	nla_nest_end(skb, nest);

	sk = tunnel->sock;
	if (!sk)
		goto out;

	inet = inet_sk(sk);

	switch (tunnel->encap) {
	case L2TP_ENCAPTYPE_UDP:
		nla_put_u16(skb, L2TP_ATTR_UDP_SPORT, ntohs(inet->inet_sport));
		nla_put_u16(skb, L2TP_ATTR_UDP_DPORT, ntohs(inet->inet_dport));
		nla_put_u8(skb, L2TP_ATTR_UDP_CSUM, (sk->sk_no_check != UDP_CSUM_NOXMIT));
		/* NOBREAK */
	case L2TP_ENCAPTYPE_IP:
		nla_put_be32(skb, L2TP_ATTR_IP_SADDR, inet->inet_saddr);
		nla_put_be32(skb, L2TP_ATTR_IP_DADDR, inet->inet_daddr);
		break;
	}

out:
	return genlmsg_end(skb, hdr);

nla_put_failure:
	genlmsg_cancel(skb, hdr);
	return -1;
}
Esempio n. 9
0
static int bond_fill_slave_info(struct sk_buff *skb,
				const struct net_device *bond_dev,
				const struct net_device *slave_dev)
{
	struct slave *slave = bond_slave_get_rtnl(slave_dev);

	if (nla_put_u8(skb, IFLA_BOND_SLAVE_STATE, bond_slave_state(slave)))
		goto nla_put_failure;

	if (nla_put_u8(skb, IFLA_BOND_SLAVE_MII_STATUS, slave->link))
		goto nla_put_failure;

	if (nla_put_u32(skb, IFLA_BOND_SLAVE_LINK_FAILURE_COUNT,
			slave->link_failure_count))
		goto nla_put_failure;

	if (nla_put(skb, IFLA_BOND_SLAVE_PERM_HWADDR,
		    slave_dev->addr_len, slave->perm_hwaddr))
		goto nla_put_failure;

	if (nla_put_u16(skb, IFLA_BOND_SLAVE_QUEUE_ID, slave->queue_id))
		goto nla_put_failure;

	if (BOND_MODE(slave->bond) == BOND_MODE_8023AD) {
		const struct aggregator *agg;
		const struct port *ad_port;

		ad_port = &SLAVE_AD_INFO(slave)->port;
		agg = SLAVE_AD_INFO(slave)->port.aggregator;
		if (agg) {
			if (nla_put_u16(skb, IFLA_BOND_SLAVE_AD_AGGREGATOR_ID,
					agg->aggregator_identifier))
				goto nla_put_failure;
			if (nla_put_u8(skb,
				       IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE,
				       ad_port->actor_oper_port_state))
				goto nla_put_failure;
			if (nla_put_u16(skb,
					IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE,
					ad_port->partner_oper.port_state))
				goto nla_put_failure;
		}
	}

	return 0;

nla_put_failure:
	return -EMSGSIZE;
}
int mod_subflow(
  struct mptcp_state *mp_state,
  uint32_t src_ip,
  uint32_t src_locid,
  struct connection *conn,
  int command)
{
    int rc = 0;
    struct nl_sock_data *nlsd;
    struct nl_sock *sock;
    struct nl_msg *msg;
    msg = nlmsg_alloc();

    nlsd = (struct nl_sock_data *)mptcp_state_get_comms(mp_state);

    sock = nlsd->sock;

    genlmsg_put(msg,
        0,
        0,
        nlsd->family_id,
        CA_PM_GENL_HDRLEN,
        0,
        command,
        CA_PM_GENL_VERSION);

    //print_debug("Subflow: %s -> %s:%d\n", src->name, ip_to_str(htonl(conn->daddr)), conn->dport);

    rc = nla_put_u32 (msg, CONTEXT_MPTCP_TOKEN, conn->token);
    if(rc < 0) print_error("NLA PUT ERROR CONTEXT_MPTCP_TOKEN\n");

    rc = nla_put_u32 (msg, CONTEXT_SRC_ADDR, src_ip);
    if(rc < 0) print_error("NLA PUT ERROR CONTEXT_SRC_ADDR\n");

    rc = nla_put_u32 (msg, CONTEXT_DST_ADDR, conn->daddr);
    if(rc < 0) print_error("NLA PUT ERROR CONTEXT_DST_ADDR\n");

    rc = nla_put_u16 (msg, CONTEXT_DST_PORT, conn->dport);
    if(rc < 0) print_error("NLA PUT ERROR CONTEXT_DST_PORT\n");

    rc = nla_put_u16 (msg, CONTEXT_LOC_ID, src_locid);
    if(rc < 0) print_error("NLA PUT ERROR CONTEXT_LOC_ID\n");

    nl_send_auto(sock, msg);
    nlmsg_free(msg);

    return 0;
}
Esempio n. 11
0
int ac_kmod_create_iface(const char* ifname, uint16_t mtu) {
	int result;
	struct nl_msg* msg;
	uint32_t ifindex = 0;

	ASSERT(ifname != NULL);
	ASSERT(mtu > 0);

	/* */
	msg = nlmsg_alloc();
	if (!msg) {
		return -1;
	}

	/* */
	genlmsg_put(msg, 0, 0, g_ac.kmodhandle.nlsmartcapwap_id, 0, 0, NLSMARTCAPWAP_CMD_ADD_IFACE, 0);
	nla_put_string(msg, NLSMARTCAPWAP_ATTR_IFPHY_NAME, ifname);
	nla_put_u16(msg, NLSMARTCAPWAP_ATTR_MTU, mtu);

	/* */
	result = ac_kmod_send_and_recv_msg(msg, cb_kmod_create_iface, &ifindex);
	if (!result) {
		result = (ifindex ? (int)ifindex : -1);
	} else {
		log_printf(LOG_ERR, "Unable to create data session: %d", result);
	}

	/* */
	nlmsg_free(msg);
	return result;
}
Esempio n. 12
0
int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate)
{
	const struct lwtunnel_encap_ops *ops;
	struct nlattr *nest;
	int ret = -EINVAL;

	if (!lwtstate)
		return 0;

	if (lwtstate->type == LWTUNNEL_ENCAP_NONE ||
	    lwtstate->type > LWTUNNEL_ENCAP_MAX)
		return 0;

	ret = -EOPNOTSUPP;
	nest = nla_nest_start(skb, RTA_ENCAP);
	rcu_read_lock();
	ops = rcu_dereference(lwtun_encaps[lwtstate->type]);
	if (likely(ops && ops->fill_encap))
		ret = ops->fill_encap(skb, lwtstate);
	rcu_read_unlock();

	if (ret)
		goto nla_put_failure;
	nla_nest_end(skb, nest);
	ret = nla_put_u16(skb, RTA_ENCAP_TYPE, lwtstate->type);
	if (ret)
		goto nla_put_failure;

	return 0;

nla_put_failure:
	nla_nest_cancel(skb, nest);

	return (ret == -EOPNOTSUPP ? 0 : ret);
}
Esempio n. 13
0
int netlink_send_cw(unsigned char ca_num, ca_descr_t *ca_descr) {
        struct sk_buff *skb;
	void *msg_head;
	int ret;

        skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
	if (!skb)
		goto out;

       	msg_head = genlmsg_put(skb, 0, 0, &ca_family, 0, CMD_SET_CW);
	if (!msg_head) {
		goto out;
	}

	ret = nla_put_u16(skb, ATTR_CA_NUM, ca_num);
	if (ret)
		goto out;
	ret = nla_put(skb, ATTR_CA_DESCR, sizeof(ca_descr_t), ca_descr);
	if (ret)
		goto out;

	genlmsg_end(skb, msg_head);

	ret = genlmsg_unicast(&init_net, skb, processPid );
	if (ret)
		goto out;

	return 0;

 out:
        printk("dvbsoftwareca: send_cw error\n");
	return 0;
}
Esempio n. 14
0
int ieee802154_nl_disassoc_indic(struct net_device *dev,
		struct ieee802154_addr *addr, u8 reason)
{
	struct sk_buff *msg;

	pr_debug("%s\n", __func__);

	msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_INDIC);
	if (!msg)
		return -ENOBUFS;

	if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
	    nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
	    nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
		    dev->dev_addr))
		goto nla_put_failure;
	if (addr->addr_type == IEEE802154_ADDR_LONG) {
		if (nla_put(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN,
			    addr->hwaddr))
			goto nla_put_failure;
	} else {
		if (nla_put_u16(msg, IEEE802154_ATTR_SRC_SHORT_ADDR,
				addr->short_addr))
			goto nla_put_failure;
	}
	if (nla_put_u8(msg, IEEE802154_ATTR_REASON, reason))
		goto nla_put_failure;
	return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);

nla_put_failure:
	nlmsg_free(msg);
	return -ENOBUFS;
}
Esempio n. 15
0
void encoder::send_encoded_packet(uint8_t type)
{
    struct nl_msg *msg;
    struct nlattr *attr;
    uint8_t *data;
    size_t symbols = this->symbols();

    VLOG(LOG_PKT) << "Encoder " << m_coder << ": Send "
                  << (m_enc_pkt_count < symbols ? "systematic" : "encoded");

    msg = nlmsg_alloc();
    genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, m_io->genl_family(),
                0, 0, BATADV_HLP_C_FRAME, 1);

    nla_put_u32(msg, BATADV_HLP_A_IFINDEX, m_io->ifindex());
    nla_put(msg, BATADV_HLP_A_SRC, ETH_ALEN, _key.src);
    nla_put(msg, BATADV_HLP_A_DST, ETH_ALEN, _key.dst);
    nla_put_u16(msg, BATADV_HLP_A_BLOCK, _key.block);
    nla_put_u8(msg, BATADV_HLP_A_TYPE, type);
    attr = nla_reserve(msg, BATADV_HLP_A_FRAME, this->payload_size());
    data = reinterpret_cast<uint8_t *>(nla_data(attr));

    this->encode(data);
    m_io->send_msg(msg);
    nlmsg_free(msg);

    m_enc_pkt_count++;
    inc("encoded sent");
    m_budget--;
}
Esempio n. 16
0
void recoder::send_rec_packet()
{
    struct nl_msg *msg;
    struct nlattr *attr;
    uint8_t *data;

    msg = nlmsg_alloc();
    genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, m_io->genl_family(),
                0, 0, BATADV_HLP_C_FRAME, 1);

    nla_put_u32(msg, BATADV_HLP_A_IFINDEX, m_io->ifindex());
    nla_put(msg, BATADV_HLP_A_SRC, ETH_ALEN, _key.src);
    nla_put(msg, BATADV_HLP_A_DST, ETH_ALEN, _key.dst);
    nla_put_u16(msg, BATADV_HLP_A_BLOCK, _key.block);
    nla_put_u8(msg, BATADV_HLP_A_TYPE, REC_PACKET);
    attr = nla_reserve(msg, BATADV_HLP_A_FRAME, this->payload_size());
    data = reinterpret_cast<uint8_t *>(nla_data(attr));

    this->recode(data);
    m_io->send_msg(msg);
    nlmsg_free(msg);

    m_rec_pkt_count++;
    inc("forward packets written");
}
Esempio n. 17
0
int ieee802154_nl_assoc_confirm(struct net_device *dev, u16 short_addr,
		u8 status)
{
	struct sk_buff *msg;

	pr_debug("%s\n", __func__);

	msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_CONF);
	if (!msg)
		return -ENOBUFS;

	nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
	nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
	nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
			dev->dev_addr);

	nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr);
	nla_put_u8(msg, IEEE802154_ATTR_STATUS, status);

	return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);

nla_put_failure:
	nlmsg_free(msg);
	return -ENOBUFS;
}
Esempio n. 18
0
static int dsa_slave_fill_info(struct net_device *dev, struct sk_buff *skb,
			       const unsigned char *addr, u16 vid,
			       bool is_static,
			       u32 portid, u32 seq, int type,
			       unsigned int flags)
{
	struct nlmsghdr *nlh;
	struct ndmsg *ndm;

	nlh = nlmsg_put(skb, portid, seq, type, sizeof(*ndm), flags);
	if (!nlh)
		return -EMSGSIZE;

	ndm = nlmsg_data(nlh);
	ndm->ndm_family	 = AF_BRIDGE;
	ndm->ndm_pad1    = 0;
	ndm->ndm_pad2    = 0;
	ndm->ndm_flags	 = NTF_EXT_LEARNED;
	ndm->ndm_type	 = 0;
	ndm->ndm_ifindex = dev->ifindex;
	ndm->ndm_state   = is_static ? NUD_NOARP : NUD_REACHABLE;

	if (nla_put(skb, NDA_LLADDR, ETH_ALEN, addr))
		goto nla_put_failure;

	if (vid && nla_put_u16(skb, NDA_VLAN, vid))
		goto nla_put_failure;

	nlmsg_end(skb, nlh);
	return 0;

nla_put_failure:
	nlmsg_cancel(skb, nlh);
	return -EMSGSIZE;
}
Esempio n. 19
0
static int ip_tun_fill_encap_info(struct sk_buff *skb,
				  struct lwtunnel_state *lwtstate)
{
	struct ip_tunnel_info *tun_info = lwt_tun_info(lwtstate);

	if (nla_put_u64(skb, IP_TUN_ID, tun_info->key.tun_id) ||
	    nla_put_be32(skb, IP_TUN_DST, tun_info->key.ipv4_dst) ||
	    nla_put_be32(skb, IP_TUN_SRC, tun_info->key.ipv4_src) ||
	    nla_put_u8(skb, IP_TUN_TOS, tun_info->key.ipv4_tos) ||
	    nla_put_u8(skb, IP_TUN_TTL, tun_info->key.ipv4_ttl) ||
	    nla_put_u16(skb, IP_TUN_SPORT, tun_info->key.tp_src) ||
	    nla_put_u16(skb, IP_TUN_DPORT, tun_info->key.tp_dst) ||
	    nla_put_u16(skb, IP_TUN_FLAGS, tun_info->key.tun_flags))
		return -ENOMEM;

	return 0;
}
Esempio n. 20
0
static int lisp_get_options(const struct vport *vport,
			      struct sk_buff *skb)
{
	struct lisp_port *lisp_port = lisp_vport(vport);

	if (nla_put_u16(skb, OVS_TUNNEL_ATTR_DST_PORT, lisp_port->port_no))
		return -EMSGSIZE;
	return 0;
}
Esempio n. 21
0
static int vxlan_get_options(const struct vport *vport, struct sk_buff *skb)
{
	struct vxlan_port *vxlan_port = vxlan_vport(vport);
	__be16 dst_port = inet_sk(vxlan_port->vs->sock->sk)->inet_sport;

	if (nla_put_u16(skb, OVS_TUNNEL_ATTR_DST_PORT, ntohs(dst_port)))
		return -EMSGSIZE;
	return 0;
}
Esempio n. 22
0
static int geneve_get_options(const struct vport *vport,
			      struct sk_buff *skb)
{
	struct geneve_port *geneve_port = geneve_vport(vport);

	if (nla_put_u16(skb, OVS_TUNNEL_ATTR_DST_PORT, geneve_port->dst_port))
		return -EMSGSIZE;
	return 0;
}
Esempio n. 23
0
static int stt_tnl_get_options(const struct vport *vport,
			       struct sk_buff *skb)
{
	struct stt_port *stt_port = stt_vport(vport);
	struct inet_sock *sk = inet_sk(stt_port->stt_sock->sock->sk);

	if (nla_put_u16(skb, OVS_TUNNEL_ATTR_DST_PORT, ntohs(sk->inet_sport)))
		return -EMSGSIZE;
	return 0;
}
Esempio n. 24
0
static int ipoib_fill_info(struct sk_buff *skb, const struct net_device *dev)
{
	struct ipoib_dev_priv *priv = netdev_priv(dev);
	u16 val;

	if (nla_put_u16(skb, IFLA_IPOIB_PKEY, priv->pkey))
		goto nla_put_failure;

	val = test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
	if (nla_put_u16(skb, IFLA_IPOIB_MODE, val))
		goto nla_put_failure;

	val = test_bit(IPOIB_FLAG_UMCAST, &priv->flags);
	if (nla_put_u16(skb, IFLA_IPOIB_UMCAST, val))
		goto nla_put_failure;

	return 0;

nla_put_failure:
	return -EMSGSIZE;
}
Esempio n. 25
0
void decoder::send_request(size_t seq)
{
    struct nl_msg *msg;

    msg = nlmsg_alloc();
    genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, m_io->genl_family(),
                0, 0, BATADV_HLP_C_FRAME, 1);

    nla_put_u32(msg, BATADV_HLP_A_IFINDEX, m_io->ifindex());
    nla_put_u8(msg, BATADV_HLP_A_TYPE, REQ_PACKET);
    nla_put(msg, BATADV_HLP_A_SRC, ETH_ALEN, _key.src);
    nla_put(msg, BATADV_HLP_A_DST, ETH_ALEN, _key.dst);
    nla_put_u16(msg, BATADV_HLP_A_BLOCK, _key.block);
    nla_put_u16(msg, BATADV_HLP_A_RANK, this->rank());
    nla_put_u16(msg, BATADV_HLP_A_SEQ, seq);

    m_io->send_msg(msg);
    nlmsg_free(msg);

    inc("request sent");
    VLOG(LOG_CTRL) << "Decoder " << m_coder << ": Sent request packet";
}
Esempio n. 26
0
int main()
{
  struct nl_sock * sk;
  int cbarg;

  // nl_debug = 4;

  // setup netlink socket
  sk = nl_socket_alloc();
  nl_socket_disable_seq_check(sk);	// disable sequence number check
  genl_connect(sk);

  int id = genl_ctrl_resolve(sk, DEMO_FAMILY_NAME);

  struct nl_msg * msg;


  // create a messgae
  msg = nlmsg_alloc();
  genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, id, 0,	// hdrlen
                        0,	// flags
                        DEMO_CMD,	// numeric command identifier
                        DEMO_VERSION	// interface version
                       );

  nla_put_string(msg, DEMO_ATTR1_STRING, "hola");
  nla_put_u16(msg, DEMO_ATTR2_UINT16, 0xf1);

  // send it
  nl_send_auto(sk, msg);

  // handle reply
  struct nl_cb * cb = NULL;
  cb = nl_cb_alloc(NL_CB_CUSTOM);

  //nl_cb_set_all(cb, NL_CB_DEBUG, NULL, NULL);
  nl_cb_set_all(cb, NL_CB_CUSTOM, cb_handler, &cbarg);
  nl_cb_err(cb, NL_CB_DEBUG, NULL, NULL);

  int nrecv = nl_recvmsgs_report(sk, cb);

  printf("cbarg %d nrecv %d\n", cbarg, nrecv);

  // cleanup
  nlmsg_free(msg);
  nl_close(sk);
  nl_socket_free(sk);

  return 0;
}
Esempio n. 27
0
static int ip_tun_fill_encap_info(struct sk_buff *skb,
				  struct lwtunnel_state *lwtstate)
{
	struct ip_tunnel_info *tun_info = lwt_tun_info(lwtstate);

	if (nla_put_u64(skb, LWTUNNEL_IP_ID, tun_info->key.tun_id) ||
	    nla_put_be32(skb, LWTUNNEL_IP_DST, tun_info->key.u.ipv4.dst) ||
	    nla_put_be32(skb, LWTUNNEL_IP_SRC, tun_info->key.u.ipv4.src) ||
	    nla_put_u8(skb, LWTUNNEL_IP_TOS, tun_info->key.tos) ||
	    nla_put_u8(skb, LWTUNNEL_IP_TTL, tun_info->key.ttl) ||
	    nla_put_u16(skb, LWTUNNEL_IP_FLAGS, tun_info->key.tun_flags))
		return -ENOMEM;

	return 0;
}
Esempio n. 28
0
int ieee802154_nl_beacon_indic(struct net_device *dev,
		u16 panid, u16 coord_addr)
{
	struct sk_buff *msg;

	pr_debug("%s\n", __func__);

	msg = ieee802154_nl_create(0, IEEE802154_BEACON_NOTIFY_INDIC);
	if (!msg)
		return -ENOBUFS;

	if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
	    nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
	    nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
		    dev->dev_addr) ||
	    nla_put_u16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, coord_addr) ||
	    nla_put_u16(msg, IEEE802154_ATTR_COORD_PAN_ID, panid))
		goto nla_put_failure;
	return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);

nla_put_failure:
	nlmsg_free(msg);
	return -ENOBUFS;
}
Esempio n. 29
0
static int ip6_tun_fill_encap_info(struct sk_buff *skb,
				   struct lwtunnel_state *lwtstate)
{
	struct ip_tunnel_info *tun_info = lwt_tun_info(lwtstate);

	if (nla_put_u64(skb, LWTUNNEL_IP6_ID, tun_info->key.tun_id) ||
	    nla_put_in6_addr(skb, LWTUNNEL_IP6_DST, &tun_info->key.u.ipv6.dst) ||
	    nla_put_in6_addr(skb, LWTUNNEL_IP6_SRC, &tun_info->key.u.ipv6.src) ||
	    nla_put_u8(skb, LWTUNNEL_IP6_HOPLIMIT, tun_info->key.tos) ||
	    nla_put_u8(skb, LWTUNNEL_IP6_TC, tun_info->key.ttl) ||
	    nla_put_u16(skb, LWTUNNEL_IP6_FLAGS, tun_info->key.tun_flags))
		return -ENOMEM;

	return 0;
}
Esempio n. 30
0
static int br_port_fill_attrs(struct sk_buff *skb,
			      const struct net_bridge_port *p)
{
	u8 mode = !!(p->flags & BR_HAIRPIN_MODE);

	if (nla_put_u8(skb, IFLA_BRPORT_STATE, p->state) ||
	    nla_put_u16(skb, IFLA_BRPORT_PRIORITY, p->priority) ||
	    nla_put_u32(skb, IFLA_BRPORT_COST, p->path_cost) ||
	    nla_put_u8(skb, IFLA_BRPORT_MODE, mode) ||
	    nla_put_u8(skb, IFLA_BRPORT_GUARD, !!(p->flags & BR_BPDU_GUARD)) ||
	    nla_put_u8(skb, IFLA_BRPORT_PROTECT, !!(p->flags & BR_ROOT_BLOCK)) ||
	    nla_put_u8(skb, IFLA_BRPORT_FAST_LEAVE, !!(p->flags & BR_MULTICAST_FAST_LEAVE)))
		return -EMSGSIZE;

	return 0;
}