From 41f05b86075aaec56018e9b6ffe277e48d560f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 2 Aug 2010 14:45:44 +0000 Subject: [PATCH] * Made datalink and interface protocol module functions static. * Got rid of datalink.h. * Only allow sending/receiving of packets through AF_LINK for root (not that sending would be implemented yet). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37844 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/network/stack/datalink.cpp | 41 +++++++++---------- src/add-ons/kernel/network/stack/datalink.h | 19 --------- src/add-ons/kernel/network/stack/link.cpp | 40 ++++++++++-------- 3 files changed, 44 insertions(+), 56 deletions(-) delete mode 100644 src/add-ons/kernel/network/stack/datalink.h diff --git a/src/add-ons/kernel/network/stack/datalink.cpp b/src/add-ons/kernel/network/stack/datalink.cpp index 8e7c2b2b3e..71f39489b3 100644 --- a/src/add-ons/kernel/network/stack/datalink.cpp +++ b/src/add-ons/kernel/network/stack/datalink.cpp @@ -8,8 +8,6 @@ */ -#include "datalink.h" - #include #include #include @@ -21,6 +19,7 @@ #include +#include #include #include @@ -183,7 +182,7 @@ fill_address(const sockaddr* from, sockaddr* to, size_t maxLength) // #pragma mark - datalink module -status_t +static status_t datalink_control(net_domain* _domain, int32 option, void* value, size_t* _length) { @@ -330,7 +329,7 @@ datalink_control(net_domain* _domain, int32 option, void* value, } -status_t +static status_t datalink_send_data(struct net_route* route, net_buffer* buffer) { TRACE("%s(route %p, buffer %p)\n", __FUNCTION__, route, buffer); @@ -375,7 +374,7 @@ datalink_send_data(struct net_route* route, net_buffer* buffer) } -status_t +static status_t datalink_send_datagram(net_protocol* protocol, net_domain* domain, net_buffer* buffer) { @@ -417,7 +416,7 @@ datalink_send_datagram(net_protocol* protocol, net_domain* domain, if non-NULL. \param _matchedType will be set to either zero or MSG_BCAST if non-NULL. */ -bool +static bool datalink_is_local_address(net_domain* domain, const struct sockaddr* address, net_interface_address** _interfaceAddress, uint32* _matchedType) { @@ -465,7 +464,7 @@ datalink_is_local_address(net_domain* domain, const struct sockaddr* address, \param _interfaceAddress will be set to the first address of the interface and domain belonging to that address if non-NULL. */ -bool +static bool datalink_is_local_link_address(net_domain* domain, bool unconfiguredOnly, const struct sockaddr* address, net_interface_address** _interfaceAddress) { @@ -486,14 +485,14 @@ datalink_is_local_link_address(net_domain* domain, bool unconfiguredOnly, } -net_interface* +static net_interface* datalink_get_interface(net_domain* domain, uint32 index) { return get_interface(domain, index); } -net_interface* +static net_interface* datalink_get_interface_with_address(const sockaddr* address) { InterfaceAddress* interfaceAddress = get_interface_address(address); @@ -519,7 +518,7 @@ datalink_put_interface(net_interface* interface) } -net_interface_address* +static net_interface_address* datalink_get_interface_address(const struct sockaddr* address) { return get_interface_address(address); @@ -540,7 +539,7 @@ datalink_get_interface_address(const struct sockaddr* address) \return \c true if an address reference was returned, \c false if not. */ -bool +static bool datalink_get_next_interface_address(net_interface* _interface, net_interface_address** _address) { @@ -554,7 +553,7 @@ datalink_get_next_interface_address(net_interface* _interface, } -void +static void datalink_put_interface_address(net_interface_address* address) { if (address == NULL) @@ -564,7 +563,7 @@ datalink_put_interface_address(net_interface_address* address) } -status_t +static status_t datalink_join_multicast(net_interface* _interface, net_domain* domain, const struct sockaddr* address) { @@ -576,7 +575,7 @@ datalink_join_multicast(net_interface* _interface, net_domain* domain, } -status_t +static status_t datalink_leave_multicast(net_interface* _interface, net_domain* domain, const struct sockaddr* address) { @@ -605,7 +604,7 @@ datalink_std_ops(int32 op, ...) // #pragma mark - net_datalink_protocol -status_t +static status_t interface_protocol_init(net_interface* interface, net_domain* domain, net_datalink_protocol** _protocol) { @@ -624,7 +623,7 @@ interface_protocol_init(net_interface* interface, net_domain* domain, } -status_t +static status_t interface_protocol_uninit(net_datalink_protocol* protocol) { TRACE("%s(%p)\n", __FUNCTION__, protocol); @@ -634,7 +633,7 @@ interface_protocol_uninit(net_datalink_protocol* protocol) } -status_t +static status_t interface_protocol_send_data(net_datalink_protocol* _protocol, net_buffer* buffer) { @@ -660,7 +659,7 @@ interface_protocol_send_data(net_datalink_protocol* _protocol, } -status_t +static status_t interface_protocol_up(net_datalink_protocol* protocol) { TRACE("%s(%p)\n", __FUNCTION__, protocol); @@ -668,7 +667,7 @@ interface_protocol_up(net_datalink_protocol* protocol) } -void +static void interface_protocol_down(net_datalink_protocol* _protocol) { TRACE("%s(%p)\n", __FUNCTION__, _protocol); @@ -691,7 +690,7 @@ interface_protocol_down(net_datalink_protocol* _protocol) } -status_t +static status_t interface_protocol_change_address(net_datalink_protocol* protocol, net_interface_address* interfaceAddress, int32 option, const struct sockaddr* oldAddress, const struct sockaddr* newAddress) @@ -714,7 +713,7 @@ interface_protocol_change_address(net_datalink_protocol* protocol, } -status_t +static status_t interface_protocol_control(net_datalink_protocol* _protocol, int32 option, void* argument, size_t length) { diff --git a/src/add-ons/kernel/network/stack/datalink.h b/src/add-ons/kernel/network/stack/datalink.h deleted file mode 100644 index 0c330abdc2..0000000000 --- a/src/add-ons/kernel/network/stack/datalink.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2006, Haiku, Inc. All Rights Reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Axel Dörfler, axeld@pinc-software.de - */ -#ifndef DATALINK_H -#define DATALINK_H - - -#include - - -status_t datalink_control(struct net_domain *domain, int32 option, - void *value, size_t *_length); -status_t datalink_send_data(struct net_route *route, net_buffer *buffer); - -#endif // DATALINK_H diff --git a/src/add-ons/kernel/network/stack/link.cpp b/src/add-ons/kernel/network/stack/link.cpp index ee7ebd8113..f93a7f1b07 100644 --- a/src/add-ons/kernel/network/stack/link.cpp +++ b/src/add-ons/kernel/network/stack/link.cpp @@ -10,20 +10,7 @@ //! The net_protocol one talks to when using the AF_LINK protocol -#include "datalink.h" -#include "device_interfaces.h" -#include "domains.h" #include "link.h" -#include "stack_private.h" -#include "utility.h" - -#include - -#include -#include - -#include -#include #include #include @@ -31,6 +18,19 @@ #include #include +#include + +#include +#include +#include +#include +#include + +#include "device_interfaces.h" +#include "domains.h" +#include "stack_private.h" +#include "utility.h" + class LocalStackBundle { public: @@ -346,6 +346,10 @@ link_control(net_protocol* _protocol, int level, int option, void* value, case SIOCSPACKETCAP: { + // Only root is allowed to capture packets + if (geteuid() != 0) + return B_NOT_ALLOWED; + struct ifreq request; if (user_memcpy(&request, value, IF_NAMESIZE) < B_OK) return B_BAD_ADDRESS; @@ -357,7 +361,7 @@ link_control(net_protocol* _protocol, int level, int option, void* value, return protocol->StopMonitoring(); } - return datalink_control(sDomain, option, value, _length); + return gNetDatalinkModule.control(sDomain, option, value, _length); } @@ -421,7 +425,11 @@ link_shutdown(net_protocol* protocol, int direction) status_t link_send_data(net_protocol* protocol, net_buffer* buffer) { - return B_NOT_ALLOWED; + // Only root is allowed to send link protocol packets + if (geteuid() != 0) + return B_NOT_ALLOWED; + + return B_NOT_SUPPORTED; } @@ -429,7 +437,7 @@ status_t link_send_routed_data(net_protocol* protocol, struct net_route* route, net_buffer* buffer) { - return B_NOT_ALLOWED; + return B_NOT_SUPPORTED; }