[opensips] client registration

opensips registration capability

Opensips can realize the ability to register through the registrar module .
All account information is in the subscribe table of opensips by default.

subscribe table
The default subscribe table structure is as shown above,

  • id is the primary key,
  • username is the account name
  • domain is the domain name of opensips
  • password is the password
  • email_address is the email address, which is generally not used
  • ha1 and ha1b are used for authentication, and they are generated as follows:
    ha1 = md5(concat(username,":",domain,":",password))
    ha1b = md5(concat(username,"@",domain,":",domain,":",password))

Client registration process

The client registers through the REGISTER message. The registration process is as follows.
insert image description here
The first Register may not carry any authentication information, and opensips will do the authentication. These are required to be written in the opensips.cfg file
Below is an example snippet,

if (is_method("REGISTER")) {
    if (!www_authorize("", "subscriber")) {
      www_challenge("", "0");
      exit;
    }
    # indicate that the client supports DTLS
	# so we know when he is called
    if (isflagset(SRC_WS)) {
			setbflag(DST_WS);
	}
    if (nat_uac_test("19")) {
                fix_nated_register();
    }
    if (!save("location","f")){
      sl_reply_error();
      exit;
    }
    exit;
  }

Note:

  1. www_challenge is an authentication request initiated by opensips
  2. If the authentication is passed, the client's information will be saved to the " location " table through the save function
  3. If the client comes through the ws or wss protocol, by setting the DST_WS mark value, it can be recorded in the location table. To
    judge the protocol of the client, the following logic can be used
if ($proto == "ws" || $proto == "wss") {
    setflag(SRC_WS);        
  }
  1. fix_nated_register will save the client's egress IP (useful for NAT) to the received field of location.

Registration information saved in opensips

A sample registration data in the location table,
insert image description here

There are many default fields, so I won’t introduce them one by one. Here we mainly look at the meaning of several important fields

  • Username: is the username field in the subscribe table
  • contact: The contact header in the client registration message, which indicates the address of the client
  • Recieved: Introduced in the previous section, it is mainly the public network information exported by the client; it is generally used in the process of NAT traversal. For example, the contact address in the screenshot is obviously an invalid address. When the signaling returns, it will use the address in Recieved for routing.
  • Expires: the timeout period for registration
  • Cflags: The bflag in opensips is saved here. The DST_WS seen here is saved by setbflag(DST_WS); in the previous section.

The address registered to opensips becomes AOR (Address-of-Record) and stored in the memory of opensips, which should be shared memory here.

How to check AOR? (version 2.x)

opensipsctl ul showCan see all AOR

opensipsctl ul show <username>
You can view the AOR of a specific username
insert image description here

opensipsctl ul show --brief
View All AORs (Abbreviated Information)
insert image description here


how to register

The registration message in SIP is REGISTER, but there is no UNREGISTER message. So, besides waiting for the registration to time out, how to register explicitly?

Methods as below:

Still send the REGISTER message, but the REGISTER message needs special processing, the following two ways,

a) Expires Header value is 0

The sample is as follows: (note Expires )

REGISTER sip:XXX.XXX.XXX:5060 SIP/2.0
Via: SIP/2.0/UDP YYY.YYY.YYY.YYY:5060;branch=z9hG4bK3AF1E87
From: <sip:[email protected]>;tag=48206668-C6C
To: <sip:[email protected]>
Date: Tue, 21 May 2019 11:01:00 GMT
Call-ID: 8CFC113F-7AEE11E9-8525B193-993D21B5
User-Agent: Cisco-SIPGateway/IOS-12.x
Max-Forwards: 70
Timestamp: 1558436460
CSeq: 4 REGISTER
Contact: <sip:[email protected]:5060>
Expires:  0
Supported: path
Content-Length: 0

The example is seen from the cisco website and has not been tested.

b) There is no Expires Header; but the contact header carries the expires=0 parameter;

The sample is as follows: (note the Contact )

REGISTER sip:xxxxx.xxxxx.xxx:32060 SIP/2.0
Via: SIP/2.0/UDP 10.11.0.65:53310;branch=z9hG4bK-d87543-bb51c7089769c71a-1--d87543-;rport
Max-Forwards: 70
Contact: <sip:[email protected]:12887;rinstance=aec7db3ce165eaf1>;expires=0
To: "gw_61225552"<sip:[email protected]:32060>
From: "gw_61225552"<sip:[email protected]:32060>;tag=d71dd162
Call-ID: Y2JiMTIxODMzODZiNWMzN2E5MjIxZWQ5ZDkwM2ExMmY.
CSeq: 12 REGISTER
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
User-Agent: eyeBeam release 1011d stamp 40820

This example is taken from the packet capture when the eyeBeam client registers or closes the software. The test is valid.

Is it possible to directly delete the data field in the location to register?

The answer is no. From the above introduction, we can see that the registration information in opensips is actually divided into two parts, location data and AOR in memory. If you just delete the data in the location table, AOR information still exists in opensips.

So after deleting the location data, you need to execute opensipsctl ul rm <username>to delete the AOR.
Note that this command may not take effect immediately, and you should observe it after execution.

In short, it is not recommended to register through manual deletion. Or use the method described in the above section to register through register.

Guess you like

Origin blog.csdn.net/mimiduck/article/details/128216883