From 5b82d4b4638b773ab91f54b0162a184438440e81 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Tue, 16 Sep 2003 19:16:59 -0300 Subject: [PATCH] o LLC: split llc into llc_core and llc2 modules For this some more functions had to be moved around, now one doesn't have to explicitely select LLC to have access in the menu to ipx, appletalk, token ring, etc. This is not yet as good as I want it to be, but at least makes it easier for the hordes of users to select stuff, making it look more like how it was in 2.4. In the next changesets I'll fix the fact that CONFIG_TR is a bool and makes psnap, p8022 and llc_core to be built statically even tho the token ring drivers are being build as modules. --- drivers/net/tokenring/Kconfig | 5 +- include/linux/llc.h | 8 ---- include/net/llc_conn.h | 3 ++ include/net/llc_sap.h | 2 - net/Kconfig | 24 ++-------- net/Makefile | 2 +- net/llc/Kconfig | 10 ++++ net/llc/Makefile | 17 ++++--- net/llc/af_llc.c | 35 +++++++++++--- net/llc/llc_conn.c | 33 +++++++++++++- net/llc/llc_if.c | 52 --------------------- net/llc/llc_main.c | 18 +++----- net/llc/llc_sap.c | 86 +++++++++++++++++++++++------------ 13 files changed, 156 insertions(+), 139 deletions(-) create mode 100644 net/llc/Kconfig diff --git a/drivers/net/tokenring/Kconfig b/drivers/net/tokenring/Kconfig index ba05c25bbbfa3..d6a164d1fd4b8 100644 --- a/drivers/net/tokenring/Kconfig +++ b/drivers/net/tokenring/Kconfig @@ -2,13 +2,14 @@ # Token Ring driver configuration # -menu "Token Ring devices (depends on LLC=y)" +menu "Token Ring devices" depends on NETDEVICES # So far, we only have PCI, ISA, and MCA token ring devices config TR bool "Token Ring driver support" - depends on (PCI || ISA || MCA || CCW) && LLC=y + depends on (PCI || ISA || MCA || CCW) + select LLC_CORE help Token Ring is IBM's way of communication on a local network; the rest of the world uses Ethernet. To participate on a Token Ring diff --git a/include/linux/llc.h b/include/linux/llc.h index 77ac5d9df544d..c9085baaf74d8 100644 --- a/include/linux/llc.h +++ b/include/linux/llc.h @@ -79,13 +79,5 @@ enum llc_sockopts { #define LLC_SAP_DYN_TRIES 4 #define llc_ui_skb_cb(__skb) ((struct sockaddr_llc *)&((__skb)->cb[0])) - -#ifdef CONFIG_LLC_UI -extern int llc_ui_init(void); -extern void llc_ui_exit(void); -#else -#define llc_ui_init() -#define llc_ui_exit() -#endif #endif /* __KERNEL__ */ #endif /* __LINUX_LLC_H */ diff --git a/include/net/llc_conn.h b/include/net/llc_conn.h index 4d1e5db3de3c3..e1adbb9215467 100644 --- a/include/net/llc_conn.h +++ b/include/net/llc_conn.h @@ -100,6 +100,9 @@ extern struct sock *llc_lookup_established(struct llc_sap *sap, struct llc_addr *laddr); extern struct sock *llc_lookup_listener(struct llc_sap *sap, struct llc_addr *laddr); +extern void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk); +extern void llc_sap_remove_socket(struct llc_sap *sap, struct sock *sk); + extern u8 llc_data_accept_state(u8 state); extern void llc_build_offset_table(void); extern int llc_release_sockets(struct llc_sap *sap); diff --git a/include/net/llc_sap.h b/include/net/llc_sap.h index fab5e668fb5b8..376ec36288e99 100644 --- a/include/net/llc_sap.h +++ b/include/net/llc_sap.h @@ -40,8 +40,6 @@ struct llc_sap { } sk_list; }; -extern void llc_sap_assign_sock(struct llc_sap *sap, struct sock *sk); -extern void llc_sap_unassign_sock(struct llc_sap *sap, struct sock *sk); extern void llc_sap_state_process(struct llc_sap *sap, struct sk_buff *skb); extern void llc_sap_rtn_pdu(struct llc_sap *sap, struct sk_buff *skb); extern void llc_save_primitive(struct sk_buff* skb, u8 prim); diff --git a/net/Kconfig b/net/Kconfig index 7d76574a9cc32..725cded87d1b0 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -370,24 +370,11 @@ config ATM_BR2684_IPFILTER config VLAN_8021Q tristate "802.1Q VLAN Support" -config LLC - tristate "ANSI/IEEE 802.2 - aka LLC (IPX, Appletalk, Token Ring)" - help - This is a Logical Link Layer protocol used for Appletalk, IPX, - Token Ring devices, the linux-sna.org project and in the future by - NetBEUI. It originally came from Procom Inc. that released the code - for 2.0.36 and was heavily modified to work with 2.{4,5}. - Select this if you want to have support for those protocols or if - you want to have the sockets interface for LLC. - - -config LLC_UI - bool "LLC sockets interface" - depends on LLC +source "net/llc/Kconfig" config IPX tristate "The IPX protocol" - depends on LLC + select LLC_CORE ---help--- This is support for the Novell networking protocol, IPX, commonly used for local networks of Windows machines. You need it if you @@ -424,7 +411,7 @@ source "net/ipx/Kconfig" config ATALK tristate "Appletalk protocol support" - depends on LLC + select LLC_CORE ---help--- AppleTalk is the protocol that Apple computers can use to communicate on a network. If your Linux box is connected to such a network and you @@ -479,9 +466,8 @@ config X25 using the X.21 protocol (not yet supported by Linux) or one can do X.25 over a standard telephone line using an ordinary modem (say Y to "X.25 async driver" below) or over Ethernet using an ordinary - Ethernet card and either the 802.2 LLC protocol (say Y to "802.2 - LLC" below) or LAPB over Ethernet (say Y to "LAPB Data Link Driver" - and "LAPB over Ethernet driver" below). + Ethernet card and the LAPB over Ethernet (say Y to "LAPB Data Link + Driver" and "LAPB over Ethernet driver" below). If you want to compile this driver as a module ( = code which can be inserted in and removed from the running kernel whenever you want), diff --git a/net/Makefile b/net/Makefile index 352f47adc54df..61670a7794699 100644 --- a/net/Makefile +++ b/net/Makefile @@ -12,7 +12,7 @@ obj-$(CONFIG_NET) := socket.o core/ obj-$(CONFIG_COMPAT) += compat.o # LLC has to be linked before the files in net/802/ -obj-$(CONFIG_LLC) += llc/ +obj-$(CONFIG_LLC_CORE) += llc/ obj-$(CONFIG_NET) += ethernet/ 802/ sched/ netlink/ obj-$(CONFIG_INET) += ipv4/ xfrm/ obj-$(CONFIG_UNIX) += unix/ diff --git a/net/llc/Kconfig b/net/llc/Kconfig new file mode 100644 index 0000000000000..5b3d032575ede --- /dev/null +++ b/net/llc/Kconfig @@ -0,0 +1,10 @@ +config LLC_CORE + tristate + depends on NET + +config LLC2 + tristate "ANSI/IEEE 802.2 LLC type 2 Support" + select LLC_CORE + help + This is a Logical Link Layer type 2, connection oriented support. + Select this if you want to have support for PF_LLC sockets. diff --git a/net/llc/Makefile b/net/llc/Makefile index 73a77522723fc..df53f82b2a6a9 100644 --- a/net/llc/Makefile +++ b/net/llc/Makefile @@ -2,7 +2,7 @@ # Makefile for the Linux 802.2 LLC (fully-functional) layer. # # Copyright (c) 1997 by Procom Technology,Inc. -# 2001, 2002 by Arnaldo Carvalho de Melo +# 2001-2003 by Arnaldo Carvalho de Melo # # This program can be redistributed or modified under the terms of the # GNU General Public License as published by the Free Software Foundation. @@ -12,9 +12,14 @@ # See the GNU General Public License for more details. ########################################################################### -obj-$(CONFIG_LLC) += llc.o +obj-$(CONFIG_LLC_CORE) += llc_core.o -llc-y := llc_if.o llc_c_ev.o llc_c_ac.o llc_mac.o llc_sap.o llc_s_st.o \ - llc_main.o llc_s_ac.o llc_conn.o llc_c_st.o llc_stat.o llc_actn.o \ - llc_s_ev.o llc_evnt.o llc_pdu.o llc_proc.o -llc-$(CONFIG_LLC_UI) += af_llc.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 + +obj-$(CONFIG_LLC2) += llc2.o + +llc2-y := llc_if.o llc_c_ev.o llc_c_ac.o llc_conn.o llc_c_st.o llc_pdu.o \ + af_llc.o + +llc2-$(CONFIG_PROC_FS) += llc_proc.o diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c index e7bcc35de9f51..6511964841aa0 100644 --- a/net/llc/af_llc.c +++ b/net/llc/af_llc.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -182,7 +183,7 @@ static int llc_ui_release(struct socket *sock) if (!llc_send_disc(sk)) llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo); if (!sk->sk_zapped) - llc_sap_unassign_sock(llc->sap, sk); + llc_sap_remove_socket(llc->sap, sk); release_sock(sk); if (llc->sap && hlist_empty(&llc->sap->sk_list.list)) { llc_release_sockets(llc->sap); @@ -305,7 +306,7 @@ static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr) memcpy(llc->daddr.mac, addr->sllc_dmac, IFHWADDRLEN); memcpy(&llc->addr, addr, sizeof(llc->addr)); /* assign new connection to its SAP */ - llc_sap_assign_sock(sap, sk); + llc_sap_add_socket(sap, sk); rc = sk->sk_zapped = 0; out: return rc; @@ -1044,14 +1045,36 @@ static struct proto_ops llc_ui_ops = { .sendpage = sock_no_sendpage, }; -int __init llc_ui_init(void) +extern void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb); +extern void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb); + +static int __init llc2_init(void) { + int rc; + + llc_build_offset_table(); llc_ui_sap_last_autoport = LLC_SAP_DYN_START; - sock_register(&llc_ui_family_ops); - return 0; + rc = llc_proc_init(); + if (!rc) { + sock_register(&llc_ui_family_ops); + llc_add_pack(LLC_DEST_SAP, llc_sap_handler); + llc_add_pack(LLC_DEST_CONN, llc_conn_handler); + } + return rc; } -void __exit llc_ui_exit(void) +static void __exit llc2_exit(void) { + llc_remove_pack(LLC_DEST_SAP); + llc_remove_pack(LLC_DEST_CONN); sock_unregister(PF_LLC); + llc_proc_exit(); } + +module_init(llc2_init); +module_exit(llc2_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Procom 1997, Jay Schullist 2001, Arnaldo C. Melo 2001-2003"); +MODULE_DESCRIPTION("IEEE 802.2 PF_LLC support"); +MODULE_ALIAS_NETPROTO(PF_LLC); diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c index ac82b30d69941..4409eb5711beb 100644 --- a/net/llc/llc_conn.c +++ b/net/llc/llc_conn.c @@ -613,6 +613,36 @@ static int llc_find_offset(int state, int ev_type) return rc; } +/** + * llc_sap_add_socket - adds a socket to a SAP + * @sap: SAP + * @sk: socket + * + * This function adds a socket to sk_list of a SAP. + */ +void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk) +{ + write_lock_bh(&sap->sk_list.lock); + llc_sk(sk)->sap = sap; + sk_add_node(sk, &sap->sk_list.list); + write_unlock_bh(&sap->sk_list.lock); +} + +/** + * llc_sap_remove_socket - removes a socket from SAP + * @sap: SAP + * @sk: socket + * + * This function removes a connection from sk_list.list of a SAP if + * the connection was in this list. + */ +void llc_sap_remove_socket(struct llc_sap *sap, struct sock *sk) +{ + write_lock_bh(&sap->sk_list.lock); + sk_del_node_init(sk); + write_unlock_bh(&sap->sk_list.lock); +} + /** * llc_conn_rcv - sends received pdus to the connection state machine * @sk: current connection structure. @@ -664,7 +694,7 @@ void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb) llc = llc_sk(sk); memcpy(&llc->laddr, &daddr, sizeof(llc->laddr)); memcpy(&llc->daddr, &saddr, sizeof(llc->daddr)); - llc_sap_assign_sock(sap, sk); + llc_sap_add_socket(sap, sk); sock_hold(sk); sock_put(parent); skb->sk = parent; @@ -902,4 +932,3 @@ void llc_sk_reset(struct sock *sk) llc->failed_data_req = 0 ; llc->last_nr = 0; } - diff --git a/net/llc/llc_if.c b/net/llc/llc_if.c index cc1533a8a7ddb..1ebc6a20eb992 100644 --- a/net/llc/llc_if.c +++ b/net/llc/llc_if.c @@ -29,58 +29,6 @@ u8 llc_mac_null_var[IFHWADDRLEN]; -/** - * llc_build_and_send_test_pkt - TEST interface for upper layers. - * @sap: sap to use - * @skb: packet to send - * @dmac: destination mac address - * @dsap: destination sap - * - * This function is called when upper layer wants to send a TEST pdu. - * Returns 0 for success, 1 otherwise. - */ -void llc_build_and_send_test_pkt(struct llc_sap *sap, - struct sk_buff *skb, u8 *dmac, u8 dsap) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - ev->saddr.lsap = sap->laddr.lsap; - ev->daddr.lsap = dsap; - memcpy(ev->saddr.mac, skb->dev->dev_addr, IFHWADDRLEN); - memcpy(ev->daddr.mac, dmac, IFHWADDRLEN); - - ev->type = LLC_SAP_EV_TYPE_PRIM; - ev->prim = LLC_TEST_PRIM; - ev->prim_type = LLC_PRIM_TYPE_REQ; - llc_sap_state_process(sap, skb); -} - -/** - * llc_build_and_send_xid_pkt - XID interface for upper layers - * @sap: sap to use - * @skb: packet to send - * @dmac: destination mac address - * @dsap: destination sap - * - * This function is called when upper layer wants to send a XID pdu. - * Returns 0 for success, 1 otherwise. - */ -void llc_build_and_send_xid_pkt(struct llc_sap *sap, struct sk_buff *skb, - u8 *dmac, u8 dsap) -{ - struct llc_sap_state_ev *ev = llc_sap_ev(skb); - - ev->saddr.lsap = sap->laddr.lsap; - ev->daddr.lsap = dsap; - memcpy(ev->saddr.mac, skb->dev->dev_addr, IFHWADDRLEN); - memcpy(ev->daddr.mac, dmac, IFHWADDRLEN); - - ev->type = LLC_SAP_EV_TYPE_PRIM; - ev->prim = LLC_XID_PRIM; - ev->prim_type = LLC_PRIM_TYPE_REQ; - llc_sap_state_process(sap, skb); -} - /** * llc_build_and_send_pkt - Connection data sending for upper layers. * @sk: connection diff --git a/net/llc/llc_main.c b/net/llc/llc_main.c index 736d3ba24b8ce..e81cecb144280 100644 --- a/net/llc/llc_main.c +++ b/net/llc/llc_main.c @@ -300,12 +300,9 @@ static int __init llc_init(void) llc_main_station.ack_timer.data = (unsigned long)&llc_main_station; llc_main_station.ack_timer.function = llc_station_ack_tmr_cb; - if (llc_proc_init()) - goto err; skb = alloc_skb(0, GFP_ATOMIC); if (!skb) - goto err_skb; - llc_build_offset_table(); + goto err; ev = llc_station_ev(skb); memset(ev, 0, sizeof(*ev)); if (dev_base->next) @@ -319,13 +316,10 @@ static int __init llc_init(void) ev->type = LLC_STATION_EV_TYPE_SIMPLE; ev->prim_type = LLC_STATION_EV_ENABLE_WITHOUT_DUP_ADDR_CHECK; rc = llc_station_next_state(&llc_main_station, skb); - llc_ui_init(); dev_add_pack(&llc_packet_type); dev_add_pack(&llc_tr_packet_type); out: return rc; -err_skb: - llc_proc_exit(); err: printk(llc_error_msg); rc = 1; @@ -334,8 +328,6 @@ err: static void __exit llc_exit(void) { - llc_ui_exit(); - llc_proc_exit(); dev_remove_pack(&llc_packet_type); dev_remove_pack(&llc_tr_packet_type); } @@ -343,7 +335,11 @@ static void __exit llc_exit(void) module_init(llc_init); module_exit(llc_exit); +EXPORT_SYMBOL(llc_sap_find); +EXPORT_SYMBOL(llc_alloc_frame); +EXPORT_SYMBOL(llc_main_station); + MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Procom, 1997, Arnaldo C. Melo, Jay Schullist, 2001-2003"); -MODULE_DESCRIPTION("LLC 2.0, IEEE 802.2 extended support"); +MODULE_AUTHOR("Procom 1997, Jay Schullist 2001, Arnaldo C. Melo 2001-2003"); +MODULE_DESCRIPTION("LLC IEEE 802.2 extended support"); MODULE_ALIAS_NETPROTO(PF_LLC); diff --git a/net/llc/llc_sap.c b/net/llc/llc_sap.c index 4eaca37f8546c..b817e72c0cfee 100644 --- a/net/llc/llc_sap.c +++ b/net/llc/llc_sap.c @@ -39,36 +39,6 @@ void llc_save_primitive(struct sk_buff* skb, u8 prim) llc_pdu_decode_ssap(skb, &addr->sllc_ssap); } -/** - * llc_sap_assign_sock - adds a connection to a SAP - * @sap: pointer to SAP. - * @conn: pointer to connection. - * - * This function adds a connection to connection_list of a SAP. - */ -void llc_sap_assign_sock(struct llc_sap *sap, struct sock *sk) -{ - write_lock_bh(&sap->sk_list.lock); - llc_sk(sk)->sap = sap; - sk_add_node(sk, &sap->sk_list.list); - write_unlock_bh(&sap->sk_list.lock); -} - -/** - * llc_sap_unassign_sock - removes a connection from SAP - * @sap: SAP - * @sk: pointer to connection - * - * This function removes a connection from sk_list.list of a SAP if - * the connection was in this list. - */ -void llc_sap_unassign_sock(struct llc_sap *sap, struct sock *sk) -{ - write_lock_bh(&sap->sk_list.lock); - sk_del_node_init(sk); - write_unlock_bh(&sap->sk_list.lock); -} - /** * llc_sap_rtn_pdu - Informs upper layer on rx of an UI, XID or TEST pdu. * @sap: pointer to SAP @@ -240,6 +210,58 @@ void llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb, llc_sap_state_process(sap, skb); } +/** + * llc_build_and_send_test_pkt - TEST interface for upper layers. + * @sap: sap to use + * @skb: packet to send + * @dmac: destination mac address + * @dsap: destination sap + * + * This function is called when upper layer wants to send a TEST pdu. + * Returns 0 for success, 1 otherwise. + */ +void llc_build_and_send_test_pkt(struct llc_sap *sap, + struct sk_buff *skb, u8 *dmac, u8 dsap) +{ + struct llc_sap_state_ev *ev = llc_sap_ev(skb); + + ev->saddr.lsap = sap->laddr.lsap; + ev->daddr.lsap = dsap; + memcpy(ev->saddr.mac, skb->dev->dev_addr, IFHWADDRLEN); + memcpy(ev->daddr.mac, dmac, IFHWADDRLEN); + + ev->type = LLC_SAP_EV_TYPE_PRIM; + ev->prim = LLC_TEST_PRIM; + ev->prim_type = LLC_PRIM_TYPE_REQ; + llc_sap_state_process(sap, skb); +} + +/** + * llc_build_and_send_xid_pkt - XID interface for upper layers + * @sap: sap to use + * @skb: packet to send + * @dmac: destination mac address + * @dsap: destination sap + * + * This function is called when upper layer wants to send a XID pdu. + * Returns 0 for success, 1 otherwise. + */ +void llc_build_and_send_xid_pkt(struct llc_sap *sap, struct sk_buff *skb, + u8 *dmac, u8 dsap) +{ + struct llc_sap_state_ev *ev = llc_sap_ev(skb); + + ev->saddr.lsap = sap->laddr.lsap; + ev->daddr.lsap = dsap; + memcpy(ev->saddr.mac, skb->dev->dev_addr, IFHWADDRLEN); + memcpy(ev->daddr.mac, dmac, IFHWADDRLEN); + + ev->type = LLC_SAP_EV_TYPE_PRIM; + ev->prim = LLC_XID_PRIM; + ev->prim_type = LLC_PRIM_TYPE_REQ; + llc_sap_state_process(sap, skb); +} + /** * llc_sap_rcv - sends received pdus to the sap state machine * @sap: current sap component structure. @@ -376,4 +398,8 @@ void llc_sap_close(struct llc_sap *sap) EXPORT_SYMBOL(llc_sap_open); EXPORT_SYMBOL(llc_sap_close); +EXPORT_SYMBOL(llc_save_primitive); +EXPORT_SYMBOL(llc_build_and_send_test_pkt); EXPORT_SYMBOL(llc_build_and_send_ui_pkt); +EXPORT_SYMBOL(llc_build_and_send_xid_pkt); +EXPORT_SYMBOL(llc_sap_handler); -- 2.53.0