/* * netsniff-ng - the packet sniffing beast * Copyright 2009, 2010 Daniel Borkmann. * Copyright 2014 Tobias Klauser * Subject to the GPL, version 2. */ #include #include "hash.h" #include "str.h" #include "lookup.h" #include "xmalloc.h" static struct hash_table lookup_port_tables[PORTS_MAX]; static const char * const lookup_port_files[] = { [PORTS_UDP] = ETCDIRE_STRING "/udp.conf", [PORTS_TCP] = ETCDIRE_STRING "/tcp.conf", [PORTS_ETHER] = ETCDIRE_STRING "/ether.conf", }; struct port { unsigned int id; char *port; struct port *next; }; void lookup_init_ports(enum ports which) { FILE *fp; char buff[128], *ptr, *end; const char *file; struct hash_table *table; struct port *p; void **pos; bug_on(which >= PORTS_MAX); table = &lookup_port_tables[which]; file = lookup_port_files[which]; fp = fopen(file, "r"); if (!fp) panic("No %s found!\n", file); memset(buff, 0, sizeof(buff)); while (fgets(buff, sizeof(buff), fp) != NULL) { buff[sizeof(buff) - 1] = 0; ptr = buff; p = xmalloc(sizeof(*p)); p->id = strtol(ptr, &end, 0); /* not a valid line, skip */ if (p->id == 0 && end == ptr) { xfree(p); continue; } ptr = strstr(buff, ", "); /* likewise */ if (!ptr) { xfree(p); continue; } ptr += strlen(", "); ptr = strtrim_right(ptr, '\n'); ptr = strtrim_right(ptr, ' '); p->port = xstrdup(ptr); p->next = NULL; pos = insert_hash(p->id, p, table); if (pos) { p->next = *pos; *pos = p; } memset(buff, 0, sizeof(buff)); } fclose(fp); } static int __lookup_cleanup_single(void *ptr) { struct port *tmp, *p = ptr; if (!ptr) return 0; while ((tmp = p->next)) { xfree(p->port); xfree(p); p = tmp; } xfree(p->port); xfree(p); return 0; } void lookup_cleanup_ports(enum ports which) { struct hash_table *table; bug_on(which >= PORTS_MAX); table = &lookup_port_tables[which]; for_each_hash(table, __lookup_cleanup_single); free_hash(table); } #define __do_lookup_inline(id, struct_name, hash_ptr, struct_member) \ ({ \ struct struct_name *entry = lookup_hash(id, hash_ptr); \ \ while (entry && id != entry->id) \ entry = entry->next; \ \ (entry && id == entry->id ? entry->struct_member : NULL); \ }) char *lookup_ether_type(unsigned int id) { return __do_lookup_inline(id, port, &lookup_port_tables[PORTS_ETHER], port); } char *lookup_port_udp(unsigned int id) { return __do_lookup_inline(id, port, &lookup_port_tables[PORTS_UDP], port); } char *lookup_port_tcp(unsigned int id) { return __do_lookup_inline(id, port, &lookup_port_tables[PORTS_TCP], port); } search'/>
path: root/Documentation/frv
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-10-24 21:19:07 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2016-10-24 21:19:07 -0700
commit1ce5bdb8312b6e9629029340063ea1e5cfac435d (patch)
treec47706ca6b30ff50ec204e5abfb5ee22dc841e48 /Documentation/frv
parentaa34e07e457ed13b44d680b5b605e3e5a585f611 (diff)
parentd71cf15b865bdd45925f7b094d169aaabd705145 (diff)
Merge tag 'gpio-v4.9-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO fixes from Linus Walleij: "Here is a set of GPIO fixes for the v4.9 kernel series: - Fix up off-by one and line offset validation, info leak to userspace, and reject invalid flags. Those are especially valuable hardening patches from Lars-Peter Clausen, all tagged for stable. - Fix module autoload for TS4800 and ATH79. - Correct the IRQ handler for MPC8xxx to use handle_level_irq() as it (a) reacts to edges not levels and (b) even implements .irq_ack(). We were missing IRQs here. - Fix the error path for acpi_dev_gpio_irq_get() - Fix a memory leak in the MXS driver. - Fix an annoying typo in the STMPE driver. - Put a dependency on sysfs to the mockup driver" * tag 'gpio-v4.9-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: gpio: mpc8xxx: Correct irq handler function gpio: ath79: Fix module autoload gpio: ts4800: Fix module autoload gpio: GPIO_GET_LINEEVENT_IOCTL: Reject invalid line and event flags gpio: GPIO_GET_LINEHANDLE_IOCTL: Reject invalid line flags gpio: GPIOHANDLE_GET_LINE_VALUES_IOCTL: Fix information leak gpio: GPIO_GET_LINEEVENT_IOCTL: Validate line offset gpio: GPIOHANDLE_GET_LINE_VALUES_IOCTL: Fix information leak gpio: GPIO_GET_LINEHANDLE_IOCTL: Validate line offset gpio: GPIO_GET_CHIPINFO_IOCTL: Fix information leak gpio: GPIO_GET_CHIPINFO_IOCTL: Fix line offset validation gpio / ACPI: fix returned error from acpi_dev_gpio_irq_get() gpio: mockup: add sysfs dependency gpio: stmpe: || vs && typo gpio: mxs: Unmap region obtained by of_iomap gpio/board.txt: point to gpiod_set_value
Diffstat (limited to 'Documentation/frv')