net/ieee802154/6lowpan/tx.c

Source file repositories/reference/linux-study-clean/net/ieee802154/6lowpan/tx.c

File Facts

System
Linux kernel
Corpus path
net/ieee802154/6lowpan/tx.c
Extension
.c
Size
8448 bytes
Lines
315
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: implementation source
Status
source implementation candidate

Why This File Exists

Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.

Dependency Surface

Detected Declarations

Annotated Snippet

struct lowpan_addr_info {
	struct ieee802154_addr daddr;
	struct ieee802154_addr saddr;
};

static inline struct
lowpan_addr_info *lowpan_skb_priv(const struct sk_buff *skb)
{
	WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct lowpan_addr_info));
	return (struct lowpan_addr_info *)(skb->data -
			sizeof(struct lowpan_addr_info));
}

/* This callback will be called from AF_PACKET and IPv6 stack, the AF_PACKET
 * sockets gives an 8 byte array for addresses only!
 *
 * TODO I think AF_PACKET DGRAM (sending/receiving) RAW (sending) makes no
 * sense here. We should disable it, the right use-case would be AF_INET6
 * RAW/DGRAM sockets.
 */
int lowpan_header_create(struct sk_buff *skb, struct net_device *ldev,
			 unsigned short type, const void *daddr,
			 const void *saddr, unsigned int len)
{
	struct wpan_dev *wpan_dev = lowpan_802154_dev(ldev)->wdev->ieee802154_ptr;
	struct lowpan_addr_info *info = lowpan_skb_priv(skb);
	struct lowpan_802154_neigh *llneigh = NULL;
	const struct ipv6hdr *hdr = ipv6_hdr(skb);
	struct neighbour *n;

	if (!daddr)
		return -EINVAL;

	/* TODO:
	 * if this package isn't ipv6 one, where should it be routed?
	 */
	if (type != ETH_P_IPV6)
		return 0;

	/* intra-pan communication */
	info->saddr.pan_id = wpan_dev->pan_id;
	info->daddr.pan_id = info->saddr.pan_id;

	if (!memcmp(daddr, ldev->broadcast, EUI64_ADDR_LEN)) {
		info->daddr.short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
		info->daddr.mode = IEEE802154_ADDR_SHORT;
	} else {
		__le16 short_addr = cpu_to_le16(IEEE802154_ADDR_SHORT_UNSPEC);

		n = neigh_lookup(&nd_tbl, &hdr->daddr, ldev);
		if (n) {
			llneigh = lowpan_802154_neigh(neighbour_priv(n));
			read_lock_bh(&n->lock);
			short_addr = llneigh->short_addr;
			read_unlock_bh(&n->lock);
		}

		if (llneigh &&
		    lowpan_802154_is_valid_src_short_addr(short_addr)) {
			info->daddr.short_addr = short_addr;
			info->daddr.mode = IEEE802154_ADDR_SHORT;
		} else {
			info->daddr.mode = IEEE802154_ADDR_LONG;
			ieee802154_be64_to_le64(&info->daddr.extended_addr,
						daddr);
		}

		if (n)
			neigh_release(n);
	}

	if (!saddr) {
		if (lowpan_802154_is_valid_src_short_addr(wpan_dev->short_addr)) {
			info->saddr.mode = IEEE802154_ADDR_SHORT;
			info->saddr.short_addr = wpan_dev->short_addr;
		} else {
			info->saddr.mode = IEEE802154_ADDR_LONG;
			info->saddr.extended_addr = wpan_dev->extended_addr;
		}
	} else {
		info->saddr.mode = IEEE802154_ADDR_LONG;
		ieee802154_be64_to_le64(&info->saddr.extended_addr, saddr);
	}

	return 0;
}

static struct sk_buff*
lowpan_alloc_frag(struct sk_buff *skb, int size,
		  const struct ieee802154_hdr *master_hdr, bool frag1)

Annotation

Implementation Notes