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 | |
Kevin Cernekee | 7266507 | 2012-12-17 18:33:58 +0000 | [diff] [blame] | 7 | #include <linux/types.h> |
| 8 | |
Patrick McHardy | 9fafcd7 | 2006-12-02 22:09:57 -0800 | [diff] [blame] | 9 | #define SIP_PORT 5060 |
| 10 | #define SIP_TIMEOUT 3600 |
| 11 | |
Patrick McHardy | 0f32a40 | 2008-03-25 20:25:13 -0700 | [diff] [blame] | 12 | struct nf_ct_sip_master { |
| 13 | unsigned int register_cseq; |
Patrick McHardy | ef75d49 | 2008-05-08 01:15:21 -0700 | [diff] [blame] | 14 | unsigned int invite_cseq; |
Kevin Cernekee | 7266507 | 2012-12-17 18:33:58 +0000 | [diff] [blame] | 15 | __be16 forced_dport; |
Patrick McHardy | 0f32a40 | 2008-03-25 20:25:13 -0700 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | enum sip_expectation_classes { |
| 19 | SIP_EXPECT_SIGNALLING, |
| 20 | SIP_EXPECT_AUDIO, |
Patrick McHardy | 0d0ab03 | 2008-03-25 20:26:24 -0700 | [diff] [blame] | 21 | SIP_EXPECT_VIDEO, |
Patrick McHardy | 9d288df | 2010-02-11 12:30:21 +0100 | [diff] [blame] | 22 | SIP_EXPECT_IMAGE, |
Patrick McHardy | 0f32a40 | 2008-03-25 20:25:13 -0700 | [diff] [blame] | 23 | __SIP_EXPECT_MAX |
| 24 | }; |
| 25 | #define SIP_EXPECT_MAX (__SIP_EXPECT_MAX - 1) |
| 26 | |
Patrick McHardy | 0d0ab03 | 2008-03-25 20:26:24 -0700 | [diff] [blame] | 27 | struct sdp_media_type { |
| 28 | const char *name; |
| 29 | unsigned int len; |
| 30 | enum sip_expectation_classes class; |
| 31 | }; |
| 32 | |
| 33 | #define SDP_MEDIA_TYPE(__name, __class) \ |
| 34 | { \ |
| 35 | .name = (__name), \ |
| 36 | .len = sizeof(__name) - 1, \ |
| 37 | .class = (__class), \ |
| 38 | } |
| 39 | |
Patrick McHardy | 30f33e6 | 2008-03-25 20:22:20 -0700 | [diff] [blame] | 40 | struct sip_handler { |
| 41 | const char *method; |
| 42 | unsigned int len; |
Patrick McHardy | 051966c | 2012-08-26 19:14:04 +0200 | [diff] [blame] | 43 | int (*request)(struct sk_buff *skb, unsigned int protoff, |
| 44 | unsigned int dataoff, |
Patrick McHardy | 30f33e6 | 2008-03-25 20:22:20 -0700 | [diff] [blame] | 45 | const char **dptr, unsigned int *datalen, |
| 46 | unsigned int cseq); |
Patrick McHardy | 051966c | 2012-08-26 19:14:04 +0200 | [diff] [blame] | 47 | int (*response)(struct sk_buff *skb, unsigned int protoff, |
| 48 | unsigned int dataoff, |
Patrick McHardy | 30f33e6 | 2008-03-25 20:22:20 -0700 | [diff] [blame] | 49 | const char **dptr, unsigned int *datalen, |
| 50 | unsigned int cseq, unsigned int code); |
| 51 | }; |
| 52 | |
| 53 | #define SIP_HANDLER(__method, __request, __response) \ |
| 54 | { \ |
| 55 | .method = (__method), \ |
| 56 | .len = sizeof(__method) - 1, \ |
| 57 | .request = (__request), \ |
| 58 | .response = (__response), \ |
| 59 | } |
| 60 | |
Patrick McHardy | 3e9b4600b | 2008-03-25 20:17:55 -0700 | [diff] [blame] | 61 | struct sip_header { |
| 62 | const char *name; |
| 63 | const char *cname; |
| 64 | const char *search; |
| 65 | unsigned int len; |
| 66 | unsigned int clen; |
| 67 | unsigned int slen; |
| 68 | int (*match_len)(const struct nf_conn *ct, |
| 69 | const char *dptr, const char *limit, |
| 70 | int *shift); |
| 71 | }; |
| 72 | |
| 73 | #define __SIP_HDR(__name, __cname, __search, __match) \ |
| 74 | { \ |
| 75 | .name = (__name), \ |
| 76 | .len = sizeof(__name) - 1, \ |
| 77 | .cname = (__cname), \ |
| 78 | .clen = (__cname) ? sizeof(__cname) - 1 : 0, \ |
| 79 | .search = (__search), \ |
| 80 | .slen = (__search) ? sizeof(__search) - 1 : 0, \ |
| 81 | .match_len = (__match), \ |
| 82 | } |
| 83 | |
Patrick McHardy | ea45f12 | 2008-03-25 20:18:57 -0700 | [diff] [blame] | 84 | #define SIP_HDR(__name, __cname, __search, __match) \ |
| 85 | __SIP_HDR(__name, __cname, __search, __match) |
| 86 | |
Patrick McHardy | 3e9b4600b | 2008-03-25 20:17:55 -0700 | [diff] [blame] | 87 | #define SDP_HDR(__name, __search, __match) \ |
| 88 | __SIP_HDR(__name, NULL, __search, __match) |
| 89 | |
Patrick McHardy | ea45f12 | 2008-03-25 20:18:57 -0700 | [diff] [blame] | 90 | enum sip_header_types { |
Patrick McHardy | 30f33e6 | 2008-03-25 20:22:20 -0700 | [diff] [blame] | 91 | SIP_HDR_CSEQ, |
Patrick McHardy | ea45f12 | 2008-03-25 20:18:57 -0700 | [diff] [blame] | 92 | SIP_HDR_FROM, |
| 93 | SIP_HDR_TO, |
| 94 | SIP_HDR_CONTACT, |
Patrick McHardy | f5b321b | 2010-02-11 12:26:19 +0100 | [diff] [blame] | 95 | SIP_HDR_VIA_UDP, |
| 96 | SIP_HDR_VIA_TCP, |
Patrick McHardy | 0f32a40 | 2008-03-25 20:25:13 -0700 | [diff] [blame] | 97 | SIP_HDR_EXPIRES, |
Patrick McHardy | ea45f12 | 2008-03-25 20:18:57 -0700 | [diff] [blame] | 98 | SIP_HDR_CONTENT_LENGTH, |
Simon Horman | 001985b | 2010-08-22 21:37:51 +0900 | [diff] [blame] | 99 | SIP_HDR_CALL_ID, |
Patrick McHardy | ea45f12 | 2008-03-25 20:18:57 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
Patrick McHardy | 3e9b4600b | 2008-03-25 20:17:55 -0700 | [diff] [blame] | 102 | enum sdp_header_types { |
| 103 | SDP_HDR_UNSPEC, |
| 104 | SDP_HDR_VERSION, |
Patrick McHardy | 9a66482 | 2012-08-26 19:14:25 +0200 | [diff] [blame] | 105 | SDP_HDR_OWNER, |
| 106 | SDP_HDR_CONNECTION, |
Patrick McHardy | 3e9b4600b | 2008-03-25 20:17:55 -0700 | [diff] [blame] | 107 | SDP_HDR_MEDIA, |
Patrick McHardy | 9fafcd7 | 2006-12-02 22:09:57 -0800 | [diff] [blame] | 108 | }; |
| 109 | |
holger@eitzenberger.org | 180cf72 | 2013-09-30 17:07:28 +0200 | [diff] [blame] | 110 | struct nf_nat_sip_hooks { |
| 111 | unsigned int (*msg)(struct sk_buff *skb, |
| 112 | unsigned int protoff, |
| 113 | unsigned int dataoff, |
| 114 | const char **dptr, |
| 115 | unsigned int *datalen); |
| 116 | |
| 117 | void (*seq_adjust)(struct sk_buff *skb, |
| 118 | unsigned int protoff, s16 off); |
| 119 | |
| 120 | unsigned int (*expect)(struct sk_buff *skb, |
| 121 | unsigned int protoff, |
| 122 | unsigned int dataoff, |
| 123 | const char **dptr, |
| 124 | unsigned int *datalen, |
| 125 | struct nf_conntrack_expect *exp, |
| 126 | unsigned int matchoff, |
| 127 | unsigned int matchlen); |
| 128 | |
| 129 | unsigned int (*sdp_addr)(struct sk_buff *skb, |
| 130 | unsigned int protoff, |
| 131 | unsigned int dataoff, |
| 132 | const char **dptr, |
| 133 | unsigned int *datalen, |
| 134 | unsigned int sdpoff, |
| 135 | enum sdp_header_types type, |
| 136 | enum sdp_header_types term, |
| 137 | const union nf_inet_addr *addr); |
| 138 | |
| 139 | unsigned int (*sdp_port)(struct sk_buff *skb, |
| 140 | unsigned int protoff, |
| 141 | unsigned int dataoff, |
| 142 | const char **dptr, |
| 143 | unsigned int *datalen, |
| 144 | unsigned int matchoff, |
| 145 | unsigned int matchlen, |
| 146 | u_int16_t port); |
| 147 | |
| 148 | unsigned int (*sdp_session)(struct sk_buff *skb, |
| 149 | unsigned int protoff, |
| 150 | unsigned int dataoff, |
| 151 | const char **dptr, |
| 152 | unsigned int *datalen, |
| 153 | unsigned int sdpoff, |
| 154 | const union nf_inet_addr *addr); |
| 155 | |
| 156 | unsigned int (*sdp_media)(struct sk_buff *skb, |
| 157 | unsigned int protoff, |
| 158 | unsigned int dataoff, |
| 159 | const char **dptr, |
| 160 | unsigned int *datalen, |
| 161 | struct nf_conntrack_expect *rtp_exp, |
| 162 | struct nf_conntrack_expect *rtcp_exp, |
| 163 | unsigned int mediaoff, |
| 164 | unsigned int medialen, |
| 165 | union nf_inet_addr *rtp_addr); |
| 166 | }; |
| 167 | extern const struct nf_nat_sip_hooks *nf_nat_sip_hooks; |
Patrick McHardy | 9fafcd7 | 2006-12-02 22:09:57 -0800 | [diff] [blame] | 168 | |
Joe Perches | a0f4ecf | 2013-09-26 14:48:15 -0700 | [diff] [blame] | 169 | int ct_sip_parse_request(const struct nf_conn *ct, const char *dptr, |
| 170 | unsigned int datalen, unsigned int *matchoff, |
| 171 | unsigned int *matchlen, union nf_inet_addr *addr, |
| 172 | __be16 *port); |
| 173 | int ct_sip_get_header(const struct nf_conn *ct, const char *dptr, |
| 174 | unsigned int dataoff, unsigned int datalen, |
| 175 | enum sip_header_types type, unsigned int *matchoff, |
| 176 | unsigned int *matchlen); |
| 177 | int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr, |
| 178 | unsigned int *dataoff, unsigned int datalen, |
| 179 | enum sip_header_types type, int *in_header, |
| 180 | unsigned int *matchoff, unsigned int *matchlen, |
| 181 | union nf_inet_addr *addr, __be16 *port); |
| 182 | int ct_sip_parse_address_param(const struct nf_conn *ct, const char *dptr, |
| 183 | unsigned int dataoff, unsigned int datalen, |
| 184 | const char *name, unsigned int *matchoff, |
| 185 | unsigned int *matchlen, union nf_inet_addr *addr, |
| 186 | bool delim); |
| 187 | int ct_sip_parse_numerical_param(const struct nf_conn *ct, const char *dptr, |
| 188 | unsigned int off, unsigned int datalen, |
| 189 | const char *name, unsigned int *matchoff, |
| 190 | unsigned int *matchen, unsigned int *val); |
Patrick McHardy | 3e9b4600b | 2008-03-25 20:17:55 -0700 | [diff] [blame] | 191 | |
Joe Perches | a0f4ecf | 2013-09-26 14:48:15 -0700 | [diff] [blame] | 192 | int ct_sip_get_sdp_header(const struct nf_conn *ct, const char *dptr, |
| 193 | unsigned int dataoff, unsigned int datalen, |
| 194 | enum sdp_header_types type, |
| 195 | enum sdp_header_types term, |
| 196 | unsigned int *matchoff, unsigned int *matchlen); |
Patrick McHardy | 3e9b4600b | 2008-03-25 20:17:55 -0700 | [diff] [blame] | 197 | |
Patrick McHardy | 9fafcd7 | 2006-12-02 22:09:57 -0800 | [diff] [blame] | 198 | #endif /* __KERNEL__ */ |
| 199 | #endif /* __NF_CONNTRACK_SIP_H__ */ |