<p><b>@henningw</b> commented on this pull request.</p>

<p>I Haven't tested it, but the parsing part looks like a solid and good implementation. I have added one small remark in the code, and have some general questions:</p>
<ul>
<li>You work on a local pointer src_ip and dst_ip in the parsing part, but directly on the c->rcv.src_port/c->rcv.dst_port - is there a particular reasons for it?</li>
<li>related to error cases, what would happen if you e.g. set in the IPv6 case 0x21 the dst_ip->af = AF_INET6, but later one run unto an error in the parsing. Then you would return an error to the callee, and would go to the read_ip_info path. Here the AF_INET6 would be still be set, or I am wrong? What about just setting all the data into a temporary variable, and then if the parsing was completed successfully, set it.</li>
<li>why you set the c->rcv.bind_address=ba; in line 1221?</li>
</ul><hr>

<p>In <a href="https://github.com/kamailio/kamailio/pull/1765#discussion_r241947452">src/core/tcp_main.c</a>:</p>
<pre style='color:#555'>> -    if (likely(local_addr)){
-               su2ip_addr(&c->rcv.dst_ip, local_addr);
-               c->rcv.dst_port=su_getport(local_addr);
-       }else if (ba){
-               c->rcv.dst_ip=ba->address;
-               c->rcv.dst_port=ba->port_no;
+       if (unlikely(ksr_tcp_accept_haproxy && state == S_CONN_ACCEPT)) {
+               ret = tcpconn_read_haproxy(c);
+
+               if (ret == -1) {
+                       LM_ERR("invalid PROXY protocol header\n");
+                       goto error;
+               } else if (ret == 1) {
+                       LM_DBG("PROXY protocol did not override IP addresses\n");
+                       goto read_ip_info;
+               }
</pre>
<p>Small suggestion, add a LM_DBG output here, that the tcpconn_read_haproxy call was successful.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/pull/1765#pullrequestreview-185352625">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36Zdf0w013usGo4E5CRjif_QABNAdGks5u5Ot7gaJpZM4ZR-BH">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZafyfE7Aw6huRYdcdkLU2mRoqukbks5u5Ot7gaJpZM4ZR-BH.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"PERSON","message":"@henningw commented on #1765"}],"action":{"name":"View Pull Request","url":"https://github.com/kamailio/kamailio/pull/1765#pullrequestreview-185352625"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/pull/1765#pullrequestreview-185352625",
"url": "https://github.com/kamailio/kamailio/pull/1765#pullrequestreview-185352625",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>