/* * netsniff-ng - the packet sniffing beast * Copyright 2009, 2010 Daniel Borkmann. * Copyright 2014, 2015 Tobias Klauser * Subject to the GPL, version 2. */ #include #include #include #include #include "hash.h" #include "str.h" #include "lookup.h" #include "xmalloc.h" static bool lookup_initialized[LT_MAX]; static struct hash_table lookup_tables[LT_MAX]; static const char * const lookup_files[] = { [LT_PORTS_UDP] = ETCDIRE_STRING "/udp.conf", [LT_PORTS_TCP] = ETCDIRE_STRING "/tcp.conf", [LT_ETHERTYPES] = ETCDIRE_STRING "/ether.conf", [LT_OUI] = ETCDIRE_STRING "/oui.conf", }; struct lookup_entry { unsigned int id; char *str; struct lookup_entry *next; }; void lookup_init(enum lookup_type which) { FILE *fp; char buff[128], *ptr, *end; const char *file; struct hash_table *table; struct lookup_entry *p; void **pos; bug_on(which >= LT_MAX); if (lookup_initialized[which]) return; table = &lookup_tables[which]; file = lookup_files[which]; fp = fopen(file, "r"); if (!fp) { fprintf(stderr, "Cannot open %s: %s." "Port name resolution won't be available.\n", file, strerror(errno)); return; } 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->str = 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); lookup_initialized[which] = true; } static int __lookup_cleanup_single(void *ptr) { struct lookup_entry *tmp, *p = ptr; if (!ptr) return 0; while ((tmp = p->next)) { xfree(p->str); xfree(p); p = tmp; } xfree(p->str); xfree(p); return 0; } void lookup_cleanup(enum lookup_type which) { struct hash_table *table; bug_on(which >= LT_MAX); if (!lookup_initialized[which]) return; table = &lookup_tables[which]; for_each_hash(table, __lookup_cleanup_single); free_hash(table); lookup_initialized[which] = false; } static inline const char *__lookup_inline(unsigned int id, struct hash_table *tbl) { struct lookup_entry *entry = lookup_hash(id, tbl); while (entry && id != entry->id) entry = entry->next; return (entry && id == entry->id ? entry->str : NULL); } const char *lookup_ether_type(unsigned int id) { return __lookup_inline(id, &lookup_tables[LT_ETHERTYPES]); } const char *lookup_port_udp(unsigned int id) { return __lookup_inline(id, &lookup_tables[LT_PORTS_UDP]); } const char *lookup_port_tcp(unsigned int id) { return __lookup_inline(id, &lookup_tables[LT_PORTS_TCP]); } const char *lookup_vendor(unsigned int id) { return __lookup_inline(id, &lookup_tables[LT_OUI]); } > Merge updates from Andrew Morton: - various misc bits - most of MM (quite a lot of MM material is awaiting the merge of linux-next dependencies) - kasan - printk updates - procfs updates - MAINTAINERS - /lib updates - checkpatch updates * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (123 commits) init: reduce rootwait polling interval time to 5ms binfmt_elf: use vmalloc() for allocation of vma_filesz checkpatch: don't emit unified-diff error for rename-only patches checkpatch: don't check c99 types like uint8_t under tools checkpatch: avoid multiple line dereferences checkpatch: don't check .pl files, improve absolute path commit log test scripts/checkpatch.pl: fix spelling checkpatch: don't try to get maintained status when --no-tree is given lib/ida: document locking requirements a bit better lib/rbtree.c: fix typo in comment of ____rb_erase_color lib/Kconfig.debug: make CONFIG_STRICT_DEVMEM depend on CONFIG_DEVMEM MAINTAINERS: add drm and drm/i915 irc channels MAINTAINERS: add "C:" for URI for chat where developers hang out MAINTAINERS: add drm and drm/i915 bug filing info MAINTAINERS: add "B:" for URI where to file bugs get_maintainer: look for arbitrary letter prefixes in sections printk: add Kconfig option to set default console loglevel printk/sound: handle more message headers printk/btrfs: handle more message headers printk/kdb: handle more message headers ... MAINTAINERS: add drm and drm/i915 irc channels 2016-12-13T02:55:09+00:00 Jani Nikula jani.nikula@intel.com 2016-12-13T00:46:11+00:00 urn:sha1:5fc41a70d804f93b88924bed1d2f494f3b735571 Link: http://lkml.kernel.org/r/1476966135-26943-4-git-send-email-jani.nikula@intel.com Signed-off-by: Jani Nikula <jani.nikula@intel.com> Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> Cc: Daniel Vetter <daniel@ffwll.ch> Cc: Dave Airlie <airlied@gmail.com> Cc: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> MAINTAINERS: add "C:" for URI for chat where developers hang out 2016-12-13T02:55:09+00:00 Jani Nikula jani.nikula@intel.com 2016-12-13T00:46:08+00:00 urn:sha1:57599f9b879cae3c85e8646772e94ae568854319 Make it easier to find the developer chat for the subsystem or driver. Link: http://lkml.kernel.org/r/1476966135-26943-3-git-send-email-jani.nikula@intel.com Signed-off-by: Jani Nikula <jani.nikula@intel.com> Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> Cc: Daniel Vetter <daniel@ffwll.ch> Cc: Dave Airlie <airlied@gmail.com> Cc: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> MAINTAINERS: add drm and drm/i915 bug filing info 2016-12-13T02:55:09+00:00 Jani Nikula jani.nikula@intel.com 2016-12-13T00:46:05+00:00 urn:sha1:51b06f9f84eb05f98755fd2d6293063a1a23980c Link: http://lkml.kernel.org/r/1476966135-26943-2-git-send-email-jani.nikula@intel.com Signed-off-by: Jani Nikula <jani.nikula@intel.com> Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> Cc: Daniel Vetter <daniel@ffwll.ch> Cc: Dave Airlie <airlied@gmail.com> Cc: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> MAINTAINERS: add "B:" for URI where to file bugs 2016-12-13T02:55:09+00:00 Jani Nikula jani.nikula@intel.com 2016-12-13T00:46:02+00:00 urn:sha1:2de2bd95f45639b8e21b1da7f72f506d43400b4d Different subsystems and drivers have different preferences for where to file bugs and what information to include. Add "B:" entry for specifying the URI for the bug tracker directly, a web page for detailed info on filing bugs, or a mailto: URI. Link: http://lkml.kernel.org/r/1476966135-26943-1-git-send-email-jani.nikula@intel.com Signed-off-by: Jani Nikula <jani.nikula@intel.com> Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> Acked-by: Daniel Vetter <daniel@ffwll.ch> Cc: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Merge branch 'x86-idle-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2016-12-12T22:55:04+00:00 Linus Torvalds torvalds@linux-foundation.org 2016-12-12T22:55:04+00:00 urn:sha1:212f30008a284a9312d95dad6cc237ff81173d73 Pull x86 idle updates from Ingo Molnar: "There were two bigger changes in this development cycle: - remove idle notifiers: 32 files changed, 74 insertions(+), 803 deletions(-) These notifiers were of questionable value and the main usecase, the i7300 driver, was essentially unmaintained and can be removed, plus modern power management concepts don't need the callback - so use this golden opportunity and get rid of this opaque and fragile callback from a latency sensitive code path. (Len Brown, Thomas Gleixner) - improve the AMD Erratum 400 workaround that used high overhead MSR polling in the idle loop (Borisla Petkov, Thomas Gleixner)" * 'x86-idle-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86: Remove empty idle.h header x86/amd: Simplify AMD E400 aware idle routine x86/amd: Check for the C1E bug post ACPI subsystem init x86/bugs: Separate AMD E400 erratum and C1E bug x86/cpufeature: Provide helper to set bugs bits x86/idle: Remove enter_idle(), exit_idle() x86: Remove x86_test_and_clear_bit_percpu() x86/idle: Remove is_idle flag x86/idle: Remove idle_notifier i7300_idle: Remove this driver