Skip to content

Commit f0dfc24

Browse files
Revert "proto_ipsec: Add IPSec NAT Traversal (NAT-T) support"
This reverts commit 49bc814.
1 parent 49bc814 commit f0dfc24

File tree

6 files changed

+21
-329
lines changed

6 files changed

+21
-329
lines changed

modules/proto_ipsec/doc/proto_ipsec_admin.xml

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818
specification (GSMA PRD IR.92) and implements the extensions defined
1919
in TS 33.203 (3G Security: Access Security for IP-based Services).
2020
</para>
21-
<para>
22-
The module also supports <emphasis role='bold'>IPSec NAT Traversal (NAT-T)</emphasis>
23-
as specified in 3GPP TS 33.203 Annex M and TS 24.229. When NAT-T is enabled,
24-
the module can accept and use the <emphasis>mod=UDP-enc-tun</emphasis> mode
25-
in Security-Client headers, which encapsulates ESP packets in UDP datagrams
26-
(as per RFC 3948) to traverse NAT devices. This feature is optional and can
27-
be enabled via the <xref linkend="param_nat_traversal"/> parameter.
28-
</para>
2921
<para>
3022
It allows creation of both UDP and TCP secure connections on the same
3123
IP:port pair, defined as sockets. Essentially, when defining a socket
@@ -360,58 +352,6 @@ modparam("proto_ipsec", "disable_deprecated_algorithms", yes)
360352
</example>
361353
</section>
362354

363-
<section id="param_nat_traversal" xreflabel="nat_traversal">
364-
<title><varname>nat_traversal</varname> (integer)</title>
365-
<para>
366-
Enables or disables IPSec NAT Traversal (NAT-T) support according to
367-
3GPP TS 33.203 Annex M and TS 24.229.
368-
</para>
369-
<para>
370-
When enabled (set to 1), the module will:
371-
<itemizedlist>
372-
<listitem>
373-
<para>
374-
Accept <emphasis>mod=UDP-enc-tun</emphasis> in Security-Client headers
375-
</para>
376-
</listitem>
377-
<listitem>
378-
<para>
379-
Use UDP encapsulation for ESP packets (RFC 3948) when NAT-T mode is negotiated
380-
</para>
381-
</listitem>
382-
<listitem>
383-
<para>
384-
Use tunnel mode instead of transport mode for IPSec SAs
385-
</para>
386-
</listitem>
387-
<listitem>
388-
<para>
389-
Include <emphasis>mod=UDP-enc-tun</emphasis> in Security-Server headers
390-
when the UE requests NAT-T mode
391-
</para>
392-
</listitem>
393-
</itemizedlist>
394-
</para>
395-
<para>
396-
When disabled (set to 0, default), only <emphasis>mod=trans</emphasis>
397-
(standard transport mode) is accepted in Security-Client headers.
398-
</para>
399-
<para>
400-
<emphasis>
401-
Default value is 0 (disabled).
402-
</emphasis>
403-
</para>
404-
<example>
405-
<title>Set <varname>nat_traversal</varname> parameter</title>
406-
<programlisting format="linespecific">
407-
...
408-
# Enable NAT Traversal support for UEs behind NAT
409-
modparam("proto_ipsec", "nat_traversal", 1)
410-
...
411-
</programlisting>
412-
</example>
413-
</section>
414-
415355
</section>
416356

417357
<section id="exported_functions" xreflabel="exported_functions">
@@ -514,21 +454,16 @@ onreply_route[ipsec] {
514454
<listitem><para><emphasis>port-c</emphasis> - local port
515455
chosen for communicating through the client channel.
516456
</para></listitem>
517-
<listitem><para><emphasis>port-s</emphasis> - local port
457+
<listitem><para><emphasis>port-c</emphasis> - local port
518458
chosen for communicating through the server channel.
519459
</para></listitem>
520-
<listitem><para><emphasis>mode</emphasis> - IPSec mode being used:
521-
<emphasis>trans</emphasis> for transport mode or
522-
<emphasis>UDP-enc-tun</emphasis> for NAT-T tunnel mode
523-
(as per 3GPP TS 33.203 Annex M).
524-
</para></listitem>
525460
</itemizedlist>
526461
</para>
527462
<example>
528463
<title><function>$ipsec(field)</function> usage</title>
529464
<programlisting format="linespecific">
530465
...
531-
xlog("Using $ipsec(ip):$ipsec(port-c) and $ipsec(ip):$ipsec(port-s) socket, mode=$ipsec(mode)\n");
466+
xlog("Using $ipsec(ip):$ipsec(port-c) and $ipsec(ip):$ipsec(port-s) socket\n");
532467
...
533468
</programlisting>
534469
</example>
@@ -567,21 +502,16 @@ xlog("Using $ipsec(ip):$ipsec(port-c) and $ipsec(ip):$ipsec(port-s) socket, mode
567502
<listitem><para><emphasis>port-c</emphasis> - remote port
568503
chosen for communicating through the client channel.
569504
</para></listitem>
570-
<listitem><para><emphasis>port-s</emphasis> - remote port
505+
<listitem><para><emphasis>port-c</emphasis> - remote port
571506
chosen for communicating through the server channel.
572507
</para></listitem>
573-
<listitem><para><emphasis>mode</emphasis> - IPSec mode being used:
574-
<emphasis>trans</emphasis> for transport mode or
575-
<emphasis>UDP-enc-tun</emphasis> for NAT-T tunnel mode
576-
(as per 3GPP TS 33.203 Annex M).
577-
</para></listitem>
578508
</itemizedlist>
579509
</para>
580510
<example>
581511
<title><function>$ipsec_ue(field)</function> usage</title>
582512
<programlisting format="linespecific">
583513
...
584-
xlog("UE $ipsec_ue(ip):$ipsec_ue(port-c) and $ipsec_ue(ip):$ipsec_ue(port-s), mode=$ipsec_ue(mode)\n");
514+
xlog("Using $ipsec_ue(ip):$ipsec_ue(port-c) and $ipsec_ue(ip):$ipsec_ue(port-s) socket\n");
585515
...
586516
</programlisting>
587517
</example>

modules/proto_ipsec/ipsec.c

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -392,21 +392,6 @@ struct xfrm_algo_osips {
392392
static_assert(sizeof(struct xfrm_algo_osips) == sizeof(struct xfrm_algo)
393393
+ IPSEC_ALGO_MAX_KEY_SIZE, "ERROR! Unexpected 'xfrm_algo' size!");
394394

395-
/*
396-
* NAT-T (NAT Traversal) support according to:
397-
* - 3GPP TS 33.203 Annex M: IPsec NAT traversal
398-
* - 3GPP TS 24.229: IP multimedia call control protocol
399-
* - RFC 3948: UDP Encapsulation of IPsec ESP Packets
400-
*
401-
* When NAT-T mode (mod=UDP-enc-tun) is used:
402-
* - ESP packets are encapsulated in UDP (port 4500 typically)
403-
* - Tunnel mode is used instead of transport mode
404-
* - XFRMA_ENCAP attribute is added to the SA
405-
*/
406-
#ifndef UDP_ENCAP_ESPINUDP
407-
#define UDP_ENCAP_ESPINUDP 2 /* RFC 3948 */
408-
#endif
409-
410395
int ipsec_sa_add(struct mnl_socket *sock, struct ipsec_ctx *ctx,
411396
enum ipsec_dir dir, int client)
412397
{
@@ -416,12 +401,10 @@ int ipsec_sa_add(struct mnl_socket *sock, struct ipsec_ctx *ctx,
416401
struct xfrm_userpolicy_info *policy_info;
417402
struct xfrm_algo_osips ia, ie;
418403
struct xfrm_user_tmpl tmpl;
419-
struct xfrm_encap_tmpl encap;
420404
unsigned short dst_port;
421405
unsigned short src_port;
422406
unsigned int spi;
423407
struct ipsec_endpoint *src, *dst;
424-
int xfrm_mode;
425408

426409
if (dir == IPSEC_POLICY_IN) {
427410
src = &ctx->ue;
@@ -527,41 +510,13 @@ int ipsec_sa_add(struct mnl_socket *sock, struct ipsec_ctx *ctx,
527510
sa_info->reqid = htonl(spi);
528511
sa_info->family = dst->ip.af;
529512
sa_info->replay_window = 32;
530-
531-
/*
532-
* Set mode according to NAT-T configuration:
533-
* - Transport mode (mod=trans): Standard IPsec transport mode
534-
* - Tunnel mode (mod=UDP-enc-tun): NAT-T with UDP encapsulation
535-
* as per 3GPP TS 33.203 Annex M
536-
*/
537-
if (ctx->mode == IPSEC_MODE_UDP_ENCAP_TUNNEL) {
538-
xfrm_mode = XFRM_MODE_TUNNEL;
539-
sa_info->flags |= XFRM_STATE_NOPMTUDISC;
540-
} else {
541-
xfrm_mode = XFRM_MODE_TRANSPORT;
542-
}
543-
sa_info->mode = xfrm_mode;
513+
sa_info->mode = XFRM_MODE_TRANSPORT;
544514

545515
mnl_attr_put(nlh, XFRMA_ALG_AUTH,
546516
sizeof(struct xfrm_algo) + ia.alg_key_len, &ia);
547517
mnl_attr_put(nlh, XFRMA_ALG_CRYPT,
548518
sizeof(struct xfrm_algo) + ie.alg_key_len, &ie);
549519

550-
/*
551-
* NAT-T UDP Encapsulation (3GPP TS 33.203 Annex M, RFC 3948)
552-
* When mod=UDP-enc-tun is negotiated, ESP packets are encapsulated
553-
* in UDP datagrams to traverse NAT devices.
554-
*/
555-
if (ctx->mode == IPSEC_MODE_UDP_ENCAP_TUNNEL) {
556-
memset(&encap, 0, sizeof(encap));
557-
encap.encap_type = UDP_ENCAP_ESPINUDP;
558-
encap.encap_sport = htons(src_port);
559-
encap.encap_dport = htons(dst_port);
560-
/* OA (Original Address) - set to zero, kernel fills if needed */
561-
mnl_attr_put(nlh, XFRMA_ENCAP, sizeof(encap), &encap);
562-
LM_DBG("NAT-T encapsulation: sport=%hu dport=%hu\n", src_port, dst_port);
563-
}
564-
565520
if (mnl_socket_sendto(sock, nlh, nlh->nlmsg_len) < 0) {
566521
LM_ERR("communicating with kernel for new SA: %s\n", strerror(errno));
567522
goto error;
@@ -605,7 +560,7 @@ int ipsec_sa_add(struct mnl_socket *sock, struct ipsec_ctx *ctx,
605560
tmpl.family = dst->ip.af;
606561
memcpy(&tmpl.saddr, &src->ip.u, src->ip.len);
607562
tmpl.reqid = htonl(spi);
608-
tmpl.mode = xfrm_mode; /* Transport or Tunnel mode based on NAT-T */
563+
tmpl.mode = XFRM_MODE_TRANSPORT;
609564
tmpl.share = XFRM_SHARE_ANY;
610565
tmpl.optional = 0;
611566
tmpl.aalgos = 0xffffffff;
@@ -693,7 +648,7 @@ static void ipsec_ctx_free(struct ipsec_ctx *ctx)
693648

694649
struct ipsec_ctx *ipsec_ctx_new(sec_agree_body_t *sa, struct ip_addr *ip,
695650
struct socket_info *ss, struct socket_info *sc, str *ck, str *ik,
696-
unsigned int spi_pc, unsigned int spi_ps, enum ipsec_mode mode)
651+
unsigned int spi_pc, unsigned int spi_ps)
697652
{
698653
struct ipsec_spi *spi_s, *spi_c;
699654
struct ipsec_ctx *ctx;
@@ -755,7 +710,6 @@ struct ipsec_ctx *ipsec_ctx_new(sec_agree_body_t *sa, struct ip_addr *ip,
755710
ctx->client = sc;
756711
ctx->alg = alg;
757712
ctx->ealg = ealg;
758-
ctx->mode = mode;
759713
/* own information - shortcut */
760714
memcpy(&ctx->me.ip, &sc->address, sizeof(struct ip_addr));
761715
ctx->me.spi_s = spi_s->spi;

modules/proto_ipsec/ipsec.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,6 @@ enum ipsec_state {
4242
IPSEC_STATE_INVALID,
4343
};
4444

45-
/*
46-
* IPSec mode according to 3GPP TS 33.203 Annex H/M:
47-
* - IPSEC_MODE_TRANSPORT: mod=trans (standard transport mode)
48-
* - IPSEC_MODE_UDP_ENCAP_TUNNEL: mod=UDP-enc-tun (NAT-T mode with UDP encapsulation)
49-
*/
50-
enum ipsec_mode {
51-
IPSEC_MODE_TRANSPORT = 0,
52-
IPSEC_MODE_UDP_ENCAP_TUNNEL,
53-
};
54-
55-
/* NAT-T encapsulation port (RFC 3948) */
56-
#define IPSEC_NAT_T_PORT 4500
57-
58-
#define VALID_IPSEC_STATE(_s) \
59-
((_s) == IPSEC_STATE_TMP || \
60-
(_s) == IPSEC_STATE_OK)
61-
6245
#define ipsec_socket mnl_socket
6346

6447
#include "../../str.h"
@@ -80,7 +63,6 @@ struct ipsec_ctx {
8063
struct ipsec_algorithm_desc *alg, *ealg;
8164
struct ipsec_endpoint me;
8265
struct ipsec_endpoint ue;
83-
enum ipsec_mode mode; /* transport or UDP-enc-tun (NAT-T) */
8466

8567
/* dynamic values - should be locked */
8668
gen_lock_t lock;
@@ -134,7 +116,7 @@ void ipsec_sa_rm_all(struct ipsec_socket *sock, struct ipsec_ctx *ctx);
134116
/* ctx */
135117
struct ipsec_ctx *ipsec_ctx_new(sec_agree_body_t *sa, struct ip_addr *ip,
136118
struct socket_info *ss, struct socket_info *sc, str *ck, str *ik,
137-
unsigned int spi_pc, unsigned int spi_ps, enum ipsec_mode mode);
119+
unsigned int spi_pc, unsigned int spi_ps);
138120
struct ipsec_ctx *ipsec_ctx_find(struct ipsec_user *user, unsigned short port);
139121
void ipsec_ctx_push(struct ipsec_ctx *ctx);
140122
struct ipsec_ctx *ipsec_ctx_get(void);
@@ -144,9 +126,7 @@ void ipsec_ctx_release_tmp_user(struct ipsec_user *user);
144126
void ipsec_ctx_release_user(struct ipsec_ctx *ctx);
145127
void ipsec_ctx_release(struct ipsec_ctx *ctx);
146128
int ipsec_ctx_release_unsafe(struct ipsec_ctx *ctx);
147-
void ipsec_ctx_add_tmp(struct ipsec_ctx *ctx);
148129
void ipsec_ctx_remove_tmp(struct ipsec_ctx *ctx);
149-
void ipsec_ctx_remove_free_tmp(struct ipsec_ctx *ctx, int _free);
150130
void ipsec_ctx_extend_tmp(struct ipsec_ctx *ctx);
151131

152132
#endif /* _IPSEC_H_ */

modules/proto_ipsec/ipsec_algo.c

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -73,39 +73,6 @@
7373
#define IPSEC_ALGO_MAX_KEY_SIZE IPSEC_ALGO_DES3_KEY_SIZE
7474

7575
int ipsec_disable_deprecated_algorithms = 0;
76-
/* NAT-T support flag - defined in proto_ipsec.c, declared in ipsec_algo.h */
77-
78-
/*
79-
* Validate IPSec mode from Security-Client header
80-
* According to 3GPP TS 33.203 Annex H/M:
81-
* - "trans": Transport mode (always accepted)
82-
* - "UDP-enc-tun": UDP-encapsulated tunnel mode (only if NAT-T enabled)
83-
*/
84-
static int ipsec_validate_mode(str *mod_str)
85-
{
86-
static str trans_str = str_init("trans");
87-
static str udp_enc_tun_str = str_init("UDP-enc-tun");
88-
89-
if (!mod_str || !mod_str->len) {
90-
/* No mode specified - default to transport, acceptable */
91-
return 0;
92-
}
93-
94-
if (str_casematch(mod_str, &trans_str)) {
95-
return 0; /* Transport mode always accepted */
96-
}
97-
98-
if (str_casematch(mod_str, &udp_enc_tun_str)) {
99-
if (ipsec_nat_traversal_enabled) {
100-
return 0; /* NAT-T mode accepted when enabled */
101-
}
102-
LM_DBG("NAT-T mode (UDP-enc-tun) not accepted - nat_traversal disabled\n");
103-
return -1;
104-
}
105-
106-
LM_DBG("unknown IPSec mode: %.*s\n", mod_str->len, mod_str->s);
107-
return -1;
108-
}
10976

11077
static struct ipsec_algorithm_desc ipsec_auth_algorithms[] = {
11178
{
@@ -319,12 +286,7 @@ sec_agree_body_t *ipsec_get_security_client(struct sip_msg *msg, struct ipsec_al
319286
for (sa = sas; sa; sa = sa->next) {
320287
if (sa->invalid || sa->mechanism != SEC_AGREE_MECHANISM_IPSEC_3GPP)
321288
continue;
322-
/* Validate mode (trans or UDP-enc-tun per 3GPP TS 33.203) */
323-
if (ipsec_validate_mode(&sa->ts3gpp.mod_str) < 0) {
324-
LM_DBG("unsupported mode %.*s in Security-Client\n",
325-
sa->ts3gpp.mod_str.len, sa->ts3gpp.mod_str.s);
326-
continue;
327-
}
289+
/* TODO: should we check mode for now? */
328290
if (!sa->ts3gpp.alg_str.len)
329291
continue;
330292
alg_desc = ipsec_parse_algorithm(&sa->ts3gpp.alg_str, IPSEC_ALGO_TYPE_AUTH);
@@ -372,12 +334,7 @@ sec_agree_body_t *ipsec_get_security_client(struct sip_msg *msg, struct ipsec_al
372334
for (sa = sas; sa; sa = sa->next) {
373335
if (sa->invalid || sa->mechanism != SEC_AGREE_MECHANISM_IPSEC_3GPP)
374336
continue;
375-
/* Validate mode (trans or UDP-enc-tun per 3GPP TS 33.203) */
376-
if (ipsec_validate_mode(&sa->ts3gpp.mod_str) < 0) {
377-
LM_DBG("unsupported mode %.*s in Security-Client\n",
378-
sa->ts3gpp.mod_str.len, sa->ts3gpp.mod_str.s);
379-
continue;
380-
}
337+
/* TODO: should we check mode for now? */
381338
if (!sa->ts3gpp.alg_str.len)
382339
continue;
383340
auth = ipsec_parse_algorithm(&sa->ts3gpp.alg_str, IPSEC_ALGO_TYPE_AUTH);

modules/proto_ipsec/ipsec_algo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,5 @@ sec_agree_body_t *ipsec_get_security_client(struct sip_msg *msg, struct ipsec_al
9494
void ipsec_free_allowed_algorithms(struct ipsec_allowed_algo *algos);
9595

9696
extern int ipsec_disable_deprecated_algorithms;
97-
extern int ipsec_nat_traversal_enabled; /* NAT-T support enabled */
9897

9998
#endif /* _IPSEC_ALGO_H_ */

0 commit comments

Comments
 (0)