{"id":1013,"date":"2012-04-13T02:16:41","date_gmt":"2012-04-12T17:16:41","guid":{"rendered":"http:\/\/blog.xcir.net\/?p=1013"},"modified":"2012-04-13T02:16:41","modified_gmt":"2012-04-12T17:16:41","slug":"perform-an-acl-match-to-x-forwarded-for-varnish","status":"publish","type":"post","link":"https:\/\/blog.xcir.net\/?p=1013","title":{"rendered":"Perform an ACL match to X-Forwarded-For (varnish)"},"content":{"rendered":"<p>How do ACL match to req.http.X-Forwarded-For? (this is string!!)<br \/>\nI tried to make a vmod.<\/p>\n<p>inet_pton(BOOL ipv6 , STRING str , STRING defaultstr)<\/p>\n<h4>example 1<\/h4>\n<pre class=\"brush: plain; \">\n\r\nimport campur_xcir;\r\n\r\nset resp.http.v6 = campur_xcir.inet_pton(true,&quot;2001:0db8:bd05:01d2:288a:1fc0:0001:10ee&quot;,&quot;1982:db8:20:3:1000:100:20:3&quot;);\r\nset resp.http.v4 = campur_xcir.inet_pton(false,&quot;1.1.1.1&quot;,&quot;2.2.2.2&quot;);\r\nset resp.http.v6ng = campur_xcir.inet_pton(true,&quot;2001:0db8:bd05:01d2:288a:1fc0:0001:10eeHOGE&quot;,&quot;1982:db8:20:3:1000:100:20:3&quot;);\/\/NG pattern\r\nset resp.http.v4ng = campur_xcir.inet_pton(false,&quot;1.1.1.1HOGE&quot;,&quot;2.2.2.2&quot;);\/\/NG pattern\r\n\r\n\/\/result\r\nv6: 2001:db8:bd05:1d2:288a:1fc0:1:10ee\r\nv4: 1.1.1.1\r\nv6ng: 1982:db8:20:3:1000:100:20:3\r\nv4ng: 2.2.2.2\r\n\n<\/pre>\n<h4>example 2<\/h4>\n<pre class=\"brush: plain; \">\n\r\nimport campur_xcir;\r\n\r\n\/\/acl\r\nacl local {\r\n    &quot;192.168.1.0&quot;\/24;\r\n    !&quot;0.0.0.0&quot;;\r\n}\r\n\r\nsub vcl_recv{\r\n  if(campur_xcir.inet_pton(false , req.http.X-Forwarded-For , &quot;0.0.0.0&quot;) ~ local){\r\n      \/\/acl ok\r\n      ...\r\n  }\r\n}\r\n\n<\/pre>\n<p>I hope that this code is of help to you.<br \/>\n<a href=\"https:\/\/github.com\/xcir\/libvmod-campur_xcir\" target=\"_blank\">libvmod-campur_xcir<\/a><\/p>\n<p>this module is my motley function.<br \/>\nOthers, get varnish generated hash etc&#8230;<\/p>\n<p>this vmod&#8217;s function is increase at times. \ud83d\ude42<\/p>\n<div class='wp_social_bookmarking_light'>        <div class=\"wsbl_hatena\"><a href='\/\/b.hatena.ne.jp\/add?mode=confirm&url=https%3A%2F%2Fblog.xcir.net%2F%3Fp%3D1013&title=Perform%20an%20ACL%20match%20to%20X-Forwarded-For%20%28varnish%29' title='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='https:\/\/blog.xcir.net\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/hatena.gif' alt='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' title='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' width='16' height='12' class='wp_social_bookmarking_light_img' \/><\/a><\/div>        <div class=\"wsbl_hatena_users\"><a href='\/\/b.hatena.ne.jp\/entry\/https:\/\/blog.xcir.net\/?p=1013' title='\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af - Perform an ACL match to X-Forwarded-For (varnish)' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='\/\/b.hatena.ne.jp\/entry\/image\/https:\/\/blog.xcir.net\/?p=1013' alt='\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af - Perform an ACL match to X-Forwarded-For (varnish)' title='\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af - Perform an ACL match to X-Forwarded-For (varnish)'   class='wp_social_bookmarking_light_img' \/><\/a><\/div>        <div class=\"wsbl_facebook\"><a href='http:\/\/www.facebook.com\/share.php?u=https%3A%2F%2Fblog.xcir.net%2F%3Fp%3D1013&t=Perform%20an%20ACL%20match%20to%20X-Forwarded-For%20%28varnish%29' title='Facebook \u306b\u30b7\u30a7\u30a2' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='https:\/\/blog.xcir.net\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/facebook.png' alt='Facebook \u306b\u30b7\u30a7\u30a2' title='Facebook \u306b\u30b7\u30a7\u30a2' width='16' height='16' class='wp_social_bookmarking_light_img' \/><\/a><\/div>        <div class=\"wsbl_linkedin\"><a href='\/\/www.linkedin.com\/shareArticle?mini=true&url=https%3A%2F%2Fblog.xcir.net%2F%3Fp%3D1013&title=Perform%20an%20ACL%20match%20to%20X-Forwarded-For%20%28varnish%29' title='LinkedIn \u306b\u30b7\u30a7\u30a2' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='https:\/\/blog.xcir.net\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/linkedin.png' alt='LinkedIn \u306b\u30b7\u30a7\u30a2' title='LinkedIn \u306b\u30b7\u30a7\u30a2' width='16' height='16' class='wp_social_bookmarking_light_img' \/><\/a><\/div>        <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/blog.xcir.net\/?p=1013\" data-text=\"Perform an ACL match to X-Forwarded-For (varnish)\" data-lang=\"ja\">Tweet<\/a><\/div><\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>How do ACL match to req.http.X-Forwarded-For? (this is string!!) I tried to make a vmod. inet_pton(BOOL ipv6 , <a href='https:\/\/blog.xcir.net\/?p=1013' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,3],"tags":[5,34,40],"class_list":["post-1013","post","type-post","status-publish","format-standard","hentry","category-english","category-3","tag-varnish","tag-vmod","tag-vmod_campur_xcir","category-24-id","category-3-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/posts\/1013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.xcir.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1013"}],"version-history":[{"count":3,"href":"https:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/posts\/1013\/revisions"}],"predecessor-version":[{"id":1016,"href":"https:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/posts\/1013\/revisions\/1016"}],"wp:attachment":[{"href":"https:\/\/blog.xcir.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.xcir.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.xcir.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}