{"action":"created","comment":{"url":"https://api.github.com/repos/cilium/cilium/pulls/comments/77905821","id":77905821,"diff_hunk":"@@ -42,62 +43,122 @@ import (\n )\n \n var (\n-\tlog = logging.MustGetLogger(\"cilium-net\")\n+\tlog  = logging.MustGetLogger(\"cilium-net\")\n+\tipv4 bool\n )\n \n const (\n-\terrInvalidArgument = -1\n-\terrIOFailure       = -2\n+\tmapSize = 1024\n )\n \n-const (\n-\tMaxLxc = 8\n-)\n+type LB6Key struct {\n+\tAddress types.IPv6\n+\tPort    uint16\n+\tSlave   uint16\n+}\n \n-// lbServices : LBKey => LBValue, file cilium_lb_services\n-// lbState    : state => LBValue, file cilium_lb_state\n-const (\n-\tlbServices = 1\n-\tlbState    = 2\n-)\n+func (k LB6Key) GetPtr() unsafe.Pointer {\n+\treturn unsafe.Pointer(&k)\n+}\n \n-type LBKey struct {\n-\tvip   v6Addr\n-\tdport uint16\n-\tpad   uint16\n+type LB4Key struct {\n+\tAddress types.IPv4\n+\tPort    uint16\n+\tSlave   uint16\n }\n \n-type LBLXCPair struct {\n-\tLxcID  uint16\n-\tPort   uint16\n-\tNodeID uint32\n+func (k LB4Key) GetPtr() unsafe.Pointer {\n+\treturn unsafe.Pointer(&k)\n }\n \n-type LBValue struct {\n-\tvip      v6Addr\n-\tdport    uint16\n-\tstate    uint16\n-\tlxcCount int32\n-\tlxc      [MaxLxc]LBLXCPair\n+type LB6Service struct {\n+\tAddress types.IPv6\n+\tPort    uint16\n+\tCount   uint16\n+}\n+\n+type LB4Service struct {\n+\tAddress types.IPv4\n+\tPort    uint16\n+\tCount   uint16\n+\tState   uint16\n+}\n+\n+func (s *LB4Service) GetPtr() unsafe.Pointer {\n+\treturn unsafe.Pointer(s)\n+}\n+\n+type StateKey uint16\n+\n+func NewStateKey(value uint16) StateKey {\n+\t// The key is in network byte order\n+\treturn StateKey(common.Swab16(value))\n+}\n+\n+func (k StateKey) GetPtr() unsafe.Pointer {\n+\treturn unsafe.Pointer(&k)\n+}\n+\n+type LB6State struct {\n+\tAddress types.IPv6\n+\tPort    uint16\n+}\n+\n+type LB4State struct {\n+\tAddress types.IPv4\n+\tPort    uint16\n }\n \n type LBMap struct {\n \tfd int\n }\n \n-type v6Addr types.IPv6\n+func parseUint16(ctx *cli.Context, argn int) uint16 {\n+\ttmp, err := strconv.ParseUint(ctx.Args().Get(argn), 0, 16)\n+\tif err != nil {\n+\t\tfmt.Fprintf(os.Stderr, \"Invalid argument: %s\\n\", err)\n+\t\tprintUsageAndExit(ctx)\n+\t}\n \n-func printErrorAndExit(ctx *cli.Context, err string, code int) {\n-\tfmt.Fprintf(os.Stderr, \"%s\\n\", err)\n-\tfmt.Fprintf(os.Stderr, \"Usage: %s %s %s\\n\", ctx.App.Name, ctx.Command.Name,\n-\t\tctx.Command.ArgsUsage)\n-\tos.Exit(code)\n-\treturn\n+\treturn uint16(tmp)\n+}\n+\n+func servicesMap() *bpf.Map {\n+\tif ipv4 {\n+\t\treturn bpf.NewMap(\"/sys/fs/bpf/tc/globals/cilium_lb4_services\",\n+\t\t\tbpf.MapTypeHash,\n+\t\t\tint(unsafe.Sizeof(LB4Key{})),\n+\t\t\tint(unsafe.Sizeof(LB4Service{})),\n+\t\t\tmapSize)\n+\t} else {\n+\t\treturn bpf.NewMap(\"/sys/fs/bpf/tc/globals/cilium_lb6_services\",\n+\t\t\tbpf.MapTypeHash,\n+\t\t\tint(unsafe.Sizeof(LB6Key{})),\n+\t\t\tint(unsafe.Sizeof(LB6Service{})),\n+\t\t\tmapSize)\n+\t}\n+}\n+\n+func stateMap() *bpf.Map {\n+\tif ipv4 {\n+\t\treturn bpf.NewMap(\"/sys/fs/bpf/tc/globals/cilium_lb4_state\",","path":"bpf/lbmap/lb.go","position":155,"original_position":155,"commit_id":"4cdf770fe3e4de03855d85e2593ee57fcca03c20","original_commit_id":"4cdf770fe3e4de03855d85e2593ee57fcca03c20","user":{"login":"aanm","id":5714066,"avatar_url":"https://avatars.githubusercontent.com/u/5714066?v=3","gravatar_id":"","url":"https://api.github.com/users/aanm","html_url":"https://github.com/aanm","followers_url":"https://api.github.com/users/aanm/followers","following_url":"https://api.github.com/users/aanm/following{/other_user}","gists_url":"https://api.github.com/users/aanm/gists{/gist_id}","starred_url":"https://api.github.com/users/aanm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aanm/subscriptions","organizations_url":"https://api.github.com/users/aanm/orgs","repos_url":"https://api.github.com/users/aanm/repos","events_url":"https://api.github.com/users/aanm/events{/privacy}","received_events_url":"https://api.github.com/users/aanm/received_events","type":"User","site_admin":false},"body":"`\"/sys/fs/bpf/tc/globals/cilium_lb4_state\"` -> `common.BPFCiliumMaps + \"/cilium_lb4_state\"`","created_at":"2016-09-07T21:18:13Z","updated_at":"2016-09-07T21:18:13Z","html_url":"https://github.com/cilium/cilium/pull/109#discussion_r77905821","pull_request_url":"https://api.github.com/repos/cilium/cilium/pulls/109","_links":{"self":{"href":"https://api.github.com/repos/cilium/cilium/pulls/comments/77905821"},"html":{"href":"https://github.com/cilium/cilium/pull/109#discussion_r77905821"},"pull_request":{"href":"https://api.github.com/repos/cilium/cilium/pulls/109"}}},"pull_request":{"url":"https://api.github.com/repos/cilium/cilium/pulls/109","id":83548817,"html_url":"https://github.com/cilium/cilium/pull/109","diff_url":"https://github.com/cilium/cilium/pull/109.diff","patch_url":"https://github.com/cilium/cilium/pull/109.patch","issue_url":"https://api.github.com/repos/cilium/cilium/issues/109","number":109,"state":"open","locked":false,"title":"Add east-west and IPv4 load balancing [WIP]","user":{"login":"tgraf","id":1417913,"avatar_url":"https://avatars.githubusercontent.com/u/1417913?v=3","gravatar_id":"","url":"https://api.github.com/users/tgraf","html_url":"https://github.com/tgraf","followers_url":"https://api.github.com/users/tgraf/followers","following_url":"https://api.github.com/users/tgraf/following{/other_user}","gists_url":"https://api.github.com/users/tgraf/gists{/gist_id}","starred_url":"https://api.github.com/users/tgraf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tgraf/subscriptions","organizations_url":"https://api.github.com/users/tgraf/orgs","repos_url":"https://api.github.com/users/tgraf/repos","events_url":"https://api.github.com/users/tgraf/events{/privacy}","received_events_url":"https://api.github.com/users/tgraf/received_events","type":"User","site_admin":false},"body":"Reworks the load balancing code and makes most of the code available for reuse.\r\n\r\nAdds the following capabilities:\r\n - East west load balance\r\n - Balancing from and to arbitrary IPs\r\n - IPv4 support\r\n\r\nExample config, L3 load balancer based on L4 hash:\r\n```\r\nSVC_IP6=\"f00d::1:1\"\r\n￼LB_PORT=0\r\n￼STATE=222\r\ncilium lb create-services-map\r\ncilium lb update-service $SVC_IP6 $LB_PORT 0 2 $STATE :: $LB_PORT\r\ncilium lb update-service $SVC_IP6 $LB_PORT 1 2 $STATE $SERVER1_IP $LB_PORT\r\ncilium lb update-service $SVC_IP6 $LB_PORT 2 2 $STATE $SERVER2_IP $LB_PORT\r\ncilium lb create-state-map\r\ncilium lb update-state $STATE $SVC_IP6 $LB_PORT\r\n```\r\n","created_at":"2016-08-31T23:45:58Z","updated_at":"2016-09-07T21:18:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cc9e5be3a304b31d2431f66deea959921457af3d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/cilium/cilium/pulls/109/commits","review_comments_url":"https://api.github.com/repos/cilium/cilium/pulls/109/comments","review_comment_url":"https://api.github.com/repos/cilium/cilium/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cilium/cilium/issues/109/comments","statuses_url":"https://api.github.com/repos/cilium/cilium/statuses/4cdf770fe3e4de03855d85e2593ee57fcca03c20","head":{"label":"cilium:lb-updates","ref":"lb-updates","sha":"4cdf770fe3e4de03855d85e2593ee57fcca03c20","user":{"login":"cilium","id":21054566,"avatar_url":"https://avatars.githubusercontent.com/u/21054566?v=3","gravatar_id":"","url":"https://api.github.com/users/cilium","html_url":"https://github.com/cilium","followers_url":"https://api.github.com/users/cilium/followers","following_url":"https://api.github.com/users/cilium/following{/other_user}","gists_url":"https://api.github.com/users/cilium/gists{/gist_id}","starred_url":"https://api.github.com/users/cilium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cilium/subscriptions","organizations_url":"https://api.github.com/users/cilium/orgs","repos_url":"https://api.github.com/users/cilium/repos","events_url":"https://api.github.com/users/cilium/events{/privacy}","received_events_url":"https://api.github.com/users/cilium/received_events","type":"Organization","site_admin":false},"repo":{"id":48109239,"name":"cilium","full_name":"cilium/cilium","owner":{"login":"cilium","id":21054566,"avatar_url":"https://avatars.githubusercontent.com/u/21054566?v=3","gravatar_id":"","url":"https://api.github.com/users/cilium","html_url":"https://github.com/cilium","followers_url":"https://api.github.com/users/cilium/followers","following_url":"https://api.github.com/users/cilium/following{/other_user}","gists_url":"https://api.github.com/users/cilium/gists{/gist_id}","starred_url":"https://api.github.com/users/cilium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cilium/subscriptions","organizations_url":"https://api.github.com/users/cilium/orgs","repos_url":"https://api.github.com/users/cilium/repos","events_url":"https://api.github.com/users/cilium/events{/privacy}","received_events_url":"https://api.github.com/users/cilium/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cilium/cilium","description":"BPF & XDP for containers","fork":false,"url":"https://api.github.com/repos/cilium/cilium","forks_url":"https://api.github.com/repos/cilium/cilium/forks","keys_url":"https://api.github.com/repos/cilium/cilium/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cilium/cilium/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cilium/cilium/teams","hooks_url":"https://api.github.com/repos/cilium/cilium/hooks","issue_events_url":"https://api.github.com/repos/cilium/cilium/issues/events{/number}","events_url":"https://api.github.com/repos/cilium/cilium/events","assignees_url":"https://api.github.com/repos/cilium/cilium/assignees{/user}","branches_url":"https://api.github.com/repos/cilium/cilium/branches{/branch}","tags_url":"https://api.github.com/repos/cilium/cilium/tags","blobs_url":"https://api.github.com/repos/cilium/cilium/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cilium/cilium/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cilium/cilium/git/refs{/sha}","trees_url":"https://api.github.com/repos/cilium/cilium/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cilium/cilium/statuses/{sha}","languages_url":"https://api.github.com/repos/cilium/cilium/languages","stargazers_url":"https://api.github.com/repos/cilium/cilium/stargazers","contributors_url":"https://api.github.com/repos/cilium/cilium/contributors","subscribers_url":"https://api.github.com/repos/cilium/cilium/subscribers","subscription_url":"https://api.github.com/repos/cilium/cilium/subscription","commits_url":"https://api.github.com/repos/cilium/cilium/commits{/sha}","git_commits_url":"https://api.github.com/repos/cilium/cilium/git/commits{/sha}","comments_url":"https://api.github.com/repos/cilium/cilium/comments{/number}","issue_comment_url":"https://api.github.com/repos/cilium/cilium/issues/comments{/number}","contents_url":"https://api.github.com/repos/cilium/cilium/contents/{+path}","compare_url":"https://api.github.com/repos/cilium/cilium/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cilium/cilium/merges","archive_url":"https://api.github.com/repos/cilium/cilium/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cilium/cilium/downloads","issues_url":"https://api.github.com/repos/cilium/cilium/issues{/number}","pulls_url":"https://api.github.com/repos/cilium/cilium/pulls{/number}","milestones_url":"https://api.github.com/repos/cilium/cilium/milestones{/number}","notifications_url":"https://api.github.com/repos/cilium/cilium/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cilium/cilium/labels{/name}","releases_url":"https://api.github.com/repos/cilium/cilium/releases{/id}","deployments_url":"https://api.github.com/repos/cilium/cilium/deployments","created_at":"2015-12-16T12:33:31Z","updated_at":"2016-09-07T08:48:52Z","pushed_at":"2016-09-07T20:52:22Z","git_url":"git://github.com/cilium/cilium.git","ssh_url":"git@github.com:cilium/cilium.git","clone_url":"https://github.com/cilium/cilium.git","svn_url":"https://github.com/cilium/cilium","homepage":"","size":8916,"stargazers_count":104,"watchers_count":104,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":9,"forks":4,"open_issues":9,"watchers":104,"default_branch":"master"}},"base":{"label":"cilium:master","ref":"master","sha":"0e7a4e6af94a6daab5eeb9b10443fa2bc498f750","user":{"login":"cilium","id":21054566,"avatar_url":"https://avatars.githubusercontent.com/u/21054566?v=3","gravatar_id":"","url":"https://api.github.com/users/cilium","html_url":"https://github.com/cilium","followers_url":"https://api.github.com/users/cilium/followers","following_url":"https://api.github.com/users/cilium/following{/other_user}","gists_url":"https://api.github.com/users/cilium/gists{/gist_id}","starred_url":"https://api.github.com/users/cilium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cilium/subscriptions","organizations_url":"https://api.github.com/users/cilium/orgs","repos_url":"https://api.github.com/users/cilium/repos","events_url":"https://api.github.com/users/cilium/events{/privacy}","received_events_url":"https://api.github.com/users/cilium/received_events","type":"Organization","site_admin":false},"repo":{"id":48109239,"name":"cilium","full_name":"cilium/cilium","owner":{"login":"cilium","id":21054566,"avatar_url":"https://avatars.githubusercontent.com/u/21054566?v=3","gravatar_id":"","url":"https://api.github.com/users/cilium","html_url":"https://github.com/cilium","followers_url":"https://api.github.com/users/cilium/followers","following_url":"https://api.github.com/users/cilium/following{/other_user}","gists_url":"https://api.github.com/users/cilium/gists{/gist_id}","starred_url":"https://api.github.com/users/cilium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cilium/subscriptions","organizations_url":"https://api.github.com/users/cilium/orgs","repos_url":"https://api.github.com/users/cilium/repos","events_url":"https://api.github.com/users/cilium/events{/privacy}","received_events_url":"https://api.github.com/users/cilium/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cilium/cilium","description":"BPF & XDP for containers","fork":false,"url":"https://api.github.com/repos/cilium/cilium","forks_url":"https://api.github.com/repos/cilium/cilium/forks","keys_url":"https://api.github.com/repos/cilium/cilium/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cilium/cilium/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cilium/cilium/teams","hooks_url":"https://api.github.com/repos/cilium/cilium/hooks","issue_events_url":"https://api.github.com/repos/cilium/cilium/issues/events{/number}","events_url":"https://api.github.com/repos/cilium/cilium/events","assignees_url":"https://api.github.com/repos/cilium/cilium/assignees{/user}","branches_url":"https://api.github.com/repos/cilium/cilium/branches{/branch}","tags_url":"https://api.github.com/repos/cilium/cilium/tags","blobs_url":"https://api.github.com/repos/cilium/cilium/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cilium/cilium/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cilium/cilium/git/refs{/sha}","trees_url":"https://api.github.com/repos/cilium/cilium/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cilium/cilium/statuses/{sha}","languages_url":"https://api.github.com/repos/cilium/cilium/languages","stargazers_url":"https://api.github.com/repos/cilium/cilium/stargazers","contributors_url":"https://api.github.com/repos/cilium/cilium/contributors","subscribers_url":"https://api.github.com/repos/cilium/cilium/subscribers","subscription_url":"https://api.github.com/repos/cilium/cilium/subscription","commits_url":"https://api.github.com/repos/cilium/cilium/commits{/sha}","git_commits_url":"https://api.github.com/repos/cilium/cilium/git/commits{/sha}","comments_url":"https://api.github.com/repos/cilium/cilium/comments{/number}","issue_comment_url":"https://api.github.com/repos/cilium/cilium/issues/comments{/number}","contents_url":"https://api.github.com/repos/cilium/cilium/contents/{+path}","compare_url":"https://api.github.com/repos/cilium/cilium/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cilium/cilium/merges","archive_url":"https://api.github.com/repos/cilium/cilium/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cilium/cilium/downloads","issues_url":"https://api.github.com/repos/cilium/cilium/issues{/number}","pulls_url":"https://api.github.com/repos/cilium/cilium/pulls{/number}","milestones_url":"https://api.github.com/repos/cilium/cilium/milestones{/number}","notifications_url":"https://api.github.com/repos/cilium/cilium/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cilium/cilium/labels{/name}","releases_url":"https://api.github.com/repos/cilium/cilium/releases{/id}","deployments_url":"https://api.github.com/repos/cilium/cilium/deployments","created_at":"2015-12-16T12:33:31Z","updated_at":"2016-09-07T08:48:52Z","pushed_at":"2016-09-07T20:52:22Z","git_url":"git://github.com/cilium/cilium.git","ssh_url":"git@github.com:cilium/cilium.git","clone_url":"https://github.com/cilium/cilium.git","svn_url":"https://github.com/cilium/cilium","homepage":"","size":8916,"stargazers_count":104,"watchers_count":104,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":9,"forks":4,"open_issues":9,"watchers":104,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cilium/cilium/pulls/109"},"html":{"href":"https://github.com/cilium/cilium/pull/109"},"issue":{"href":"https://api.github.com/repos/cilium/cilium/issues/109"},"comments":{"href":"https://api.github.com/repos/cilium/cilium/issues/109/comments"},"review_comments":{"href":"https://api.github.com/repos/cilium/cilium/pulls/109/comments"},"review_comment":{"href":"https://api.github.com/repos/cilium/cilium/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cilium/cilium/pulls/109/commits"},"statuses":{"href":"https://api.github.com/repos/cilium/cilium/statuses/4cdf770fe3e4de03855d85e2593ee57fcca03c20"}}}}
{"actor":{"display_login":"aanm"}}