alias_smedia.c (190841) | alias_smedia.c (259858) |
---|---|
1/* 2 * alias_smedia.c 3 * 4 * Copyright (c) 2000 Whistle Communications, Inc. 5 * All rights reserved. 6 * 7 * Subject to the following obligations and disclaimer of warranty, use and 8 * redistribution of this software, in source or object code forms, with or --- 50 unchanged lines hidden (view full) --- 59 * SUCH DAMAGE. 60 * 61 * Authors: Erik Salander <erik@whistle.com> 62 * Junichi SATOH <junichi@astec.co.jp> 63 * <junichi@junichi.org> 64 */ 65 66#include <sys/cdefs.h> | 1/* 2 * alias_smedia.c 3 * 4 * Copyright (c) 2000 Whistle Communications, Inc. 5 * All rights reserved. 6 * 7 * Subject to the following obligations and disclaimer of warranty, use and 8 * redistribution of this software, in source or object code forms, with or --- 50 unchanged lines hidden (view full) --- 59 * SUCH DAMAGE. 60 * 61 * Authors: Erik Salander <erik@whistle.com> 62 * Junichi SATOH <junichi@astec.co.jp> 63 * <junichi@junichi.org> 64 */ 65 66#include <sys/cdefs.h> |
67__FBSDID("$FreeBSD: head/sys/netinet/libalias/alias_smedia.c 190841 2009-04-08 11:56:49Z piso $"); | 67__FBSDID("$FreeBSD: head/sys/netinet/libalias/alias_smedia.c 259858 2013-12-25 02:06:57Z glebius $"); |
68 69/* 70 Alias_smedia.c is meant to contain the aliasing code for streaming media 71 protocols. It performs special processing for RSTP sessions under TCP. 72 Specifically, when a SETUP request is sent by a client, or a 200 reply 73 is sent by a server, it is intercepted and modified. The address is 74 changed to the gateway machine and an aliasing port is used. 75 --- 50 unchanged lines hidden (view full) --- 126 127#define RTSP_CONTROL_PORT_NUMBER_1 554 128#define RTSP_CONTROL_PORT_NUMBER_2 7070 129#define TFTP_PORT_NUMBER 69 130 131static void 132AliasHandleRtspOut(struct libalias *, struct ip *, struct alias_link *, 133 int maxpacketsize); | 68 69/* 70 Alias_smedia.c is meant to contain the aliasing code for streaming media 71 protocols. It performs special processing for RSTP sessions under TCP. 72 Specifically, when a SETUP request is sent by a client, or a 200 reply 73 is sent by a server, it is intercepted and modified. The address is 74 changed to the gateway machine and an aliasing port is used. 75 --- 50 unchanged lines hidden (view full) --- 126 127#define RTSP_CONTROL_PORT_NUMBER_1 554 128#define RTSP_CONTROL_PORT_NUMBER_2 7070 129#define TFTP_PORT_NUMBER 69 130 131static void 132AliasHandleRtspOut(struct libalias *, struct ip *, struct alias_link *, 133 int maxpacketsize); |
134static int | 134static int |
135fingerprint(struct libalias *la, struct alias_data *ah) 136{ 137 138 if (ah->dport != NULL && ah->aport != NULL && ah->sport != NULL && 139 ntohs(*ah->dport) == TFTP_PORT_NUMBER) 140 return (0); | 135fingerprint(struct libalias *la, struct alias_data *ah) 136{ 137 138 if (ah->dport != NULL && ah->aport != NULL && ah->sport != NULL && 139 ntohs(*ah->dport) == TFTP_PORT_NUMBER) 140 return (0); |
141 if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL || | 141 if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL || |
142 ah->maxpktsize == 0) 143 return (-1); 144 if (ntohs(*ah->dport) == RTSP_CONTROL_PORT_NUMBER_1 145 || ntohs(*ah->sport) == RTSP_CONTROL_PORT_NUMBER_1 146 || ntohs(*ah->dport) == RTSP_CONTROL_PORT_NUMBER_2 147 || ntohs(*ah->sport) == RTSP_CONTROL_PORT_NUMBER_2) 148 return (0); 149 return (-1); 150} 151 | 142 ah->maxpktsize == 0) 143 return (-1); 144 if (ntohs(*ah->dport) == RTSP_CONTROL_PORT_NUMBER_1 145 || ntohs(*ah->sport) == RTSP_CONTROL_PORT_NUMBER_1 146 || ntohs(*ah->dport) == RTSP_CONTROL_PORT_NUMBER_2 147 || ntohs(*ah->sport) == RTSP_CONTROL_PORT_NUMBER_2) 148 return (0); 149 return (-1); 150} 151 |
152static int | 152static int |
153protohandler(struct libalias *la, struct ip *pip, struct alias_data *ah) 154{ 155 156 if (ntohs(*ah->dport) == TFTP_PORT_NUMBER) 157 FindRtspOut(la, pip->ip_src, pip->ip_dst, 158 *ah->sport, *ah->aport, IPPROTO_UDP); 159 else AliasHandleRtspOut(la, pip, ah->lnk, ah->maxpktsize); 160 return (0); 161} 162 163struct proto_handler handlers[] = { | 153protohandler(struct libalias *la, struct ip *pip, struct alias_data *ah) 154{ 155 156 if (ntohs(*ah->dport) == TFTP_PORT_NUMBER) 157 FindRtspOut(la, pip->ip_src, pip->ip_dst, 158 *ah->sport, *ah->aport, IPPROTO_UDP); 159 else AliasHandleRtspOut(la, pip, ah->lnk, ah->maxpktsize); 160 return (0); 161} 162 163struct proto_handler handlers[] = { |
164 { 165 .pri = 100, 166 .dir = OUT, | 164 { 165 .pri = 100, 166 .dir = OUT, |
167 .proto = TCP|UDP, | 167 .proto = TCP|UDP, |
168 .fingerprint = &fingerprint, | 168 .fingerprint = &fingerprint, |
169 .protohandler = &protohandler | 169 .protohandler = &protohandler |
170 }, | 170 }, |
171 { EOH } 172}; 173 174static int 175mod_handler(module_t mod, int type, void *data) 176{ 177 int error; 178 --- 8 unchanged lines hidden (view full) --- 187 break; 188 default: 189 error = EINVAL; 190 } 191 return (error); 192} 193 194#ifdef _KERNEL | 171 { EOH } 172}; 173 174static int 175mod_handler(module_t mod, int type, void *data) 176{ 177 int error; 178 --- 8 unchanged lines hidden (view full) --- 187 break; 188 default: 189 error = EINVAL; 190 } 191 return (error); 192} 193 194#ifdef _KERNEL |
195static | 195static |
196#endif 197moduledata_t alias_mod = { 198 "alias_smedia", mod_handler, NULL 199}; 200 201#ifdef _KERNEL 202DECLARE_MODULE(alias_smedia, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND); 203MODULE_VERSION(alias_smedia, 1); --- 197 unchanged lines hidden (view full) --- 401 402 /* Create new packet */ 403 new_dlen = port_newdata - newdata; 404 memcpy(data, newdata, new_dlen); 405 406 SetAckModified(lnk); 407 tc = (struct tcphdr *)ip_next(pip); 408 delta = GetDeltaSeqOut(tc->th_seq, lnk); | 196#endif 197moduledata_t alias_mod = { 198 "alias_smedia", mod_handler, NULL 199}; 200 201#ifdef _KERNEL 202DECLARE_MODULE(alias_smedia, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND); 203MODULE_VERSION(alias_smedia, 1); --- 197 unchanged lines hidden (view full) --- 401 402 /* Create new packet */ 403 new_dlen = port_newdata - newdata; 404 memcpy(data, newdata, new_dlen); 405 406 SetAckModified(lnk); 407 tc = (struct tcphdr *)ip_next(pip); 408 delta = GetDeltaSeqOut(tc->th_seq, lnk); |
409 AddSeq(lnk, delta + new_dlen - dlen, pip->ip_hl, pip->ip_len, | 409 AddSeq(lnk, delta + new_dlen - dlen, pip->ip_hl, pip->ip_len, |
410 tc->th_seq, tc->th_off); 411 412 new_len = htons(hlen + new_dlen); 413 DifferentialChecksum(&pip->ip_sum, 414 &new_len, 415 &pip->ip_len, 416 1); 417 pip->ip_len = new_len; --- 132 unchanged lines hidden --- | 410 tc->th_seq, tc->th_off); 411 412 new_len = htons(hlen + new_dlen); 413 DifferentialChecksum(&pip->ip_sum, 414 &new_len, 415 &pip->ip_len, 416 1); 417 pip->ip_len = new_len; --- 132 unchanged lines hidden --- |