{"action":"created","comment":{"url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls/comments/115019198","pull_request_review_id":36531309,"id":115019198,"diff_hunk":"@@ -0,0 +1,238 @@\n+/* Copyright 2017 Endless Mobile, Inc.\n+ *\n+ * This file is part of eos-metrics-instrumentation.\n+ *\n+ * eos-metrics-instrumentation is free software: you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as published by\n+ * the Free Software Foundation, either version 2 of the License, or (at your\n+ * option) any later version.\n+ *\n+ * eos-metrics-instrumentation is distributed in the hope that it will be\n+ * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General\n+ * Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with eos-metrics-instrumentation.  If not, see\n+ * <http://www.gnu.org/licenses/>.\n+ */\n+\n+#include <glib.h>\n+#include <stdio.h>\n+\n+#include \"eins-network-id.h\"\n+\n+#define PROC_IPV4_ROUTE_FILE \"/proc/net/route\"\n+#define IPV4_ROUTE_REGEXP \"^(?:\\\\S+\\\\s+){2}(?P<Gateway>[0-9A-F]{8})\\\\s+(?:\\\\S+\\\\s+){4}(?P<Mask>00000000)\"\n+\n+/*\n+ * greps the /proc/net/route file for the IPv4 default route. note that even\n+ * on machines with multiple interfaces, the first listed 00000000 route will\n+ * be the first one selected for outbound traffic, so we don't need to do any\n+ * more complex searching/sorting here (verified in net/ipv4/fib_trie.c on\n+ * kernel 4.10.5 - the trie is ordered by (prefix,tos,priority) so the highest\n+ * preference default route will appear first)\n+ */\n+gchar *\n+get_ipv4_default_gateway (void)\n+{\n+  g_autofree gchar *route = NULL;\n+\n+  if (!g_file_get_contents (PROC_IPV4_ROUTE_FILE, &route, NULL, NULL) || !route)\n+    {\n+      g_debug (\"could not load \" PROC_IPV4_ROUTE_FILE);\n+      return NULL;\n+    }\n+\n+  g_autoptr(GRegex) route_rx = g_regex_new (IPV4_ROUTE_REGEXP, G_REGEX_MULTILINE, 0, NULL);\n+  g_autoptr(GMatchInfo) route_mi = NULL;\n+\n+  if (!g_regex_match (route_rx, route, 0, &route_mi) || !route_mi)\n+    {\n+      g_debug (\"couldn't match IPv4 default gateway in \" PROC_IPV4_ROUTE_FILE);\n+      return NULL;\n+    }\n+\n+  const gchar *gateway = g_match_info_fetch_named (route_mi, \"Gateway\");\n+  g_assert (gateway);\n+  guint64 gateway_ip = g_ascii_strtoull (gateway, NULL, 16);\n+\n+  return g_strdup_printf (\"%u.%u.%u.%u\",\n+                          (guint8) gateway_ip,\n+                          (guint8) (gateway_ip >> 8),\n+                          (guint8) (gateway_ip >> 16),\n+                          (guint8) (gateway_ip >> 24));\n+}\n+\n+#define PROC_IPV4_ARP_FILE \"/proc/net/arp\"\n+#define IPV4_ARP_REGEXP \"^%s\\\\s+(\\\\S+\\\\s+){2}(?P<HW>[0-9a-f:]{17})\"\n+\n+/*\n+ * find the given IPv4 address in the ARP cache to find the HW address.\n+ * relies on two assumptions:\n+ *  - the first (obviously) is that the IP has been communicated with recently\n+ *    enough to be in the cache. for an internet-connected host, this is a\n+ *    pretty safe bet for the gateway IP.\n+ *  - the second is that if the host has multiple interfaces which are in the\n+ *    same IPv4 segment, that these are the same physical network, because the\n+ *    search is not constrained by interface which would be the strictly\n+ *    correct thing to do. this configuration seems pretty unlikely (two bonded\n+ *    load-balanced links with separate gateways?) on a client machine, and for\n+ *    our purposes it doesn't matter if we always report one gateway, or report\n+ *    both over time, so it's not worth getting excited about.\n+ */\n+gchar *\n+get_ipv4_hwaddr (const gchar *address)\n+{\n+  g_autofree gchar *arp = NULL;\n+\n+  if (!g_file_get_contents (PROC_IPV4_ARP_FILE, &arp, NULL, NULL) || !arp)\n+    {\n+      g_debug (\"could not load \" PROC_IPV4_ARP_FILE);","path":"src/eins-network-id.c","position":91,"original_position":91,"commit_id":"c8837074bebefa143a29ae6b4ad844f8904dd68a","original_commit_id":"c8837074bebefa143a29ae6b4ad844f8904dd68a","user":{"login":"pwithnall","id":53172,"avatar_url":"https://avatars1.githubusercontent.com/u/53172?v=3","gravatar_id":"","url":"https://api.github.com/users/pwithnall","html_url":"https://github.com/pwithnall","followers_url":"https://api.github.com/users/pwithnall/followers","following_url":"https://api.github.com/users/pwithnall/following{/other_user}","gists_url":"https://api.github.com/users/pwithnall/gists{/gist_id}","starred_url":"https://api.github.com/users/pwithnall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pwithnall/subscriptions","organizations_url":"https://api.github.com/users/pwithnall/orgs","repos_url":"https://api.github.com/users/pwithnall/repos","events_url":"https://api.github.com/users/pwithnall/events{/privacy}","received_events_url":"https://api.github.com/users/pwithnall/received_events","type":"User","site_admin":false},"body":"Same comments as above apply in this function too.","created_at":"2017-05-05T15:07:58Z","updated_at":"2017-05-05T15:23:47Z","html_url":"https://github.com/endlessm/eos-metrics-instrumentation/pull/66#discussion_r115019198","pull_request_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls/66","_links":{"self":{"href":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls/comments/115019198"},"html":{"href":"https://github.com/endlessm/eos-metrics-instrumentation/pull/66#discussion_r115019198"},"pull_request":{"href":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls/66"}}},"pull_request":{"url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls/66","id":119189678,"html_url":"https://github.com/endlessm/eos-metrics-instrumentation/pull/66","diff_url":"https://github.com/endlessm/eos-metrics-instrumentation/pull/66.diff","patch_url":"https://github.com/endlessm/eos-metrics-instrumentation/pull/66.patch","issue_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/issues/66","number":66,"state":"open","locked":false,"title":"T16934: add new network ID event to group machines by location","user":{"login":"ramcq","id":254468,"avatar_url":"https://avatars3.githubusercontent.com/u/254468?v=3","gravatar_id":"","url":"https://api.github.com/users/ramcq","html_url":"https://github.com/ramcq","followers_url":"https://api.github.com/users/ramcq/followers","following_url":"https://api.github.com/users/ramcq/following{/other_user}","gists_url":"https://api.github.com/users/ramcq/gists{/gist_id}","starred_url":"https://api.github.com/users/ramcq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramcq/subscriptions","organizations_url":"https://api.github.com/users/ramcq/orgs","repos_url":"https://api.github.com/users/ramcq/repos","events_url":"https://api.github.com/users/ramcq/events{/privacy}","received_events_url":"https://api.github.com/users/ramcq/received_events","type":"User","site_admin":false},"body":"Introduce the event `38eb48f8-e131-9b57-77c6-35e0590c82fd` which is recorded at system startup and when we detect a change in the default route.\r\n\r\nThe auxiliary payload is a 32-bit unsigned integer containing a hash of the ethernet MAC address of the gateway, favouring IPv4 if available, or IPv6 if not. The intention is to provide a value which is opaque and stable which is the same for every system located on the same physical network.\r\n\r\nThe new `eos-network-id` command prints this ID for user inspection.\r\n\r\nhttps://phabricator.endlessm.com/T16934","created_at":"2017-05-05T14:37:12Z","updated_at":"2017-05-05T15:23:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dfa216683a009728d40bd1857bf4c6149c30a6ef","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls/66/commits","review_comments_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls/66/comments","review_comment_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls/comments{/number}","comments_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/issues/66/comments","statuses_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/statuses/c8837074bebefa143a29ae6b4ad844f8904dd68a","head":{"label":"endlessm:T16934","ref":"T16934","sha":"c8837074bebefa143a29ae6b4ad844f8904dd68a","user":{"login":"endlessm","id":1930958,"avatar_url":"https://avatars2.githubusercontent.com/u/1930958?v=3","gravatar_id":"","url":"https://api.github.com/users/endlessm","html_url":"https://github.com/endlessm","followers_url":"https://api.github.com/users/endlessm/followers","following_url":"https://api.github.com/users/endlessm/following{/other_user}","gists_url":"https://api.github.com/users/endlessm/gists{/gist_id}","starred_url":"https://api.github.com/users/endlessm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endlessm/subscriptions","organizations_url":"https://api.github.com/users/endlessm/orgs","repos_url":"https://api.github.com/users/endlessm/repos","events_url":"https://api.github.com/users/endlessm/events{/privacy}","received_events_url":"https://api.github.com/users/endlessm/received_events","type":"Organization","site_admin":false},"repo":{"id":17677266,"name":"eos-metrics-instrumentation","full_name":"endlessm/eos-metrics-instrumentation","owner":{"login":"endlessm","id":1930958,"avatar_url":"https://avatars2.githubusercontent.com/u/1930958?v=3","gravatar_id":"","url":"https://api.github.com/users/endlessm","html_url":"https://github.com/endlessm","followers_url":"https://api.github.com/users/endlessm/followers","following_url":"https://api.github.com/users/endlessm/following{/other_user}","gists_url":"https://api.github.com/users/endlessm/gists{/gist_id}","starred_url":"https://api.github.com/users/endlessm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endlessm/subscriptions","organizations_url":"https://api.github.com/users/endlessm/orgs","repos_url":"https://api.github.com/users/endlessm/repos","events_url":"https://api.github.com/users/endlessm/events{/privacy}","received_events_url":"https://api.github.com/users/endlessm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/endlessm/eos-metrics-instrumentation","description":"Instrumentation daemons for eos-metrics","fork":false,"url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation","forks_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/forks","keys_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/keys{/key_id}","collaborators_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/teams","hooks_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/hooks","issue_events_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/issues/events{/number}","events_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/events","assignees_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/assignees{/user}","branches_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/branches{/branch}","tags_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/tags","blobs_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/git/refs{/sha}","trees_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/git/trees{/sha}","statuses_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/statuses/{sha}","languages_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/languages","stargazers_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/stargazers","contributors_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/contributors","subscribers_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/subscribers","subscription_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/subscription","commits_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/commits{/sha}","git_commits_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/git/commits{/sha}","comments_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/comments{/number}","issue_comment_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/issues/comments{/number}","contents_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/contents/{+path}","compare_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/compare/{base}...{head}","merges_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/merges","archive_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/downloads","issues_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/issues{/number}","pulls_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls{/number}","milestones_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/milestones{/number}","notifications_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/labels{/name}","releases_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/releases{/id}","deployments_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/deployments","created_at":"2014-03-12T18:06:36Z","updated_at":"2016-11-01T16:59:07Z","pushed_at":"2017-05-05T14:37:12Z","git_url":"git://github.com/endlessm/eos-metrics-instrumentation.git","ssh_url":"git@github.com:endlessm/eos-metrics-instrumentation.git","clone_url":"https://github.com/endlessm/eos-metrics-instrumentation.git","svn_url":"https://github.com/endlessm/eos-metrics-instrumentation","homepage":null,"size":144,"stargazers_count":1,"watchers_count":1,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"endlessm:master","ref":"master","sha":"39d41a038c41607e8ddd072965c92dc7fedac365","user":{"login":"endlessm","id":1930958,"avatar_url":"https://avatars2.githubusercontent.com/u/1930958?v=3","gravatar_id":"","url":"https://api.github.com/users/endlessm","html_url":"https://github.com/endlessm","followers_url":"https://api.github.com/users/endlessm/followers","following_url":"https://api.github.com/users/endlessm/following{/other_user}","gists_url":"https://api.github.com/users/endlessm/gists{/gist_id}","starred_url":"https://api.github.com/users/endlessm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endlessm/subscriptions","organizations_url":"https://api.github.com/users/endlessm/orgs","repos_url":"https://api.github.com/users/endlessm/repos","events_url":"https://api.github.com/users/endlessm/events{/privacy}","received_events_url":"https://api.github.com/users/endlessm/received_events","type":"Organization","site_admin":false},"repo":{"id":17677266,"name":"eos-metrics-instrumentation","full_name":"endlessm/eos-metrics-instrumentation","owner":{"login":"endlessm","id":1930958,"avatar_url":"https://avatars2.githubusercontent.com/u/1930958?v=3","gravatar_id":"","url":"https://api.github.com/users/endlessm","html_url":"https://github.com/endlessm","followers_url":"https://api.github.com/users/endlessm/followers","following_url":"https://api.github.com/users/endlessm/following{/other_user}","gists_url":"https://api.github.com/users/endlessm/gists{/gist_id}","starred_url":"https://api.github.com/users/endlessm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endlessm/subscriptions","organizations_url":"https://api.github.com/users/endlessm/orgs","repos_url":"https://api.github.com/users/endlessm/repos","events_url":"https://api.github.com/users/endlessm/events{/privacy}","received_events_url":"https://api.github.com/users/endlessm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/endlessm/eos-metrics-instrumentation","description":"Instrumentation daemons for eos-metrics","fork":false,"url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation","forks_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/forks","keys_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/keys{/key_id}","collaborators_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/teams","hooks_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/hooks","issue_events_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/issues/events{/number}","events_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/events","assignees_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/assignees{/user}","branches_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/branches{/branch}","tags_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/tags","blobs_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/git/refs{/sha}","trees_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/git/trees{/sha}","statuses_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/statuses/{sha}","languages_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/languages","stargazers_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/stargazers","contributors_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/contributors","subscribers_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/subscribers","subscription_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/subscription","commits_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/commits{/sha}","git_commits_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/git/commits{/sha}","comments_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/comments{/number}","issue_comment_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/issues/comments{/number}","contents_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/contents/{+path}","compare_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/compare/{base}...{head}","merges_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/merges","archive_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/downloads","issues_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/issues{/number}","pulls_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls{/number}","milestones_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/milestones{/number}","notifications_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/labels{/name}","releases_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/releases{/id}","deployments_url":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/deployments","created_at":"2014-03-12T18:06:36Z","updated_at":"2016-11-01T16:59:07Z","pushed_at":"2017-05-05T14:37:12Z","git_url":"git://github.com/endlessm/eos-metrics-instrumentation.git","ssh_url":"git@github.com:endlessm/eos-metrics-instrumentation.git","clone_url":"https://github.com/endlessm/eos-metrics-instrumentation.git","svn_url":"https://github.com/endlessm/eos-metrics-instrumentation","homepage":null,"size":144,"stargazers_count":1,"watchers_count":1,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls/66"},"html":{"href":"https://github.com/endlessm/eos-metrics-instrumentation/pull/66"},"issue":{"href":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/issues/66"},"comments":{"href":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/issues/66/comments"},"review_comments":{"href":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls/66/comments"},"review_comment":{"href":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/pulls/66/commits"},"statuses":{"href":"https://api.github.com/repos/endlessm/eos-metrics-instrumentation/statuses/c8837074bebefa143a29ae6b4ad844f8904dd68a"}}}}
{"actor":{"display_login":"pwithnall"}}