hal/hald/linux2 classdev.c,1.10,1.11 osspec.c,1.8,1.9
David Zeuthen
david at freedesktop.org
Tue Feb 8 13:17:40 PST 2005
Update of /cvs/hal/hal/hald/linux2
In directory gabe:/tmp/cvs-serv12449/hald/linux2
Modified Files:
classdev.c osspec.c
Log Message:
2005-02-08 David Zeuthen <davidz at redhat.com>
* hald/linux2/osspec.c: Do not care about link detection, NM and other
tools are going to do this on their own now.
(link_detection_handle_message): Remove
(netlink_socket_data): Remove
(osspec_init): Don't listen to the netlink socket
* hald/linux2/classdev.c (net_add): Do not care about link detection
Index: classdev.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/classdev.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- classdev.c 8 Feb 2005 20:11:05 -0000 1.10
+++ classdev.c 8 Feb 2005 21:17:38 -0000 1.11
@@ -253,21 +253,8 @@
hal_device_property_set_string (d, "info.category", "net.80211");
hal_device_add_capability (d, "net.80211");
} else {
- gint have_link;
-
hal_device_property_set_string (d, "info.category", "net.80203");
hal_device_add_capability (d, "net.80203");
-
- if (hal_util_get_int_from_file (sysfs_path, "carrier", &have_link, 10)) {
- hal_device_property_set_bool (d, "net.80203.can_detect_link", TRUE);
- hal_device_property_set_bool (d, "net.80203.link", have_link != 0);
- if (have_link != 0) {
- HAL_INFO (("FIXME: no speed file in sysfs; assuming link speed is 100Mbps"));
- hal_device_property_set_uint64 (d, "net.80203.rate", 100 * 1000 * 1000);
- }
- } else {
- hal_device_property_set_bool (d, "net.80203.can_detect_link", FALSE);
- }
}
addr = hal_device_property_get_string (d, "net.address");
Index: osspec.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/osspec.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- osspec.c 8 Feb 2005 16:44:20 -0000 1.8
+++ osspec.c 8 Feb 2005 21:17:38 -0000 1.9
@@ -85,202 +85,8 @@
char hal_sysfs_path [HAL_PATH_MAX];
char hal_proc_path [HAL_PATH_MAX];
-/* TODO: clean up netlink socket handling - this is almost a verbatim copy from 0.4.x */
-
-static void
-link_detection_handle_message (struct nlmsghdr *hdr)
-{
- struct ifinfomsg *ifinfo;
- char ifname[1024];
- struct rtattr *attr;
- int attr_len;
- HalDevice *d;
- const char *hal_ifname;
-
- ifinfo = NLMSG_DATA (hdr);
-
- if (hdr->nlmsg_len < NLMSG_LENGTH (sizeof (struct ifinfomsg))) {
- HAL_ERROR (("Packet too small or truncated for ifinfomsg"));
- return;
- }
-
- memset (&ifname, 0, sizeof (ifname));
-
- attr = (struct rtattr *) ((unsigned char *)ifinfo + NLMSG_ALIGN (sizeof (struct ifinfomsg)));
- attr_len = NLMSG_PAYLOAD (hdr, sizeof (struct ifinfomsg));
-
- while (RTA_OK (attr, attr_len)) {
- if (attr->rta_type == IFLA_IFNAME) {
- unsigned int l = RTA_PAYLOAD (attr);
-
- if (l > sizeof (ifname) - 1)
- l = sizeof (ifname) - 1;
-
- strncpy (ifname, RTA_DATA (attr), l);
- }
-
- attr = RTA_NEXT (attr, attr_len);
- }
-
- /* bail out if there is no interface name */
- if (strlen (ifname) == 0)
- goto out;
-
- HAL_INFO (("type=0x%02x, SEQ=%d, ifi_flags=0x%04x, ifi_change=0x%04x, ifi_index=%d, ifname='%s'",
- hdr->nlmsg_type,
- hdr->nlmsg_seq,
- ifinfo->ifi_flags,
- ifinfo->ifi_change,
- ifinfo->ifi_index,
- ifname));
-
- /* find hal device object this event applies to */
- d = hal_device_store_match_key_value_int (hald_get_gdl (), "net.linux.ifindex", ifinfo->ifi_index);
- if (d == NULL) {
- HAL_WARNING (("No HAL device object corresponding to ifindex=%d, ifname='%s'",
- ifinfo->ifi_index, ifname));
- goto out;
- }
-
- device_property_atomic_update_begin ();
- {
-
- /* handle link changes */
- if (ifinfo->ifi_flags & IFF_RUNNING) {
- if (hal_device_has_capability (d, "net.80203") &&
- hal_device_property_get_bool (d, "net.80203.can_detect_link")) {
- if (!hal_device_property_get_bool (d, "net.80203.link")) {
- hal_device_property_set_bool (d, "net.80203.link", TRUE);
- HAL_INFO (("Assuming link speed is 100Mbps"));
- hal_device_property_set_uint64 (d, "net.80203.rate", 100 * 1000 * 1000);
- }
- }
- } else {
- if (hal_device_has_capability (d, "net.80203") &&
- hal_device_property_get_bool (d, "net.80203.can_detect_link")) {
- if (hal_device_property_get_bool (d, "net.80203.link")) {
- hal_device_property_set_bool (d, "net.80203.link", FALSE);
- /* only have rate when we have a link */
- hal_device_property_remove (d, "net.80203.rate");
- }
- }
- }
-
- /* handle events for renaming */
- hal_ifname = hal_device_property_get_string (d, "net.interface");
- if (hal_ifname != NULL && strcmp (hal_ifname, ifname) != 0) {
- char new_sysfs_path[256];
- const char *sysfs_path;
- char *p;
-
- HAL_INFO (("Net interface '%s' renamed to '%s'", hal_ifname, ifname));
-
- hal_device_property_set_string (d, "net.interface", ifname);
-
- sysfs_path = hal_device_property_get_string (d, "net.linux.sysfs_path");
- strncpy (new_sysfs_path, sysfs_path, sizeof (new_sysfs_path) - 1);
- p = strrchr (new_sysfs_path, '/');
- if (p != NULL) {
- strncpy (p + 1, ifname, sizeof (new_sysfs_path) - 1 - (p + 1 - new_sysfs_path));
- hal_device_property_set_string (d, "net.linux.sysfs_path", new_sysfs_path);
- }
- }
-
- /* handle up/down status */
- if (ifinfo->ifi_flags & IFF_UP) {
- if (!hal_device_property_get_bool (d, "net.interface_up")) {
- hal_device_property_set_bool (d, "net.interface_up", TRUE);
- }
- } else {
- if (hal_device_property_get_bool (d, "net.interface_up")) {
- hal_device_property_set_bool (d, "net.interface_up", FALSE);
- }
- }
-
- }
- device_property_atomic_update_end ();
-
-out:
- return;
-}
-
-#define VALID_NLMSG(h, s) ((NLMSG_OK (h, s) && \
- s >= sizeof (struct nlmsghdr) && \
- s >= h->nlmsg_len))
-
static gboolean
-netlink_socket_data (GIOChannel *channel, GIOCondition cond, gpointer user_data)
-{
- int fd;
- int bytes_read;
- guint total_read = 0;
- struct sockaddr_nl nladdr;
- socklen_t nladdrlen = sizeof(nladdr);
- char buf[1024];
-
- if (cond & ~(G_IO_IN | G_IO_PRI)) {
- HAL_ERROR (("Error occurred on netlink socket"));
- return TRUE;
- }
-
- fd = g_io_channel_unix_get_fd (channel);
- do {
- errno = 0;
- bytes_read = recvfrom (fd,
- buf + total_read,
- sizeof (buf) - total_read,
- MSG_DONTWAIT,
- (struct sockaddr*)&nladdr, &nladdrlen);
- if (nladdrlen != sizeof(nladdr)) {
- HAL_ERROR(("Bad address size reading netlink socket"));
- return TRUE;
- }
- if (nladdr.nl_pid) {
- HAL_ERROR(("Spoofed packet received on netlink socket"));
- return TRUE;
- }
- if (bytes_read > 0)
- total_read += bytes_read;
- } while (bytes_read > 0 || errno == EINTR);
-
- if (bytes_read < 0 && errno != EAGAIN) {
- HAL_ERROR (("Error reading data off netlink socket"));
- return TRUE;
- }
-
- if (total_read > 0) {
- struct nlmsghdr *hdr = (struct nlmsghdr *) buf;
- guint offset = 0;
-
- while (offset < total_read &&
- VALID_NLMSG (hdr, total_read - offset)) {
-
- if (hdr->nlmsg_type == NLMSG_DONE)
- break;
-
- if (hdr->nlmsg_type == RTM_NEWLINK ||
- hdr->nlmsg_type == RTM_DELLINK)
- link_detection_handle_message (hdr);
-
- offset += hdr->nlmsg_len;
- hdr = (struct nlmsghdr *) (buf + offset);
- }
-
- if (offset < total_read &&
- !VALID_NLMSG (hdr, total_read - offset)) {
- HAL_ERROR (("Packet too small or truncated"));
- return TRUE;
- }
- }
-
- return TRUE;
-}
-
-
-static gboolean
-hald_helper_data (GIOChannel *source,
- GIOCondition condition,
- gpointer user_data)
+hald_helper_data (GIOChannel *source, GIOCondition condition, gpointer user_data)
{
struct hald_helper_msg msg;
int fd;
@@ -373,8 +179,6 @@
void
osspec_init (void)
{
- int netlinkfd;
- struct sockaddr_nl netlink_addr;
int socketfd;
struct sockaddr_un saddr;
socklen_t addrlen;
@@ -417,26 +221,6 @@
}
HAL_INFO (("proc mount point is '%s'", hal_proc_path));
-
- /* Listen to the netlink socket */
- netlinkfd = socket (PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
-
- if (netlinkfd < 0) {
- DIE (("Couldn't open socket"));
- }
-
- memset (&netlink_addr, 0, sizeof (netlink_addr));
- netlink_addr.nl_family = AF_NETLINK;
- netlink_addr.nl_pid = getpid ();
- netlink_addr.nl_groups = RTMGRP_LINK;
- if (bind (netlinkfd, (struct sockaddr *) &netlink_addr, sizeof (netlink_addr)) < 0) {
- DIE (("Unable to bind to netlink socket"));
- return;
- }
- channel = g_io_channel_unix_new (netlinkfd);
- g_io_add_watch (channel, G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_NVAL,
- netlink_socket_data, NULL);
-
/* Load various hardware id databases */
ids_init ();
More information about the hal-commit
mailing list