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