{"action":"created","comment":{"url":"https://api.github.com/repos/Gandi/packet-journey/pulls/comments/43275959","id":43275959,"diff_hunk":"@@ -493,6 +499,103 @@ parse_config_from_file(uint8_t port_id, char *q_arg)\n \treturn 0;\n }\n \n+static int rate_limit_ipv4(uint32_t naddr, uint32_t num)\n+{\n+\tunion rlimit_addr *addr;\n+\tuint8_t range_id;\n+\tstatic uint8_t next_range_id = 0;\n+\n+\taddr = (union rlimit_addr *)&naddr;\n+\trange_id = rlimit4_lookup_table[addr->network];\n+\t// check if this cidr range is the lookup table\n+\tif (range_id == INVALID_RLIMIT_RANGE) {\n+\t\trange_id = next_range_id++;\n+\n+\t\tif (range_id >= MAX_RLIMIT_RANGE) { // if not found\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\t// set slot for this cidr range in the lookup table\n+\t// and set the max packet rate for this dest addr\n+\trlimit4_lookup_table[addr->network] = range_id;\n+\trlimit4_max[range_id][addr->host] = num;\n+\n+\treturn 0;\n+}\n+\n+int rate_limit_address(cmdline_ipaddr_t *ip, uint32_t num);\n+int rate_limit_address(cmdline_ipaddr_t *ip, uint32_t num)\n+{\n+\tuint8_t next_hop;\n+\tint i;\n+\tuint32_t netmask, netaddr, j;\n+\n+\tif (ip->prefixlen > 0) {\n+\t\t// rate limit range\n+\t\tif (ip->family == AF_INET) {\n+\t\t\tnetmask = ((1 << ip->prefixlen) - 1) << (32 - ip->prefixlen);\n+\t\t\tnetaddr = rte_be_to_cpu_32(ip->addr.ipv4.s_addr) & netmask;\n+\t\t\tfor (j = netaddr; j < netaddr + (1 << (32 - ip->prefixlen)); j++) {","path":"app/config.c","position":61,"original_position":61,"commit_id":"51ccad35684b98e56a0f80dcf914389c7a934b97","original_commit_id":"51ccad35684b98e56a0f80dcf914389c7a934b97","user":{"login":"klnikita","id":176634,"avatar_url":"https://avatars.githubusercontent.com/u/176634?v=3","gravatar_id":"","url":"https://api.github.com/users/klnikita","html_url":"https://github.com/klnikita","followers_url":"https://api.github.com/users/klnikita/followers","following_url":"https://api.github.com/users/klnikita/following{/other_user}","gists_url":"https://api.github.com/users/klnikita/gists{/gist_id}","starred_url":"https://api.github.com/users/klnikita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/klnikita/subscriptions","organizations_url":"https://api.github.com/users/klnikita/orgs","repos_url":"https://api.github.com/users/klnikita/repos","events_url":"https://api.github.com/users/klnikita/events{/privacy}","received_events_url":"https://api.github.com/users/klnikita/received_events","type":"User","site_admin":false},"body":"may you put `netaddr + (1 << (32 - ip->prefixlen))` in a var outside the loop ? its easier to debug/print","created_at":"2015-10-28T15:59:32Z","updated_at":"2015-10-28T15:59:32Z","html_url":"https://github.com/Gandi/packet-journey/pull/5#discussion_r43275959","pull_request_url":"https://api.github.com/repos/Gandi/packet-journey/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/Gandi/packet-journey/pulls/comments/43275959"},"html":{"href":"https://github.com/Gandi/packet-journey/pull/5#discussion_r43275959"},"pull_request":{"href":"https://api.github.com/repos/Gandi/packet-journey/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/Gandi/packet-journey/pulls/5","id":48994350,"html_url":"https://github.com/Gandi/packet-journey/pull/5","diff_url":"https://github.com/Gandi/packet-journey/pull/5.diff","patch_url":"https://github.com/Gandi/packet-journey/pull/5.patch","issue_url":"https://api.github.com/repos/Gandi/packet-journey/issues/5","number":5,"state":"open","locked":false,"title":"Implement dest rate limiting","user":{"login":"fatih-acar","id":15028881,"avatar_url":"https://avatars.githubusercontent.com/u/15028881?v=3","gravatar_id":"","url":"https://api.github.com/users/fatih-acar","html_url":"https://github.com/fatih-acar","followers_url":"https://api.github.com/users/fatih-acar/followers","following_url":"https://api.github.com/users/fatih-acar/following{/other_user}","gists_url":"https://api.github.com/users/fatih-acar/gists{/gist_id}","starred_url":"https://api.github.com/users/fatih-acar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fatih-acar/subscriptions","organizations_url":"https://api.github.com/users/fatih-acar/orgs","repos_url":"https://api.github.com/users/fatih-acar/repos","events_url":"https://api.github.com/users/fatih-acar/events{/privacy}","received_events_url":"https://api.github.com/users/fatih-acar/received_events","type":"User","site_admin":false},"body":"Per dest address for IPv4\r\nPer dest neighbor for IPv6\r\nSingle counter per lcore (like kni rate limiting)","created_at":"2015-10-28T11:38:35Z","updated_at":"2015-10-28T15:59:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"92c42b4847241812613d510f3a5b4e12dfa153d2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Gandi/packet-journey/pulls/5/commits","review_comments_url":"https://api.github.com/repos/Gandi/packet-journey/pulls/5/comments","review_comment_url":"https://api.github.com/repos/Gandi/packet-journey/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Gandi/packet-journey/issues/5/comments","statuses_url":"https://api.github.com/repos/Gandi/packet-journey/statuses/51ccad35684b98e56a0f80dcf914389c7a934b97","head":{"label":"fatih-acar:dest_ratelimit","ref":"dest_ratelimit","sha":"51ccad35684b98e56a0f80dcf914389c7a934b97","user":{"login":"fatih-acar","id":15028881,"avatar_url":"https://avatars.githubusercontent.com/u/15028881?v=3","gravatar_id":"","url":"https://api.github.com/users/fatih-acar","html_url":"https://github.com/fatih-acar","followers_url":"https://api.github.com/users/fatih-acar/followers","following_url":"https://api.github.com/users/fatih-acar/following{/other_user}","gists_url":"https://api.github.com/users/fatih-acar/gists{/gist_id}","starred_url":"https://api.github.com/users/fatih-acar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fatih-acar/subscriptions","organizations_url":"https://api.github.com/users/fatih-acar/orgs","repos_url":"https://api.github.com/users/fatih-acar/repos","events_url":"https://api.github.com/users/fatih-acar/events{/privacy}","received_events_url":"https://api.github.com/users/fatih-acar/received_events","type":"User","site_admin":false},"repo":{"id":45108179,"name":"packet-journey","full_name":"fatih-acar/packet-journey","owner":{"login":"fatih-acar","id":15028881,"avatar_url":"https://avatars.githubusercontent.com/u/15028881?v=3","gravatar_id":"","url":"https://api.github.com/users/fatih-acar","html_url":"https://github.com/fatih-acar","followers_url":"https://api.github.com/users/fatih-acar/followers","following_url":"https://api.github.com/users/fatih-acar/following{/other_user}","gists_url":"https://api.github.com/users/fatih-acar/gists{/gist_id}","starred_url":"https://api.github.com/users/fatih-acar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fatih-acar/subscriptions","organizations_url":"https://api.github.com/users/fatih-acar/orgs","repos_url":"https://api.github.com/users/fatih-acar/repos","events_url":"https://api.github.com/users/fatih-acar/events{/privacy}","received_events_url":"https://api.github.com/users/fatih-acar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fatih-acar/packet-journey","description":"Packet-journey, userland router which uses DPDK for its fastpath switching.","fork":true,"url":"https://api.github.com/repos/fatih-acar/packet-journey","forks_url":"https://api.github.com/repos/fatih-acar/packet-journey/forks","keys_url":"https://api.github.com/repos/fatih-acar/packet-journey/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fatih-acar/packet-journey/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fatih-acar/packet-journey/teams","hooks_url":"https://api.github.com/repos/fatih-acar/packet-journey/hooks","issue_events_url":"https://api.github.com/repos/fatih-acar/packet-journey/issues/events{/number}","events_url":"https://api.github.com/repos/fatih-acar/packet-journey/events","assignees_url":"https://api.github.com/repos/fatih-acar/packet-journey/assignees{/user}","branches_url":"https://api.github.com/repos/fatih-acar/packet-journey/branches{/branch}","tags_url":"https://api.github.com/repos/fatih-acar/packet-journey/tags","blobs_url":"https://api.github.com/repos/fatih-acar/packet-journey/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fatih-acar/packet-journey/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fatih-acar/packet-journey/git/refs{/sha}","trees_url":"https://api.github.com/repos/fatih-acar/packet-journey/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fatih-acar/packet-journey/statuses/{sha}","languages_url":"https://api.github.com/repos/fatih-acar/packet-journey/languages","stargazers_url":"https://api.github.com/repos/fatih-acar/packet-journey/stargazers","contributors_url":"https://api.github.com/repos/fatih-acar/packet-journey/contributors","subscribers_url":"https://api.github.com/repos/fatih-acar/packet-journey/subscribers","subscription_url":"https://api.github.com/repos/fatih-acar/packet-journey/subscription","commits_url":"https://api.github.com/repos/fatih-acar/packet-journey/commits{/sha}","git_commits_url":"https://api.github.com/repos/fatih-acar/packet-journey/git/commits{/sha}","comments_url":"https://api.github.com/repos/fatih-acar/packet-journey/comments{/number}","issue_comment_url":"https://api.github.com/repos/fatih-acar/packet-journey/issues/comments{/number}","contents_url":"https://api.github.com/repos/fatih-acar/packet-journey/contents/{+path}","compare_url":"https://api.github.com/repos/fatih-acar/packet-journey/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fatih-acar/packet-journey/merges","archive_url":"https://api.github.com/repos/fatih-acar/packet-journey/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fatih-acar/packet-journey/downloads","issues_url":"https://api.github.com/repos/fatih-acar/packet-journey/issues{/number}","pulls_url":"https://api.github.com/repos/fatih-acar/packet-journey/pulls{/number}","milestones_url":"https://api.github.com/repos/fatih-acar/packet-journey/milestones{/number}","notifications_url":"https://api.github.com/repos/fatih-acar/packet-journey/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fatih-acar/packet-journey/labels{/name}","releases_url":"https://api.github.com/repos/fatih-acar/packet-journey/releases{/id}","created_at":"2015-10-28T11:34:37Z","updated_at":"2015-10-28T11:34:38Z","pushed_at":"2015-10-28T15:04:10Z","git_url":"git://github.com/fatih-acar/packet-journey.git","ssh_url":"git@github.com:fatih-acar/packet-journey.git","clone_url":"https://github.com/fatih-acar/packet-journey.git","svn_url":"https://github.com/fatih-acar/packet-journey","homepage":"","size":684,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Gandi:master","ref":"master","sha":"b74467b07249ae45fc74a2acb23636c54077acb4","user":{"login":"Gandi","id":467962,"avatar_url":"https://avatars.githubusercontent.com/u/467962?v=3","gravatar_id":"","url":"https://api.github.com/users/Gandi","html_url":"https://github.com/Gandi","followers_url":"https://api.github.com/users/Gandi/followers","following_url":"https://api.github.com/users/Gandi/following{/other_user}","gists_url":"https://api.github.com/users/Gandi/gists{/gist_id}","starred_url":"https://api.github.com/users/Gandi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gandi/subscriptions","organizations_url":"https://api.github.com/users/Gandi/orgs","repos_url":"https://api.github.com/users/Gandi/repos","events_url":"https://api.github.com/users/Gandi/events{/privacy}","received_events_url":"https://api.github.com/users/Gandi/received_events","type":"Organization","site_admin":false},"repo":{"id":43833153,"name":"packet-journey","full_name":"Gandi/packet-journey","owner":{"login":"Gandi","id":467962,"avatar_url":"https://avatars.githubusercontent.com/u/467962?v=3","gravatar_id":"","url":"https://api.github.com/users/Gandi","html_url":"https://github.com/Gandi","followers_url":"https://api.github.com/users/Gandi/followers","following_url":"https://api.github.com/users/Gandi/following{/other_user}","gists_url":"https://api.github.com/users/Gandi/gists{/gist_id}","starred_url":"https://api.github.com/users/Gandi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gandi/subscriptions","organizations_url":"https://api.github.com/users/Gandi/orgs","repos_url":"https://api.github.com/users/Gandi/repos","events_url":"https://api.github.com/users/Gandi/events{/privacy}","received_events_url":"https://api.github.com/users/Gandi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Gandi/packet-journey","description":"Packet-journey, userland router which uses DPDK for its fastpath switching.","fork":false,"url":"https://api.github.com/repos/Gandi/packet-journey","forks_url":"https://api.github.com/repos/Gandi/packet-journey/forks","keys_url":"https://api.github.com/repos/Gandi/packet-journey/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Gandi/packet-journey/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Gandi/packet-journey/teams","hooks_url":"https://api.github.com/repos/Gandi/packet-journey/hooks","issue_events_url":"https://api.github.com/repos/Gandi/packet-journey/issues/events{/number}","events_url":"https://api.github.com/repos/Gandi/packet-journey/events","assignees_url":"https://api.github.com/repos/Gandi/packet-journey/assignees{/user}","branches_url":"https://api.github.com/repos/Gandi/packet-journey/branches{/branch}","tags_url":"https://api.github.com/repos/Gandi/packet-journey/tags","blobs_url":"https://api.github.com/repos/Gandi/packet-journey/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Gandi/packet-journey/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Gandi/packet-journey/git/refs{/sha}","trees_url":"https://api.github.com/repos/Gandi/packet-journey/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Gandi/packet-journey/statuses/{sha}","languages_url":"https://api.github.com/repos/Gandi/packet-journey/languages","stargazers_url":"https://api.github.com/repos/Gandi/packet-journey/stargazers","contributors_url":"https://api.github.com/repos/Gandi/packet-journey/contributors","subscribers_url":"https://api.github.com/repos/Gandi/packet-journey/subscribers","subscription_url":"https://api.github.com/repos/Gandi/packet-journey/subscription","commits_url":"https://api.github.com/repos/Gandi/packet-journey/commits{/sha}","git_commits_url":"https://api.github.com/repos/Gandi/packet-journey/git/commits{/sha}","comments_url":"https://api.github.com/repos/Gandi/packet-journey/comments{/number}","issue_comment_url":"https://api.github.com/repos/Gandi/packet-journey/issues/comments{/number}","contents_url":"https://api.github.com/repos/Gandi/packet-journey/contents/{+path}","compare_url":"https://api.github.com/repos/Gandi/packet-journey/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Gandi/packet-journey/merges","archive_url":"https://api.github.com/repos/Gandi/packet-journey/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Gandi/packet-journey/downloads","issues_url":"https://api.github.com/repos/Gandi/packet-journey/issues{/number}","pulls_url":"https://api.github.com/repos/Gandi/packet-journey/pulls{/number}","milestones_url":"https://api.github.com/repos/Gandi/packet-journey/milestones{/number}","notifications_url":"https://api.github.com/repos/Gandi/packet-journey/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Gandi/packet-journey/labels{/name}","releases_url":"https://api.github.com/repos/Gandi/packet-journey/releases{/id}","created_at":"2015-10-07T17:34:36Z","updated_at":"2015-10-28T08:21:17Z","pushed_at":"2015-10-28T15:04:11Z","git_url":"git://github.com/Gandi/packet-journey.git","ssh_url":"git@github.com:Gandi/packet-journey.git","clone_url":"https://github.com/Gandi/packet-journey.git","svn_url":"https://github.com/Gandi/packet-journey","homepage":"","size":684,"stargazers_count":12,"watchers_count":12,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Gandi/packet-journey/pulls/5"},"html":{"href":"https://github.com/Gandi/packet-journey/pull/5"},"issue":{"href":"https://api.github.com/repos/Gandi/packet-journey/issues/5"},"comments":{"href":"https://api.github.com/repos/Gandi/packet-journey/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/Gandi/packet-journey/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/Gandi/packet-journey/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Gandi/packet-journey/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/Gandi/packet-journey/statuses/51ccad35684b98e56a0f80dcf914389c7a934b97"}}}}