📄 readme
字号:
Mediaproxy SER module Copyright Dan Pascu 2002-2004 AG Projects Mediaproxy is a SER module that is designed to allow automatic NATtraversal for the majority of existing SIP clients. This means that therewill be no need to configure anything in particular on the NAT box to allowthese clients to work behind NAT when using the mediaproxy module.Section 1 for a description of the modus operandi.Section 2 describes the types of SIP phones that work with mediaproxy and a short description about how the NAT traversal is working.Section 3 is about mediaproxy features.Section 4 describes the exported module parameters and functions.Section 5 is a comparison with nathelper.1. Principle of operation ---------------------- This NAT traversal solution operates by placing a mediaproxy server in themiddle between 2 SIP user-agents. It mangles the SDP messages for both ofthem in a way that will make the parties talk with mediaproxy while theythink they talk directly with each other.To achieve this, mediaproxy is actually composed by 2 components: - the SER mediaproxy module itself - an external proxy server called SER MediaProxy (available from http://mediaproxy.ag-projects.com/ )To avoid confusion in this document the mediaproxy module will be called'module' or 'mediaproxy module', while the mediaproxy server will be called'proxy server' from here on. The proxy server can be run on the same machine as the module or on aremote host. Moreover it is possible for a single module to control multipleproxy servers running on multiple geographically distributed hosts. To findout more about the architecture of SER MediaProxy please read thedocumentation that comes with it. To be able to act as a proxy between the 2 talking parties, the machine(s)running the module/proxy server must have a public IP address. The module will ask the proxy server to allocate as many sockets as thereare media streams in the SDP body of the SIP INVITE/Ok messages. The proxyserver will send back to the module the address and port(s) for them. Thenthe module will replace the original contact IP and RTP ports from the SDPmessages with the ones provided by the proxy server. By doing this bothclients will try to contact the proxy server instead of talking directlywith each other. Once the clients contact the proxy server, it will recordthe addresses they came from and will know where to forward packets receivedfrom the other party This is needed because the address/port the NAT boxwill allocate for the leaving streams is not known before they actuallyleave the NAT box. However the address of the proxy server is always known(being a public one) so the 2 parties know where to connect and then afterthey did so, the proxy learns the addresses they came from and can forwardpackets between them.2. Types of SIP clients -------------------- The SIP clients that will work transparently behind NAT when using themediaproxy module are the so-called symmetric clients. The symmetric clientshave the particularity that use the same port to send the data as the onethey use to receive it. In other words, if they are for example configuredto use port 5060 for SIP signaling, they will use the same port when sendingdata as well as when receiving it. This must be true for both the SIPsignaling as well as the RTP streams for a client to work transparently withthe mediaproxy module without any additional configuration on the NAT box. This ability is important because the only way to get back to a clientbehind NAT is to send to the IP address and port the packet was receivedfrom. Once a packet is sent from the client behind NAT to the outside world,it opens a communication channel in the NAT box that is open in bothdirections for a while (it will timeout after a while after no more data issent through it, but it can be kept active by sending data through it atcertain regular time intervals). While this channel is open, any data sentto the public address and port that the NAT box assigned for the address andport the client behind NAT is sending from (and this mapping is guaranteedto be unique), will go back straight to the address and port the client hassent from. This is why is necessary for the clients to be symmetric. If theylisten on the same port they sent from, the data sent back to the publicaddress that the NAT box assigned to the leaving packets will actually reachthe listening port of the client behind NAT. Some SIP clients implement particular algorithms to detect if they areactually behind a NAT box and try to act smart by detecting the IP addressof the NAT box (or simply allowing one to manually configure it), and thenuse this IP address in the SIP and SDP messages instead of their own privateIP address. This situation can be confusing for a module that tries toperform transparent NAT traversal as it can wrongly mistake such a clientthat is behind NAT with a client that is actually in the public addressspace. However for the mediaproxy module it is not important if the clientsapply or not this kind of behavior, as it is able to cope with bothsituations gracefully. This doesn't mean that mediaproxy is not able to work with asymmetricclients behind NAT, but in their case special static forwarding routes needto be configured on the NAT box. Mediaproxy has special support for asymmetric clients, can detect them andsend the data to the ports they expect it to, however they can work behindNAT only if static routes are configured on the NAT box since there is noway of getting back to an address/port that has not previously opened a datachannel in the NAT box by sending something out first. Nevertheless thesupport for asymmetric clients is important, because without it they won'tbe able to work even when they have public Internet addresses. Also thissupport allows one to use an asymmetric client behind NAT if he canconfigure the NAT box to forward the packets meant to that client. The only requirement a symmetric SIP client must met to be able to worktransparently behind NAT when using the mediaproxy module is to accept to beconfigured to use a so called outbound proxy and this proxy must be the onerunning with the mediaproxy module loaded.3. Features --------- make symmetric clients work behind NAT transparently if they use the SIP server as the outbound SIP server.- handle all media streams specified in the SDP body. There is a limit of 64 RTP streams per session in the code now, but we hardly find this to be a limitation for the time being.- able to distribute RTP traffic load on multiple proxy servers running on multiple hosts.- able to specify which proxy server to use based on the SIP domain of the caller/destination (done by the proxy server's dispatcher module)- handle asymmetric clients properly. They can even work behind NAT if a proper port forwarding is done for them on the NAT box.4. Module parameters and exported functions ---------------------------------------- The module exports the following parameters: - mediaproxy_socket it is the path to the filesystem socket where the proxy server listens for commands from the module. - sip_asymmetrics it is the path to a file that lists regular expressions that match 'User-Agent' or 'Server' fields from clients that are asymmetric regarding SIP signaling. Needed to detect when a client is asymmetric regarding SIP signaling. An example file is in the config/ subdirectory. - rtp_asymmetrics it is the path to a file that lists regular expressions that match 'User-Agent' or 'Server' fields from clients that are asymmetric regarding the RTP media. Needed to detect when a client is asymmetric regarding the RTP media. An example file is in the config/ subdirectory. - natping_interval it holds an integer value representing how often the module will send packets to all registered clients that are behind NAT to keep their opened channels alive. Represents an interval in seconds.Parameters are set in the SER configuration file by using the modparamcommand. Below are examples, which contain the actual default values of theparameters. If you are Ok with them it is not necessary to specify them in theconfiguration file at all.modparam("mediaproxy", "mediaproxy_socket", "/var/run/proxydispatcher.sock")modparam("mediaproxy", "sip_asymmetrics", "/etc/ser/sip-asymmetrics-clients")modparam("mediaproxy", "rtp_asymmetrics", "/etc/ser/rtp-asymmetrics-clients")modparam("mediaproxy", "natping_interval", 20) The module exports the following functions: - client_nat_test(type) tests if the client is behind NAT or not. The types of tests are specified by the type parameter which represents a sum of the following numbers (add the values of the ones you wish to perform tests for): 1 - tests if client has a private IP address (as defined by RFC1918) in the Contact field of the SIP message. 2 - tests if client has contacted SER from an address that is different from the one in the 1st Via field. Both IP and port are checked, except for asymmetric clients for which the port is ignored. 4 - tests if client has a private IP address (as defined by RFC1918) in the top Via field of the SIP message. for example calling client_nat_test("3") in ser.cfg will perform first 2 tests listen above and return true as soon as one succeeds if both fail will return false. - fix_contact() will replace the IP:Port in the Contact field of the SIP message with the ones the SIP message was received from. For clients that are asymmetric regarding SIP signaling (as determined from the sip_asymmetrics file) will preserve the port. usually called after an if (client_nat_test(type)) has succeded - use_media_proxy() will make a call to the proxy server and replace the IPs and ports in the SDP body with the ones returned by the proxy server for each media stream that the SDP message describes. This will force the media streams to be routed through the proxy server. called when you want to make the session go through a proxy server - end_media_session() will call on the proxy server to end the media session for that call this is done at the end of the call to instruct the proxy server to free the resources allocated to that call as well as to save log information about the call. called when a session should end (BYE or CANCEL received)5. Comparison with the nathelper module ------------------------------------ After reading all this you may wonder what this module can offer you thatthe nathelper module (a similar nat traversal solution) can't and why wasnecessary to develop this module.While at surface they seem to offer about the same functionality, there area few core differences that make them quite different. The main and most notable difference is that mediaproxy offers adistributed environment, where the mediaproxy module can control multiplemediaproxy servers. The mediaproxy servers can be local or remote and theycan be specified per domain or as defaults for domains that don't have theirown mediaproxy servers defined. These mediaproxy servers can be arranged inload balancing and fallback schemes allowing the platform to scale up easilyand also offer redundancy to keep the service running even if some of themediaproxies go offline. Mediaproxy is able to detect the dead proxies andredistribute the calls among the other mediaproxies that are available.(More details about this can be found in the SER MediaProxy documentation) Another important difference is that mediaproxy tries to move the complexlogic of decision from the ser configuration file to the module and theproxy servers themselves. This is why there are very few functions in thismodule that take any parameters. Instead, control is achieved by modifyingresources outside of ser.cfg. This includes for example specifying themediaproxy servers using DNS SRV records, or declaring asymmetric clientsin external files that are automatically re-read as soon as they change.This allows SER to run without interruption or restarts. If one wants tochange SER's behavior, instead of changing ser.cfg and restarting SER, onewill change these external resources and SER will adapt it's behavior on thefly without any need for restart.Another advantage of this is that ser.cfg becomes simpler and easier tomaintain.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -