o LLC: create llc_output and move lan_hdrs_init to it

Renaming lan_hdrs_init to llc_mac_hdr_init and making all places
check if it fails.
parent eced82e7
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
extern int llc_rcv(struct sk_buff *skb, struct net_device *dev, extern int llc_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt); struct packet_type *pt);
extern u16 lan_hdrs_init(struct sk_buff *skb, u8 *sa, u8 *da);
struct llc_sap; struct llc_sap;
struct sk_buff; struct sk_buff;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
obj-$(CONFIG_LLC_CORE) += llc_core.o obj-$(CONFIG_LLC_CORE) += llc_core.o
llc_core-y := llc_mac.o llc_sap.o llc_s_st.o llc_s_ac.o llc_s_ev.o llc_main.o \ llc_core-y := llc_mac.o llc_sap.o llc_s_st.o llc_s_ac.o llc_s_ev.o llc_main.o \
llc_actn.o llc_stat.o llc_evnt.o llc_actn.o llc_stat.o llc_evnt.o llc_output.o
obj-$(CONFIG_LLC2) += llc2.o obj-$(CONFIG_LLC2) += llc2.o
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <net/llc_evnt.h> #include <net/llc_evnt.h>
#include <net/llc_pdu.h> #include <net/llc_pdu.h>
#include <net/llc_mac.h> #include <net/llc_mac.h>
#include "llc_output.h"
int llc_station_ac_start_ack_timer(struct llc_station *station, int llc_station_ac_start_ack_timer(struct llc_station *station,
struct sk_buff *skb) struct sk_buff *skb)
...@@ -67,13 +68,17 @@ int llc_station_ac_send_null_dsap_xid_c(struct llc_station *station, ...@@ -67,13 +68,17 @@ int llc_station_ac_send_null_dsap_xid_c(struct llc_station *station,
if (!nskb) if (!nskb)
goto out; goto out;
rc = 0;
llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, 0, LLC_PDU_CMD); llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, 0, LLC_PDU_CMD);
llc_pdu_init_as_xid_cmd(nskb, LLC_XID_NULL_CLASS_2, 127); llc_pdu_init_as_xid_cmd(nskb, LLC_XID_NULL_CLASS_2, 127);
lan_hdrs_init(nskb, station->mac_sa, station->mac_sa); rc = llc_mac_hdr_init(nskb, station->mac_sa, station->mac_sa);
if (rc)
goto free;
llc_station_send_pdu(station, nskb); llc_station_send_pdu(station, nskb);
out: out:
return rc; return rc;
free:
kfree_skb(skb);
goto out;
} }
int llc_station_ac_send_xid_r(struct llc_station *station, int llc_station_ac_send_xid_r(struct llc_station *station,
...@@ -91,10 +96,15 @@ int llc_station_ac_send_xid_r(struct llc_station *station, ...@@ -91,10 +96,15 @@ int llc_station_ac_send_xid_r(struct llc_station *station,
llc_pdu_decode_ssap(skb, &dsap); llc_pdu_decode_ssap(skb, &dsap);
llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP); llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP);
llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 127); llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 127);
lan_hdrs_init(nskb, station->mac_sa, mac_da); rc = llc_mac_hdr_init(nskb, station->mac_sa, mac_da);
if (rc)
goto free;
llc_station_send_pdu(station, nskb); llc_station_send_pdu(station, nskb);
out: out:
return rc; return rc;
free:
kfree_skb(skb);
goto out;
} }
int llc_station_ac_send_test_r(struct llc_station *station, int llc_station_ac_send_test_r(struct llc_station *station,
...@@ -112,10 +122,15 @@ int llc_station_ac_send_test_r(struct llc_station *station, ...@@ -112,10 +122,15 @@ int llc_station_ac_send_test_r(struct llc_station *station,
llc_pdu_decode_ssap(skb, &dsap); llc_pdu_decode_ssap(skb, &dsap);
llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP); llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP);
llc_pdu_init_as_test_rsp(nskb, skb); llc_pdu_init_as_test_rsp(nskb, skb);
lan_hdrs_init(nskb, station->mac_sa, mac_da); rc = llc_mac_hdr_init(nskb, station->mac_sa, mac_da);
if (rc)
goto free;
llc_station_send_pdu(station, nskb); llc_station_send_pdu(station, nskb);
out: out:
return rc; return rc;
free:
kfree_skb(skb);
goto out;
} }
int llc_station_ac_report_status(struct llc_station *station, int llc_station_ac_report_status(struct llc_station *station,
......
This diff is collapsed.
...@@ -192,60 +192,5 @@ static void llc_station_rcv(struct sk_buff *skb) ...@@ -192,60 +192,5 @@ static void llc_station_rcv(struct sk_buff *skb)
llc_station_state_process(&llc_main_station, skb); llc_station_state_process(&llc_main_station, skb);
} }
/**
* lan_hdrs_init - fills MAC header fields
* @skb: Address of the frame to initialize its MAC header
* @sa: The MAC source address
* @da: The MAC destination address
*
* Fills MAC header fields, depending on MAC type. Returns 0, If MAC type
* is a valid type and initialization completes correctly 1, otherwise.
*/
u16 lan_hdrs_init(struct sk_buff *skb, u8 *sa, u8 *da)
{
u16 rc = 0;
switch (skb->dev->type) {
#ifdef CONFIG_TR
case ARPHRD_IEEE802_TR: {
struct trh_hdr *trh;
struct net_device *dev = skb->dev;
trh = (struct trh_hdr *)skb_push(skb, sizeof(*trh));
trh->ac = AC;
trh->fc = LLC_FRAME;
if (sa)
memcpy(trh->saddr, sa, dev->addr_len);
else
memset(trh->saddr, 0, dev->addr_len);
if (da) {
memcpy(trh->daddr, da, dev->addr_len);
tr_source_route(skb, trh, dev);
}
skb->mac.raw = skb->data;
break;
}
#endif
case ARPHRD_ETHER:
case ARPHRD_LOOPBACK: {
unsigned short len = skb->len;
struct ethhdr *eth;
skb->mac.raw = skb_push(skb, sizeof(*eth));
eth = (struct ethhdr *)skb->mac.raw;
eth->h_proto = htons(len);
memcpy(eth->h_dest, da, ETH_ALEN);
memcpy(eth->h_source, sa, ETH_ALEN);
break;
}
default:
printk(KERN_WARNING "Unknown DEVICE type : %d\n",
skb->dev->type);
rc = 1;
}
return rc;
}
EXPORT_SYMBOL(llc_add_pack); EXPORT_SYMBOL(llc_add_pack);
EXPORT_SYMBOL(llc_remove_pack); EXPORT_SYMBOL(llc_remove_pack);
EXPORT_SYMBOL(lan_hdrs_init);
/*
* llc_output.c - LLC output path
*
* Copyright (c) 1997 by Procom Technology, Inc.
* 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
*
* This program can be redistributed or modified under the terms of the
* GNU General Public License version 2 as published by the Free Software
* Foundation.
* This program is distributed without any warranty or implied warranty
* of merchantability or fitness for a particular purpose.
*
* See the GNU General Public License version 2 for more details.
*/
#include <linux/if_arp.h>
#include <linux/if_tr.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
/**
* llc_mac_hdr_init - fills MAC header fields
* @skb: Address of the frame to initialize its MAC header
* @sa: The MAC source address
* @da: The MAC destination address
*
* Fills MAC header fields, depending on MAC type. Returns 0, If MAC type
* is a valid type and initialization completes correctly 1, otherwise.
*/
int llc_mac_hdr_init(struct sk_buff *skb, unsigned char *sa, unsigned char *da)
{
int rc = 0;
switch (skb->dev->type) {
#ifdef CONFIG_TR
case ARPHRD_IEEE802_TR: {
struct net_device *dev = skb->dev;
struct trh_hdr *trh;
trh = (struct trh_hdr *)skb_push(skb, sizeof(*trh));
trh->ac = AC;
trh->fc = LLC_FRAME;
if (sa)
memcpy(trh->saddr, sa, dev->addr_len);
else
memset(trh->saddr, 0, dev->addr_len);
if (da) {
memcpy(trh->daddr, da, dev->addr_len);
tr_source_route(skb, trh, dev);
}
skb->mac.raw = skb->data;
break;
}
#endif
case ARPHRD_ETHER:
case ARPHRD_LOOPBACK: {
unsigned short len = skb->len;
struct ethhdr *eth;
skb->mac.raw = skb_push(skb, sizeof(*eth));
eth = (struct ethhdr *)skb->mac.raw;
eth->h_proto = htons(len);
memcpy(eth->h_dest, da, ETH_ALEN);
memcpy(eth->h_source, sa, ETH_ALEN);
break;
}
default:
printk(KERN_WARNING "device type not supported: %d\n",
skb->dev->type);
rc = -EINVAL;
}
return rc;
}
EXPORT_SYMBOL(llc_mac_hdr_init);
#ifndef LLC_OUTPUT_H
#define LLC_OUTPUT_H
/*
* Copyright (c) 1997 by Procom Technology, Inc.
* 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
*
* This program can be redistributed or modified under the terms of the
* GNU General Public License version 2 as published by the Free Software
* Foundation.
* This program is distributed without any warranty or implied warranty
* of merchantability or fitness for a particular purpose.
*
* See the GNU General Public License version 2 for more details.
*/
struct sk_buff;
int llc_mac_hdr_init(struct sk_buff *skb, unsigned char *sa, unsigned char *da);
#endif /* LLC_OUTPUT_H */
...@@ -56,7 +56,7 @@ int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb) ...@@ -56,7 +56,7 @@ int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb)
llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap, llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
ev->daddr.lsap, LLC_PDU_CMD); ev->daddr.lsap, LLC_PDU_CMD);
llc_pdu_init_as_ui_cmd(skb); llc_pdu_init_as_ui_cmd(skb);
rc = lan_hdrs_init(skb, ev->saddr.mac, ev->daddr.mac); rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
if (!rc) if (!rc)
rc = dev_queue_xmit(skb); rc = dev_queue_xmit(skb);
return rc; return rc;
...@@ -79,7 +79,7 @@ int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb) ...@@ -79,7 +79,7 @@ int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb)
llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap, llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
ev->daddr.lsap, LLC_PDU_CMD); ev->daddr.lsap, LLC_PDU_CMD);
llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0); llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0);
rc = lan_hdrs_init(skb, ev->saddr.mac, ev->daddr.mac); rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
if (!rc) if (!rc)
rc = dev_queue_xmit(skb); rc = dev_queue_xmit(skb);
return rc; return rc;
...@@ -109,7 +109,7 @@ int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb) ...@@ -109,7 +109,7 @@ int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb)
llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap, llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
LLC_PDU_RSP); LLC_PDU_RSP);
llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 0); llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 0);
rc = lan_hdrs_init(nskb, mac_sa, mac_da); rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
if (!rc) if (!rc)
rc = dev_queue_xmit(nskb); rc = dev_queue_xmit(nskb);
out: out:
...@@ -133,7 +133,7 @@ int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb) ...@@ -133,7 +133,7 @@ int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb)
llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap, llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
ev->daddr.lsap, LLC_PDU_CMD); ev->daddr.lsap, LLC_PDU_CMD);
llc_pdu_init_as_test_cmd(skb); llc_pdu_init_as_test_cmd(skb);
rc = lan_hdrs_init(skb, ev->saddr.mac, ev->daddr.mac); rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
if (!rc) if (!rc)
rc = dev_queue_xmit(skb); rc = dev_queue_xmit(skb);
return rc; return rc;
...@@ -155,7 +155,7 @@ int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb) ...@@ -155,7 +155,7 @@ int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb)
llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap, llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
LLC_PDU_RSP); LLC_PDU_RSP);
llc_pdu_init_as_test_rsp(nskb, skb); llc_pdu_init_as_test_rsp(nskb, skb);
rc = lan_hdrs_init(nskb, mac_sa, mac_da); rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
if (!rc) if (!rc)
rc = dev_queue_xmit(nskb); rc = dev_queue_xmit(nskb);
out: out:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment