<commit_before># -----------------------------------------------------------------
# NAT Traversal Section
# -----------------------------------------------------------------

route[bye-cancel-prack-nat] # NAT traversal for BYE/CANCEL/PRACK
{
    xlog("L_DBG","DEBUG -- route(bye-cancel-prack-nat) -- NAT traversal for BYE/CANCEL/PRACK");

    # NAT test 1 = RFC1918 IP in Contact ?
    # NAT test 2 = From address != 1st Via ?
    if (client_nat_test("3"))
    {
        xlog("L_DBG","DEBUG -- route(bye-cancel-prack-nat) -- $rm client is behind NAT");
        force_rport();
        fix_contact();
    };
}

route[lr-nat] # NAT traversal for loose-routed messages
{
  # Handle NAT on re-INVITE or LR ACK
  if( is_method("INVITE") || is_method("ACK") )
  {
      xlog("L_DBG","DEBUG -- route(loose-route-handler): Testing NAT on LR INVITE or LR ACK");
      # NAT test 1 = RFC1918 IP in Contact ?
      # NAT test 2 = From address != 1st Via
      if( client_nat_test("3") )
      {
          xlog("L_DBG","DEBUG -- route(loose-route-handler): originator is NATed");
          route(lr-invite-ack-nat);
      }

      route(update-media-proxy);   # Update media session if needed
  }
  if( is_method("SUBSCRIBE") )
  {
    xlog("L_DBG","DEBUG -- route(loose-route-handler): Testing NAT on LR SUBSCRIBE");
    # NAT test 1 = RFC1918 IP in Contact ?
    # NAT test 2 = From address != 1st Via
    if( client_nat_test("3") )
    {
        xlog("L_DBG","DEBUG -- route(loose-route-handler): originator is NATed");
        force_rport();
        fix_contact();
        if(proto==UDP)
        {
          nat_keepalive();
        }
    }
  }
}

route[initial-invite-nat] # NAT traversal for initial INVITE
{
  xlog("L_DBG","DEBUG -- route(initial-invite-nat) -- NAT tests for INVITE");
  # NAT tests:
  # NAT test 1 = RFC1918 IP in Contact ?
  # NAT test 2 = From address != 1st Via
  if (client_nat_test("3") && !search("^Record-Route:"))
  {
      # Trusted nodes should never be behind NAT (they can't be trusted if that's the case).
      if(allow_trusted()) # see authenticate.cfg: IP-based authentication
      {
          xlog("L_ERR","ERROR -- route(invite-handler): Trusted caller $si ($fu) is behind NAT.");
          sl_send_reply("100", "It appears you are located behind NAT. Media issues may appear.");
      }
      else
      {
          xlog("L_DBG","DEBUG -- route(invite-handler): Caller is NATed");
          route(lr-invite-ack-nat);
      }
  }
}

route[lr-invite-ack-nat] # NAT traversal for loose-routed INVITE/ACK
{
    xlog("L_DBG","DEBUG -- route(lr-invite-ack-nat) -- NAT traversal for loose-routed INVITE/ACK");
    setflag(7); # caller is NATed: force MP
    add_rr_param(";mp=yes");
    force_rport();
    fix_contact();
    if(proto==UDP)
    {
      nat_keepalive();
    }
}

route[register-nat]
{
  # NAT test 1 = RFC1918 IP in Contact ?
  # NAT test 2 = From address != 1st Via ?
  # NAT test 4 = RFC1918 in top Via ?
  if (client_nat_test("7") && !search("^Contact:[ ]*\*"))
  {
      xlog("L_DBG","DEBUG -- route(register-handler): Registering device is NATed");
      setbflag(6); # endpoint is NATed (stored in the database by registrar)
      force_rport();
      fix_contact(); # Testing
      if(proto==UDP)
      {
        nat_keepalive();
      }
      $avp(nathelper) = $source_uri;
  };
}

route[onreply-nat]
{
      # NAT test 1 = RFC1918 IP in Contact ?
      if( client_nat_test("1") )
      {
  #        nat_keepalive();
          fix_contact();
      }
}<commit_msg>Trying to handle REGISTER with client that does not support/detect NAT<commit_after># -----------------------------------------------------------------
# NAT Traversal Section
# -----------------------------------------------------------------

route[bye-cancel-prack-nat] # NAT traversal for BYE/CANCEL/PRACK
{
    xlog("L_DBG","DEBUG -- route(bye-cancel-prack-nat) -- NAT traversal for BYE/CANCEL/PRACK");

    # NAT test 1 = RFC1918 IP in Contact ?
    # NAT test 2 = From address != 1st Via ?
    if (client_nat_test("3"))
    {
        xlog("L_DBG","DEBUG -- route(bye-cancel-prack-nat) -- $rm client is behind NAT");
        force_rport();
        fix_contact();
    };
}

route[lr-nat] # NAT traversal for loose-routed messages
{
  # Handle NAT on re-INVITE or LR ACK
  if( is_method("INVITE") || is_method("ACK") )
  {
      xlog("L_DBG","DEBUG -- route(loose-route-handler): Testing NAT on LR INVITE or LR ACK");
      # NAT test 1 = RFC1918 IP in Contact ?
      # NAT test 2 = From address != 1st Via
      if( client_nat_test("3") )
      {
          xlog("L_DBG","DEBUG -- route(loose-route-handler): originator is NATed");
          route(lr-invite-ack-nat);
      }

      route(update-media-proxy);   # Update media session if needed
  }
  if( is_method("SUBSCRIBE") )
  {
    xlog("L_DBG","DEBUG -- route(loose-route-handler): Testing NAT on LR SUBSCRIBE");
    # NAT test 1 = RFC1918 IP in Contact ?
    # NAT test 2 = From address != 1st Via
    if( client_nat_test("3") )
    {
        xlog("L_DBG","DEBUG -- route(loose-route-handler): originator is NATed");
        force_rport();
        fix_contact();
        if(proto==UDP)
        {
          nat_keepalive();
        }
    }
  }
}

route[initial-invite-nat] # NAT traversal for initial INVITE
{
  xlog("L_DBG","DEBUG -- route(initial-invite-nat) -- NAT tests for INVITE");
  # NAT tests:
  # NAT test 1 = RFC1918 IP in Contact ?
  # NAT test 2 = From address != 1st Via
  if (client_nat_test("3") && !search("^Record-Route:"))
  {
      # Trusted nodes should never be behind NAT (they can't be trusted if that's the case).
      if(allow_trusted()) # see authenticate.cfg: IP-based authentication
      {
          xlog("L_ERR","ERROR -- route(invite-handler): Trusted caller $si ($fu) is behind NAT.");
          sl_send_reply("100", "It appears you are located behind NAT. Media issues may appear.");
      }
      else
      {
          xlog("L_DBG","DEBUG -- route(invite-handler): Caller is NATed");
          route(lr-invite-ack-nat);
      }
  }
}

route[lr-invite-ack-nat] # NAT traversal for loose-routed INVITE/ACK
{
    xlog("L_DBG","DEBUG -- route(lr-invite-ack-nat) -- NAT traversal for loose-routed INVITE/ACK");
    setflag(7); # caller is NATed: force MP
    add_rr_param(";mp=yes");
    force_rport();
    fix_contact();
    if(proto==UDP)
    {
      nat_keepalive();
    }
}

route[register-nat]
{
  # NAT test 1 = RFC1918 IP in Contact ?
  # NAT test 2 = From address != 1st Via ?
  # NAT test 4 = RFC1918 in top Via ?
  if (client_nat_test("7") && !search("^Contact:[ ]*\*"))
  {
      xlog("L_DBG","DEBUG -- route(register-handler): Registering device is NATed");
      setbflag(6); # endpoint is NATed (stored in the database by registrar)
      # ";rport=$sp" # also $dp
      add_local_rport();
      force_rport();
      fix_contact(); # Testing
      if(proto==UDP)
      {
        nat_keepalive();
      }
      $avp(nathelper) = $source_uri;
  };
}

route[onreply-nat]
{
      # NAT test 1 = RFC1918 IP in Contact ?
      if( client_nat_test("1") )
      {
  #        nat_keepalive();
          fix_contact();
      }
}
{'fraction_non_alphanumeric': 0.17848136732978426, 'fraction_numerical': 0.015690669655365648, 'mean_word_length': 2.2361740707162285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6160098', 'n_tokens_mistral': 2505, 'n_tokens_neox': 2361, 'n_words': 596}