public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Eldad Zack <eldad@fogrefinery.com>
To: netdev@vger.kernel.org
Cc: Eldad Zack <eldad@fogrefinery.com>
Subject: [PATCH 5/8] LLDP: Output routines
Date: Mon, 25 Jun 2012 20:28:17 +0200	[thread overview]
Message-ID: <1340648900-6547-6-git-send-email-eldad@fogrefinery.com> (raw)
In-Reply-To: <1340648900-6547-1-git-send-email-eldad@fogrefinery.com>

Handles the transmission of LLDPDUs.

Gets the TLV list, allocates the sk_buff according to the
space requirements of the TLV list, writes it to the sk_buff and
if all goes well, sends it to the wire.

Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
 net/lldp/lldp_output.c |   67 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 net/lldp/lldp_output.c

diff --git a/net/lldp/lldp_output.c b/net/lldp/lldp_output.c
new file mode 100644
index 0000000..45e6293
--- /dev/null
+++ b/net/lldp/lldp_output.c
@@ -0,0 +1,67 @@
+/* LLDP		Link Layer Discovery Protocol impementation for Linux
+ *		IEEE Std 802.1ab
+ *
+ * Author:	Eldad Zack <eldad@fogrefinery.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/if_ether.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include "lldp.h"
+
+static u8 lldp_dst_address[] = LLDP_MULTICAST_ADDR;
+
+inline struct sk_buff *lldp_create(struct net_device *dev, bool is_shutdown)
+{
+	struct sk_buff *skb;
+	struct list_head head;
+	int head_len = LL_RESERVED_SPACE(dev);
+	int tail_len = dev->needed_tailroom;
+	int lldp_len;
+
+	INIT_LIST_HEAD(&head);
+
+	lldp_tlv_construct_list(&head, dev, is_shutdown);
+	lldp_len = lldp_tlv_list_len(&head);
+
+	skb = alloc_skb(head_len + lldp_len + tail_len, GFP_ATOMIC);
+	if (skb == NULL)
+		goto done;
+
+	skb_reserve(skb, head_len);
+	skb_reset_network_header(skb);
+
+	lldp_tlv_put_skb_list(skb, &head);
+
+	skb->dev = dev;
+	skb->protocol = htons(ETH_P_LLDP);
+
+	if (dev_hard_header(skb, dev, ETH_P_LLDP, lldp_dst_address,
+		dev->dev_addr, skb->len) < 0) {
+		kfree_skb(skb);
+		skb = NULL;
+	}
+
+done:
+	lldp_tlv_destruct_list(&head);
+	return skb;
+}
+
+void __lldp_send(struct net_device *dev, bool is_shutdown)
+{
+	struct sk_buff *skb;
+
+	skb = lldp_create(dev, is_shutdown);
+
+	if (skb == NULL)
+		return;
+
+	dev_queue_xmit(skb);
+}
-- 
1.7.10

  parent reply	other threads:[~2012-06-25 18:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-25 18:28 [PATCH RFC 0/8] LLDP implementation for Linux Eldad Zack
2012-06-25 18:28 ` [PATCH 1/8] if_ether.h: Add LLDP ethertype Eldad Zack
2012-06-25 18:48   ` Eldad Zack
2012-06-25 18:28 ` [PATCH 2/8] LLDP: Header Eldad Zack
2012-06-25 18:28 ` [PATCH 3/8] LLDP: Sysctl interface Eldad Zack
2012-06-25 18:28 ` [PATCH 4/8] LLDP: PDU-handling routines Eldad Zack
2012-06-25 18:28 ` Eldad Zack [this message]
2012-06-25 18:28 ` [PATCH 6/8] LLDP: Core routines Eldad Zack
2012-06-25 18:28 ` [PATCH 7/8] LLDP: Kconfig and Makefile Eldad Zack
2012-06-25 18:28 ` [PATCH 8/8] 8021q/vlan: process NETDEV_GOING_DOWN Eldad Zack
2012-06-25 18:33 ` [PATCH RFC 0/8] LLDP implementation for Linux Eldad Zack
2012-06-25 18:54 ` Stephen Hemminger
2012-06-25 20:05   ` Eldad Zack
2012-06-25 19:00 ` John Fastabend
2012-06-25 20:21   ` Eldad Zack

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1340648900-6547-6-git-send-email-eldad@fogrefinery.com \
    --to=eldad@fogrefinery.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox