Patrick McHardy | 9fafcd7 | 2006-12-02 22:09:57 -0800 | [diff] [blame] | 1 | #ifndef __NF_CONNTRACK_SIP_H__ |
| 2 | #define __NF_CONNTRACK_SIP_H__ |
| 3 | #ifdef __KERNEL__ |
| 4 | |
Pablo Neira Ayuso | 1afc567 | 2012-06-07 12:11:50 +0200 | [diff] [blame] | 5 | #include <net/netfilter/nf_conntrack_expect.h> |
| 6 | |
Patrick McHardy | 9fafcd7 | 2006-12-02 22:09:57 -0800 | [diff] [blame] | 7 | #define SIP_PORT 5060 |
| 8 | #define SIP_TIMEOUT 3600 |
| 9 | |
Patrick McHardy | 0f32a40 | 2008-03-25 20:25:13 -0700 | [diff] [blame] | 10 | struct nf_ct_sip_master { |
| 11 | unsigned int register_cseq; |
Patrick McHardy | ef75d49 | 2008-05-08 01:15:21 -0700 | [diff] [blame] | 12 | unsigned int invite_cseq; |
Patrick McHardy | 0f32a40 | 2008-03-25 20:25:13 -0700 | [diff] [blame] | 13 | }; |
| 14 | |
| 15 | enum sip_expectation_classes { |
| 16 | SIP_EXPECT_SIGNALLING, |
| 17 | SIP_EXPECT_AUDIO, |
Patrick McHardy | 0d0ab03 | 2008-03-25 20:26:24 -0700 | [diff] [blame] | 18 | SIP_EXPECT_VIDEO, |
Patrick McHardy | 9d288df | 2010-02-11 12:30:21 +0100 | [diff] [blame] | 19 | SIP_EXPECT_IMAGE, |
Patrick McHardy | 0f32a40 | 2008-03-25 20:25:13 -0700 | [diff] [blame] | 20 | __SIP_EXPECT_MAX |
| 21 | }; |
| 22 | #define SIP_EXPECT_MAX (__SIP_EXPECT_MAX - 1) |
| 23 | |
Patrick McHardy | 0d0ab03 | 2008-03-25 20:26:24 -0700 | [diff] [blame] | 24 | struct sdp_media_type { |
| 25 | const char *name; |
| 26 | unsigned int len; |
| 27 | enum sip_expectation_classes class; |
| 28 | }; |
| 29 | |
| 30 | #define SDP_MEDIA_TYPE(__name, __class) \ |
| 31 | { \ |
| 32 | .name = (__name), \ |
| 33 | .len = sizeof(__name) - 1, \ |
| 34 | .class = (__class), \ |
| 35 | } |
| 36 | |
Patrick McHardy | 30f33e6 | 2008-03-25 20:22:20 -0700 | [diff] [blame] | 37 | struct sip_handler { |
| 38 | const char *method; |
| 39 | unsigned int len; |
Patrick McHardy | 3b6b9fa | 2010-02-11 12:23:53 +0100 | [diff] [blame] | 40 | int (*request)(struct sk_buff *skb, unsigned int dataoff, |
Patrick McHardy | 30f33e6 | 2008-03-25 20:22:20 -0700 | [diff] [blame] | 41 | const char **dptr, unsigned int *datalen, |
| 42 | unsigned int cseq); |
Patrick McHardy | 3b6b9fa | 2010-02-11 12:23:53 +0100 | [diff] [blame] | 43 | int (*response)(struct sk_buff *skb, unsigned int dataoff, |
Patrick McHardy | 30f33e6 | 2008-03-25 20:22:20 -0700 | [diff] [blame] | 44 | const char **dptr, unsigned int *datalen, |
| 45 | unsigned int cseq, unsigned int code); |
| 46 | }; |
| 47 | |
| 48 | #define SIP_HANDLER(__method, __request, __response) \ |
| 49 | { \ |
| 50 | .method = (__method), \ |
| 51 | .len = sizeof(__method) - 1, \ |
| 52 | .request = (__request), \ |
| 53 | .response = (__response), \ |
| 54 | } |
| 55 | |
Patrick McHardy | 3e9b4600b | 2008-03-25 20:17:55 -0700 | [diff] [blame] | 56 | struct sip_header { |
| 57 | const char *name; |
| 58 | const char *cname; |
| 59 | const char *search; |
| 60 | unsigned int len; |
| 61 | unsigned int clen; |
| 62 | unsigned int slen; |
| 63 | int (*match_len)(const struct nf_conn *ct, |
| 64 | const char *dptr, const char *limit, |
| 65 | int *shift); |
| 66 | }; |
| 67 | |
| 68 | #define __SIP_HDR(__name, __cname, __search, __match) \ |
| 69 | { \ |
| 70 | .name = (__name), \ |
| 71 | .len = sizeof(__name) - 1, \ |
| 72 | .cname = (__cname), \ |
| 73 | .clen = (__cname) ? sizeof(__cname) - 1 : 0, \ |
| 74 | .search = (__search), \ |
| 75 | .slen = (__search) ? sizeof(__search) - 1 : 0, \ |
| 76 | .match_len = (__match), \ |
| 77 | } |
| 78 | |
Patrick McHardy | ea45f12 | 2008-03-25 20:18:57 -0700 | [diff] [blame] | 79 | #define SIP_HDR(__name, __cname, __search, __match) \ |
| 80 | __SIP_HDR(__name, __cname, __search, __match) |
| 81 | |
Patrick McHardy | 3e9b4600b | 2008-03-25 20:17:55 -0700 | [diff] [blame] | 82 | #define SDP_HDR(__name, __search, __match) \ |
| 83 | __SIP_HDR(__name, NULL, __search, __match) |
| 84 | |
Patrick McHardy | ea45f12 | 2008-03-25 20:18:57 -0700 | [diff] [blame] | 85 | enum sip_header_types { |
Patrick McHardy | 30f33e6 | 2008-03-25 20:22:20 -0700 | [diff] [blame] | 86 | SIP_HDR_CSEQ, |
Patrick McHardy | ea45f12 | 2008-03-25 20:18:57 -0700 | [diff] [blame] | 87 | SIP_HDR_FROM, |
| 88 | SIP_HDR_TO, |
| 89 | SIP_HDR_CONTACT, |
Patrick McHardy | f5b321b | 2010-02-11 12:26:19 +0100 | [diff] [blame] | 90 | SIP_HDR_VIA_UDP, |
| 91 | SIP_HDR_VIA_TCP, |
Patrick McHardy | 0f32a40 | 2008-03-25 20:25:13 -0700 | [diff] [blame] | 92 | SIP_HDR_EXPIRES, |
Patrick McHardy | ea45f12 | 2008-03-25 20:18:57 -0700 | [diff] [blame] | 93 | SIP_HDR_CONTENT_LENGTH, |
Simon Horman | 001985b | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 94 | SIP_HDR_CALL_ID, |
Patrick McHardy | ea45f12 | 2008-03-25 20:18:57 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Patrick McHardy | 3e9b4600b | 2008-03-25 20:17:55 -0700 | [diff] [blame] | 97 | enum sdp_header_types { |
| 98 | SDP_HDR_UNSPEC, |
| 99 | SDP_HDR_VERSION, |
| 100 | SDP_HDR_OWNER_IP4, |
| 101 | SDP_HDR_CONNECTION_IP4, |
| 102 | SDP_HDR_OWNER_IP6, |
| 103 | SDP_HDR_CONNECTION_IP6, |
| 104 | SDP_HDR_MEDIA, |
Patrick McHardy | 9fafcd7 | 2006-12-02 22:09:57 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 107 | extern unsigned int (*nf_nat_sip_hook)(struct sk_buff *skb, |
Patrick McHardy | 3b6b9fa | 2010-02-11 12:23:53 +0100 | [diff] [blame] | 108 | unsigned int dataoff, |
Patrick McHardy | 2a6cfb2 | 2008-03-25 20:16:54 -0700 | [diff] [blame] | 109 | const char **dptr, |
| 110 | unsigned int *datalen); |
Patrick McHardy | 48f8ac2 | 2010-02-11 12:29:38 +0100 | [diff] [blame] | 111 | extern void (*nf_nat_sip_seq_adjust_hook)(struct sk_buff *skb, s16 off); |
Patrick McHardy | 0f32a40 | 2008-03-25 20:25:13 -0700 | [diff] [blame] | 112 | extern unsigned int (*nf_nat_sip_expect_hook)(struct sk_buff *skb, |
Patrick McHardy | 3b6b9fa | 2010-02-11 12:23:53 +0100 | [diff] [blame] | 113 | unsigned int dataoff, |
Patrick McHardy | 0f32a40 | 2008-03-25 20:25:13 -0700 | [diff] [blame] | 114 | const char **dptr, |
| 115 | unsigned int *datalen, |
| 116 | struct nf_conntrack_expect *exp, |
| 117 | unsigned int matchoff, |
| 118 | unsigned int matchlen); |
Patrick McHardy | 4ab9e64 | 2008-03-25 20:26:08 -0700 | [diff] [blame] | 119 | extern unsigned int (*nf_nat_sdp_addr_hook)(struct sk_buff *skb, |
Patrick McHardy | 4ab9e64 | 2008-03-25 20:26:08 -0700 | [diff] [blame] | 120 | unsigned int dataoff, |
Patrick McHardy | 3b6b9fa | 2010-02-11 12:23:53 +0100 | [diff] [blame] | 121 | const char **dptr, |
Patrick McHardy | 4ab9e64 | 2008-03-25 20:26:08 -0700 | [diff] [blame] | 122 | unsigned int *datalen, |
Patrick McHardy | 3b6b9fa | 2010-02-11 12:23:53 +0100 | [diff] [blame] | 123 | unsigned int sdpoff, |
Patrick McHardy | 4ab9e64 | 2008-03-25 20:26:08 -0700 | [diff] [blame] | 124 | enum sdp_header_types type, |
| 125 | enum sdp_header_types term, |
| 126 | const union nf_inet_addr *addr); |
Patrick McHardy | c7f485a | 2008-03-25 20:26:43 -0700 | [diff] [blame] | 127 | extern unsigned int (*nf_nat_sdp_port_hook)(struct sk_buff *skb, |
Patrick McHardy | 3b6b9fa | 2010-02-11 12:23:53 +0100 | [diff] [blame] | 128 | unsigned int dataoff, |
Patrick McHardy | c7f485a | 2008-03-25 20:26:43 -0700 | [diff] [blame] | 129 | const char **dptr, |
| 130 | unsigned int *datalen, |
| 131 | unsigned int matchoff, |
| 132 | unsigned int matchlen, |
| 133 | u_int16_t port); |
Patrick McHardy | 4ab9e64 | 2008-03-25 20:26:08 -0700 | [diff] [blame] | 134 | extern unsigned int (*nf_nat_sdp_session_hook)(struct sk_buff *skb, |
Patrick McHardy | 4ab9e64 | 2008-03-25 20:26:08 -0700 | [diff] [blame] | 135 | unsigned int dataoff, |
Patrick McHardy | 3b6b9fa | 2010-02-11 12:23:53 +0100 | [diff] [blame] | 136 | const char **dptr, |
Patrick McHardy | 4ab9e64 | 2008-03-25 20:26:08 -0700 | [diff] [blame] | 137 | unsigned int *datalen, |
Patrick McHardy | 3b6b9fa | 2010-02-11 12:23:53 +0100 | [diff] [blame] | 138 | unsigned int sdpoff, |
Patrick McHardy | 4ab9e64 | 2008-03-25 20:26:08 -0700 | [diff] [blame] | 139 | const union nf_inet_addr *addr); |
| 140 | extern unsigned int (*nf_nat_sdp_media_hook)(struct sk_buff *skb, |
Patrick McHardy | 3b6b9fa | 2010-02-11 12:23:53 +0100 | [diff] [blame] | 141 | unsigned int dataoff, |
Patrick McHardy | 4ab9e64 | 2008-03-25 20:26:08 -0700 | [diff] [blame] | 142 | const char **dptr, |
| 143 | unsigned int *datalen, |
| 144 | struct nf_conntrack_expect *rtp_exp, |
| 145 | struct nf_conntrack_expect *rtcp_exp, |
| 146 | unsigned int mediaoff, |
| 147 | unsigned int medialen, |
| 148 | union nf_inet_addr *rtp_addr); |
Patrick McHardy | 9fafcd7 | 2006-12-02 22:09:57 -0800 | [diff] [blame] | 149 | |
Patrick McHardy | ac36774 | 2008-03-25 20:18:40 -0700 | [diff] [blame] | 150 | extern int ct_sip_parse_request(const struct nf_conn *ct, |
| 151 | const char *dptr, unsigned int datalen, |
Patrick McHardy | 624f8b7 | 2008-03-25 20:19:30 -0700 | [diff] [blame] | 152 | unsigned int *matchoff, unsigned int *matchlen, |
| 153 | union nf_inet_addr *addr, __be16 *port); |
Patrick McHardy | ea45f12 | 2008-03-25 20:18:57 -0700 | [diff] [blame] | 154 | extern int ct_sip_get_header(const struct nf_conn *ct, const char *dptr, |
| 155 | unsigned int dataoff, unsigned int datalen, |
| 156 | enum sip_header_types type, |
| 157 | unsigned int *matchoff, unsigned int *matchlen); |
Patrick McHardy | 05e3ced | 2008-03-25 20:19:13 -0700 | [diff] [blame] | 158 | extern int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr, |
| 159 | unsigned int *dataoff, unsigned int datalen, |
| 160 | enum sip_header_types type, int *in_header, |
| 161 | unsigned int *matchoff, unsigned int *matchlen, |
| 162 | union nf_inet_addr *addr, __be16 *port); |
Patrick McHardy | 2bbb211 | 2008-03-25 20:24:24 -0700 | [diff] [blame] | 163 | extern int ct_sip_parse_address_param(const struct nf_conn *ct, const char *dptr, |
| 164 | unsigned int dataoff, unsigned int datalen, |
| 165 | const char *name, |
| 166 | unsigned int *matchoff, unsigned int *matchlen, |
Patrick McHardy | 02b69cb | 2012-08-09 10:08:46 +0000 | [diff] [blame] | 167 | union nf_inet_addr *addr, bool delim); |
Patrick McHardy | 2bbb211 | 2008-03-25 20:24:24 -0700 | [diff] [blame] | 168 | extern int ct_sip_parse_numerical_param(const struct nf_conn *ct, const char *dptr, |
| 169 | unsigned int off, unsigned int datalen, |
| 170 | const char *name, |
| 171 | unsigned int *matchoff, unsigned int *matchen, |
| 172 | unsigned int *val); |
Patrick McHardy | 3e9b4600b | 2008-03-25 20:17:55 -0700 | [diff] [blame] | 173 | |
| 174 | extern int ct_sip_get_sdp_header(const struct nf_conn *ct, const char *dptr, |
| 175 | unsigned int dataoff, unsigned int datalen, |
| 176 | enum sdp_header_types type, |
| 177 | enum sdp_header_types term, |
| 178 | unsigned int *matchoff, unsigned int *matchlen); |
| 179 | |
Patrick McHardy | 9fafcd7 | 2006-12-02 22:09:57 -0800 | [diff] [blame] | 180 | #endif /* __KERNEL__ */ |
| 181 | #endif /* __NF_CONNTRACK_SIP_H__ */ |