4.4. DATAGRAM SERVICE PACKETS
4.4.1. NetBIOS DATAGRAM HEADER
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MSG_TYPE | FLAGS | DGM_ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SOURCE_IP |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SOURCE_PORT | DGM_LENGTH |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PACKET_OFFSET |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
MSG_TYPE values (in hexidecimal):
10 - DIRECT_UNIQUE DATAGRAM
11 - DIRECT_GROUP DATAGRAM
12 - BROADCAST DATAGRAM
13 - DATAGRAM ERROR
14 - DATAGRAM QUERY REQUEST
15 - DATAGRAM POSITIVE QUERY RESPONSE
16 - DATAGRAM NEGATIVE QUERY RESPONSE
Bit definitions of the FLAGS field:
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| 0 | 0 | 0 | 0 | SNT | F | M |
+---+---+---+---+---+---+---+---+
Symbol Bit(s) Description
M 7 MORE flag, If set then more NetBIOS datagram
fragments follow.
F 6 FIRST packet flag, If set then this is first
(and possibly only) fragment of NetBIOS
datagram
SNT 4,5 Source End-Node type:
00 = B node
01 = P node
10 = M node
11 = NBDD
RESERVED 0-3 Reserved, must be zero (0)
4.4.2. DIRECT_UNIQUE, DIRECT_GROUP, & BROADCAST DATAGRAM
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MSG_TYPE | FLAGS | DGM_ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SOURCE_IP |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SOURCE_PORT | DGM_LENGTH |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PACKET_OFFSET | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| |
/ SOURCE_NAME /
/ /
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ DESTINATION_NAME /
/ /
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ USER_DATA /
/ /
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
4.4.3. DATAGRAM ERROR PACKET
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MSG_TYPE | FLAGS | DGM_ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SOURCE_IP |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SOURCE_PORT | ERROR_CODE |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ERROR_CODE values (in hexidecimal):
82 - DESTINATION NAME NOT PRESENT
83 - INVALID SOURCE NAME FORMAT
84 - INVALID DESTINATION NAME FORMAT
4.4.4. DATAGRAM QUERY REQUEST
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MSG_TYPE | FLAGS | DGM_ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SOURCE_IP |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SOURCE_PORT | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
| |
/ DESTINATION_NAME /
/ /
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
4.4.5. DATAGRAM POSITIVE AND NEGATIVE QUERY RESPONSE
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MSG_TYPE | FLAGS | DGM_ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SOURCE_IP |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SOURCE_PORT | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
| |
/ DESTINATION_NAME /
/ /
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
5. PROTOCOL DESCRIPTIONS
5.1. NAME SERVICE PROTOCOLS
A REQUEST packet is always sent to the well known UDP port -
NAME_SERVICE_UDP_PORT. The destination address is normally
either the IP broadcast address or the address of the NBNS - the
address of the NBNS server it set up at initialization time. In
rare cases, a request packet will be sent to an end node, e.g. a
NAME QUERY REQUEST sent to "challenge" a node.
A RESPONSE packet is always sent to the source UDP port and
source IP address of the request packet.
A DEMAND packet must always be sent to the well known UDP port -
NAME_SERVICE_UDP_PORT. There is no restriction on the target IP
address.
Terms used in this section:
tid - Transaction ID. This is a value composed from
the requestor's IP address and a unique 16 bit
value generated by the originator of the
transaction.
5.1.1. B-NODE ACTIVITY
5.1.1.1. B-NODE ADD NAME
PROCEDURE add_name(newname)
/*
* Host initiated processing for a B node
*/
BEGIN
REPEAT
/* build name service packet */
ONT = B_NODE; /* broadcast node */
G = UNIQUE; /* unique name */
TTL = 0;
broadcast NAME REGISTRATION REQUEST packet;
/*
* remote node(s) will send response packet
* if applicable
*/
pause(BCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet is received or
retransmit count has been exceeded
IF no response packet was received THEN
BEGIN /* no response */
/*
* build packet
*/
ONT = B_NODE; /* broadcast node */
G = UNIQUE; /* unique name */
TTL = 0;
/*
* Let other nodes known you have the name
*/
broadcast NAME UPDATE REQUEST packet;
/* name can be added to local name table */
return success;
END /* no response */
ELSE
BEGIN /* got response */
/*
* Match return transaction id
* against tid sent in request
*/
IF NOT response tid = request tid THEN
BEGIN
ignore response packet;
END
ELSE
CASE packet type OF
NEGATIVE NAME REGISTRATION RESPONSE:
return failure; /* name cannot be added */
POSITIVE NAME REGISTRATION RESPONSE:
END-NODE CHALLENGE NAME REGISTRATION RESPONSE:
/*
* B nodes should normally not get this
* response.
*/
ignore packet;
END /* case */;
END /* got response */
END /* procedure */
5.1.1.2. B-NODE ADD_GROUP NAME
PROCEDURE add_group_name(newname)
/*
* Host initiated processing for a B node
*/
BEGIN
/*
* same as for a unique name with the
* exception that the group bit (G) must
* be set in the request packets.
*/
...
G = GROUP;
...
...
/*
* broadcast request ...
*/
END
5.1.1.3. B-NODE FIND_NAME
PROCEDURE find_name(name)
/*
* Host initiated processing for a B node
*/
BEGIN
REPEAT
/*
* build packet
*/
ONT = B;
TTL = 0;
G = DONT CARE;
broadcast NAME QUERY REQUEST packet;
/*
* a node might send response packet
*/
pause(BCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet received OR
max transmit threshold exceeded
IF no response packet received THEN
return failure;
ELSE
IF NOT response tid = request tid THEN
ignore packet;
ELSE
CASE packet type OF
POSITIVE NAME QUERY RESPONSE:
/*
* Start a timer to detect conflict.
*
* Be prepared to detect conflict if
* any more response packets are received.
*
*/
save response as authoritative response;
start_timer(CONFLICT_TIMER);
return success;
NEGATIVE NAME QUERY RESPONSE:
REDIRECT NAME QUERY RESPONSE:
/*
* B Node should normally not get either
* response.
*/
ignore response packet;
END /* case */
END /* procedure */
5.1.1.4. B NODE NAME RELEASE
PROCEDURE delete_name (name)
BEGIN
REPEAT
/*
* build packet
*/
...
/*
* send request
*/
broadcast NAME RELEASE REQUEST packet;
/*
* no response packet expected
*/
pause(BCAST_REQ_RETRY_TIMEOUT);
UNTIL retransmit count has been exceeded
END /* procedure */
5.1.1.5. B-NODE INCOMING PACKET PROCESSING
Following processing is done when broadcast or unicast packets
are received at the NAME_SERVICE_UDP_PORT.
PROCEDURE process_incoming_packet(packet)
/*
* Processing initiated by incoming packets for a B node
*/
BEGIN
/*
* Note: response packets are always sent
* to:
* source IP address of request packet
* source UDP port of request packet
*/
CASE packet type OF
NAME REGISTRATION REQUEST (UNIQUE):
IF name exists in local name table THEN
send NEGATIVE NAME REGISTRATION RESPONSE ;
NAME REGISTRATION REQUEST (GROUP):
IF name exists in local name table THEN
BEGIN
IF local entry is a unique name THEN
send NEGATIVE NAME REGISTRATION RESPONSE ;
END
NAME QUERY REQUEST:
IF name exists in local name table THEN
BEGIN
build response packet;
send POSITIVE NAME QUERY RESPONSE;
POSITIVE NAME QUERY RESPONSE:
IF name conflict timer is not active THEN
BEGIN
/*
* timer has expired already... ignore this
* packet
*/
return;
END
ELSE /* timer is active */
IF a response for this name has previously been
received THEN
BEGIN /* existing entry */
/*
* we sent out a request packet, and
* have already received (at least)
* one response
*
* Check if conflict exists.
* If so, send out a conflict packet.
*
* Note: detecting conflict does NOT
* affect any existing sessions.
*
*/
/*
* Check for name conflict.
* See "Name Conflict" in Concepts and Methods
*/
check saved authoritative response against
information in this response packet;
IF conflict detected THEN
BEGIN
unicast NAME CONFLICT DEMAND packet;
IF entry exists in cache THEN
BEGIN
remove entry from cache;
END
END
END /* existing entry */
ELSE
BEGIN
/*
* Note: If this was the first response
* to a name query, it would have been
* handled in the
* find_name() procedure.
*/
ignore packet;
END
NAME CONFLICT DEMAND:
IF name exists in local name table THEN
BEGIN
mark name as conflict detected;
/*
* a name in the state "conflict detected"
* does not "logically" exist on that node.
* No further session will be accepted on
* that name.
* No datagrams can be sent against that name.
* Such an entry will not be used for
* purposes of processing incoming request
* packets.
* The only valid user NetBIOS operation
* against such a name is DELETE NAME.
*/
END
NAME RELEASE REQUEST:
IF caching is being done THEN
BEGIN
remove entry from cache;
END
NAME UPDATE REQUEST:
IF caching is being done THEN
BEGIN
IF entry exists in cache already,
update cache;
ELSE IF name is "interesting" THEN
BEGIN
add entry to cache;
END
END
NODE STATUS REQUEST:
IF name exists in local name table THEN
BEGIN
/*
* send only those names that are
* in the same scope as the scope
* field in the request packet
*/
send NODE STATUS RESPONSE;
END
END
5.1.2. P-NODE ACTIVITY
All packets sent or received by P nodes are unicast UDP packets.
A P node sends name service requests to the NBNS node that is
specified in the P-node configuration.
5.1.2.1. P-NODE ADD_NAME
PROCEDURE add_name(newname)
/*
* Host initiated processing for a P node
*/
BEGIN
REPEAT
/*
* build packet
*/
ONT = P;
G = UNIQUE;
...
/*
* send request
*/
unicast NAME REGISTRATION REQUEST packet;
/*
* NBNS will send response packet
*/
IF receive a WACK RESPONSE THEN
pause(time from TTL field of response);
ELSE
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet is received OR
retransmit count has been exceeded
IF no response packet was received THEN
BEGIN /* no response */
/*
* NBNS is down. Cannot claim name.
*/
return failure; /* name cannot be claimed */
END /* no response */
ELSE
BEGIN /* response */
IF NOT response tid = request tid THEN
BEGIN
/* Packet may belong to another transaction */
ignore response packet;
END
ELSE
CASE packet type OF
POSITIVE NAME REGISTRATION RESPONSE:
/*
* name can be added
*/
adjust refresh timeout value, TTL, for this name;
return success; /* name can be added */
NEGATIVE NAME REGISTRATION RESPONSE:
return failure; /* name cannot be added */
END-NODE CHALLENGE REGISTRATION REQUEST:
BEGIN /* end node challenge */
/*
* The response packet has in it the
* address of the presumed owner of the
* name. Challenge that owner.
* If owner either does not
* respond or indicates that he no longer
* owns the name, claim the name.
* Otherwise, the name cannot be claimed.
*
*/
REPEAT
/*
* build packet
*/
...
unicast NAME QUERY REQUEST packet to the
address contained in the END NODE
CHALLENGE RESPONSE packet;
/*
* remote node may send response packet
*/
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet is received or
retransmit count has been exceeded
IF no response packet is received OR
NEGATIVE NAME QUERY RESPONSE packet
received THEN
BEGIN /* update */
/*
* name can be claimed
*/
REPEAT
/*
* build packet
*/
...
unicast NAME UPDATE REQUEST to NBNS;
/*
* NBNS node will send response packet
*/
IF receive a WACK RESPONSE THEN
pause(time from TTL field of response);
ELSE
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet is received or
retransmit count has been exceeded
IF no response packet received THEN
BEGIN /* no response */
/*
* name could not be claimed
*/
return failure;
END /* no response */
ELSE
CASE packet type OF
POSITIVE NAME REGISTRATION RESPONSE:
/*
* add name
*/
return success;
NEGATIVE NAME REGISTRATION RESPONSE:
/*
* you lose ...
*/
return failure;
END /* case */
END /* update */
ELSE
/*
* received a positive response to the "challenge"
* Remote node still has name
*/
return failure;
END /* end node challenge */
END /* response */
END /* procedure */
5.1.2.2. P-NODE ADD GROUP NAME
PROCEDURE add_group_name(newname)
/*
* Host initiated processing for a P node
*/
BEGIN
/*
* same as for a unique name, except that the
* request packet must indicate that a
* group name claim is being made.
*/
...
G = GROUP;
...
/*
* send packet
*/
...
END
5.1.2.3. P-NODE FIND NAME
PROCEDURE find_name(name)
/*
* Host initiated processing for a P node
*/
BEGIN
REPEAT
/*
* build packet
*/
ONT = P;
G = DONT CARE;
unicast NAME QUERY REQUEST packet;
/*
* a NBNS node might send response packet
*/
IF receive a WACK RESPONSE THEN
pause(time from TTL field of response);
ELSE
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet received OR
max transmit threshold exceeded
IF no response packet received THEN
return failure;
ELSE
IF NOT response tid = request tid THEN
ignore packet;
ELSE
CASE packet type OF
POSITIVE NAME QUERY RESPONSE:
return success;
REDIRECT NAME QUERY RESPONSE:
/*
* NBNS node wants this end node
* to use some other NBNS node
* to resolve the query.
*/
repeat query with NBNS address
in the response packet;
NEGATIVE NAME QUERY RESPONSE:
return failure;
END /* case */
END /* procedure */
5.1.2.4. P-NODE DELETE_NAME
PROCEDURE delete_name (name)
/*
* Host initiated processing for a P node
*/
BEGIN
REPEAT
/*
* build packet
*/
...
/*
* send request
*/
unicast NAME RELEASE REQUEST packet;
IF receive a WACK RESPONSE THEN
pause(time from TTL field of response);
ELSE
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL retransmit count has been exceeded
or response been received
IF response has been received THEN
CASE packet type OF
POSITIVE NAME RELEASE RESPONSE:
return success;
NEGATIVE NAME RELEASE RESPONSE:
/*
* NBNS does want node to delete this
* name !!!
*/
return failure;
END /* case */
END /* procedure */
5.1.2.5. P-NODE INCOMING PACKET PROCESSING
Processing initiated by reception of packets at a P node
PROCEDURE process_incoming_packet(packet)
/*
* Processing initiated by incoming packets at a P node
*/
BEGIN
/*
* always ignore UDP broadcast packets
*/
IF packet was sent as a broadcast THEN
BEGIN
ignore packet;
return;
END
CASE packet type of
NAME CONFLICT DEMAND:
IF name exists in local name table THEN
mark name as in conflict;
return;
NAME QUERY REQUEST:
IF name exists in local name table THEN
BEGIN /* name exists */
/*
* build packet
*/
...
/*
* send response to the IP address and port
* number from which the request was received.
*/
send POSITIVE NAME QUERY RESPONSE ;
return;
END /* exists */
ELSE
BEGIN /* does not exist */
/*
* send response to the requestor
*/
send NEGATIVE NAME QUERY RESPONSE ;
return;
END /* does not exist */
NODE STATUS REQUEST:
/*
* Name of "*" may be used for force node to
* divulge status for administrative purposes
*/
IF name in local name table OR name = "*" THEN
BEGIN
/*
* Build response packet and
* send to requestor node
* Send only those names that are
* in the same scope as the scope
* in the request packet.
*/
send NODE STATUS RESPONSE;
END
NAME RELEASE REQUEST:
/*
* This will be received if the NBNS wants to flush the
* name from the local name table, or from the local
* cache.
*/
IF name exists in the local name table THEN
BEGIN
delete name from local name table;
inform user that name has been deleted;
END
ELSE
IF name has been cached locally THEN
BEGIN
remove entry from cache:
END
END /* case */
END /* procedure */
5.1.2.6. P-NODE TIMER INITIATED PROCESSING
Processing initiated by timer expiration.
PROCEDURE timer_expired()
/*
* Processing initiated by the expiration of a timer on a P node
*/
BEGIN
/*
* Send a NAME REFRESH REQUEST for each name which the
* TTL which has expired.
*/
REPEAT
build NAME REFRESH REQUEST packet;
REPEAT
send packet to NBNS;
IF receive a WACK RESPONSE THEN
pause(time from TTL field of response);
ELSE
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet is received or
retransmit count has been exceeded
CASE packet type OF
POSITIVE NAME REGISTRATION RESPONSE:
/* successfully refreshed */
reset TTL timer for this name;
NEGATIVE NAME REGISTRATION RESPONSE:
/*
* refused, can't keep name
* assume in conflict
*/
mark name as in conflict;
END /* case */
UNTIL request sent for all names for which TTL
has expired
END /* procedure */
5.1.3. M-NODE ACTIVITY
M nodes behavior is similar to that of P nodes with the addition
of some B node-like broadcast actions. M node name service
proceeds in two steps:
1.Use broadcast UDP based name service. Depending on the
operation, goto step 2.
2.Use directed UDP name service.
The following code for M nodes is exactly the same as for a P
node, with the exception that broadcast operations are done
before P type operation is attempted.
5.1.3.1. M-NODE ADD NAME
PROCEDURE add_name(newname)
/*
* Host initiated processing for a M node
*/
BEGIN
/*
* check if name exists on the
* broadcast area
*/
REPEAT
/* build packet */
....
broadcast NAME REGISTRATION REQUEST packet;
pause(BCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet is received or
retransmit count has been exceeded
IF valid response received THEN
BEGIN
/* cannot claim name */
return failure;
END
/*
* No objections received within the
* broadcast area.
* Send request to name server.
*/
REPEAT
/*
* build packet
*/
ONT = M;
...
unicast NAME REGISTRATION REQUEST packet;
/*
* remote NBNS will send response packet
*/
IF receive a WACK RESPONSE THEN
pause(time from TTL field of response);
ELSE
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet is received or
retransmit count has been exceeded
IF no response packet was received THEN
BEGIN /* no response */
/*
* NBNS is down. Cannot claim name.
*/
return failure; /* name cannot be claimed */
END /* no response */
ELSE
BEGIN /* response */
IF NOT response tid = request tid THEN
BEGIN
ignore response packet;
END
ELSE
CASE packet type OF
POSITIVE NAME REGISTRATION RESPONSE:
/*
* name can be added
*/
adjust refresh timeout value, TTL;
return success; /* name can be added */
NEGATIVE NAME REGISTRATION RESPONSE:
return failure; /* name cannot be added */
END-NODE CHALLENGE REGISTRATION REQUEST:
BEGIN /* end node challenge */
/*
* The response packet has in it the
* address of the presumed owner of the
* name. Challenge that owner.
* If owner either does not
* respond or indicates that he no longer
* owns the name, claim the name.
* Otherwise, the name cannot be claimed.
*
*/
REPEAT
/*
* build packet
*/
...
/*
* send packet to address contained in the
* response packet
*/
unicast NAME QUERY REQUEST packet;
/*
* remote node may send response packet
*/
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet is received or
retransmit count has been exceeded
IF no response packet is received THEN
BEGIN /* no response */
/*
* name can be claimed
*/
REPEAT
/*
* build packet
*/
...
unicast NAME UPDATE REQUEST to NBNS;
/*
* NBNS node will send response packet
*/
IF receive a WACK RESPONSE THEN
pause(time from TTL field of response);
ELSE
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet is received or
retransmit count has been exceeded
IF no response packet received THEN
BEGIN /* no response */
/*
* name could not be claimed
*/
return failure;
END /* no response */
ELSE
CASE packet type OF
POSITIVE NAME REGISTRATION RESPONSE:
/*
* add name
*/
return success;
NEGATIVE NAME REGISTRATION RESPONSE:
/*
* you lose ...
*/
return failure;
END /* case */
END /* no response */
ELSE
IF NOT response tid = request tid THEN
BEGIN
ignore response packet;
END
/*
* received a response to the "challenge"
* packet
*/
CASE packet type OF
POSITIVE NAME QUERY:
/*
* remote node still has name.
*/
return failure;
NEGATIVE NAME QUERY:
/*
* remote node no longer has name
*/
return success;
END /* case */
END /* end node challenge */
END /* case */
END /* response */
END /* procedure */
5.1.3.2. M-NODE ADD GROUP NAME
PROCEDURE add_group_name(newname)
/*
* Host initiated processing for a P node
*/
BEGIN
/*
* same as for a unique name, except that the
* request packet must indicate that a
* group name claim is being made.
*/
...
G = GROUP;
...
/*
* send packet
*/
...
END
5.1.3.3. M-NODE FIND NAME
PROCEDURE find_name(name)
/*
* Host initiated processing for a M node
*/
BEGIN
/*
* check if any node on the broadcast
* area has the name
*/
REPEAT
/* build packet */
...
broadcast NAME QUERY REQUEST packet;
pause(BCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet received OR
max transmit threshold exceeded
IF valid response received THEN
BEGIN
save response as authoritative response;
start_timer(CONFLICT_TIMER);
return success;
END
/*
* no valid response on the b'cast segment.
* Try the name server.
*/
REPEAT
/*
* build packet
*/
ONT = M;
G = DONT CARE;
unicast NAME QUERY REQUEST packet to NBNS;
/*
* a NBNS node might send response packet
*/
IF receive a WACK RESPONSE THEN
pause(time from TTL field of response);
ELSE
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet received OR
max transmit threshold exceeded
IF no response packet received THEN
return failure;
ELSE
IF NOT response tid = request tid THEN
ignore packet;
ELSE
CASE packet type OF
POSITIVE NAME QUERY RESPONSE:
return success;
REDIRECT NAME QUERY RESPONSE:
/*
* NBNS node wants this end node
* to use some other NBNS node
* to resolve the query.
*/
repeat query with NBNS address
in the response packet;
NEGATIVE NAME QUERY RESPONSE:
return failure;
END /* case */
END /* procedure */
5.1.3.4. M-NODE DELETE NAME
PROCEDURE delete_name (name)
/*
* Host initiated processing for a P node
*/
BEGIN
/*
* First, delete name on NBNS
*/
REPEAT
/*
* build packet
*/
...
/*
* send request
*/
unicast NAME RELEASE REQUEST packet to NBNS;
IF receive a WACK RESPONSE THEN
pause(time from TTL field of response);
ELSE
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL retransmit count has been exceeded
or response been received
IF response has been received THEN
CASE packet type OF
POSITIVE NAME RELEASE RESPONSE:
/*
* Deletion of name on b'cast segment is deferred
* until after NBNS has deleted the name
*/
REPEAT
/* build packet */
...
broadcast NAME RELEASE REQUEST;
pause(BCAST_REQ_RETRY_TIMEOUT);
UNTIL rexmt threshold exceeded
return success;
NEGATIVE NAME RELEASE RESPONSE:
/*
* NBNS does want node to delete this
* name
*/
return failure;
END /* case */
END /* procedure */
5.1.3.5. M-NODE INCOMING PACKET PROCESSING
Processing initiated by reception of packets at a M node
PROCEDURE process_incoming_packet(packet)
/*
* Processing initiated by incoming packets at a M node
*/
BEGIN
CASE packet type of
NAME CONFLICT DEMAND:
IF name exists in local name table THEN
mark name as in conflict;
return;
NAME QUERY REQUEST:
IF name exists in local name table THEN
BEGIN /* name exists */
/*
* build packet
*/
...
/*
* send response to the IP address and port
* number from which the request was received.
*/
send POSITIVE NAME QUERY RESPONSE ;
return;
END /* exists */
ELSE
BEGIN /* does not exist */
/*
* send response to the requestor
*/
IF request NOT broadcast THEN
/*
* Don't send negative responses to
* queries sent by B nodes
*/
send NEGATIVE NAME QUERY RESPONSE ;
return;
END /* does not exist */
NODE STATUS REQUEST:
BEGIN
/*
* Name of "*" may be used for force node to
* divulge status for administrative purposes
*/
IF name in local name table OR name = "*" THEN
/*
* Build response packet and
* send to requestor node
* Send only those names that are
* in the same scope as the scope
* in the request packet.
*/
send NODE STATUS RESPONSE;
END
NAME RELEASE REQUEST:
/*
* This will be received if the NBNS wants to flush the
* name from the local name table, or from the local
* cache.
*/
IF name exists in the local name table THEN
BEGIN
delete name from local name table;
inform user that name has been deleted;
END
ELSE
IF name has been cached locally THEN
BEGIN
remove entry from cache:
END
NAME REGISTRATION REQUEST (UNIQUE):
IF name exists in local name table THEN
send NEGATIVE NAME REGISTRATION RESPONSE ;
NAME REGISTRATION REQUEST (GROUP):
IF name exists in local name table THEN
BEGIN
IF local entry is a unique name THEN
send NEGATIVE NAME REGISTRATION RESPONSE ;
END
END /* case */
END /* procedure */
5.1.3.6. M-NODE TIMER INITIATED PROCESSING
Processing initiated by timer expiration:
PROCEDURE timer_expired()
/*
* Processing initiated by the expiration of a timer on a M node
*/
BEGIN
/*
* Send a NAME REFRESH REQUEST for each name which the
* TTL which has expired.
*/
REPEAT
build NAME REFRESH REQUEST packet;
REPEAT
send packet to NBNS;
IF receive a WACK RESPONSE THEN
pause(time from TTL field of response);
ELSE
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL response packet is received or
retransmit count has been exceeded
CASE packet type OF
POSITIVE NAME REGISTRATION RESPONSE:
/* successfully refreshed */
reset TTL timer for this name;
NEGATIVE NAME REGISTRATION RESPONSE:
/*
* refused, can't keep name
* assume in conflict
*/
mark name as in conflict;
END /* case */
UNTIL request sent for all names for which TTL
has expired
END /* procedure */
5.1.4. NBNS ACTIVITY
A NBNS node will receive directed packets from P and M nodes.
Reply packets are always sent as directed packets to the source
IP address and UDP port number. Received broadcast packets must
be ignored.
5.1.4.1. NBNS INCOMING PACKET PROCESSING
PROCEDURE process_incoming_packet(packet)
/*
* Incoming packet processing on a NS node
*/
BEGIN
IF packet was sent as a broadcast THEN
BEGIN
discard packet;
return;
END
CASE packet type of
NAME REGISTRATION REQUEST (UNIQUE):
IF unique name exists in data base THEN
BEGIN /* unique name exists */
/*
* NBNS node may be a "passive"
* server in that it expects the
* end node to do the challenge
* server. Such a NBNS node is
* called a "non-secure" server.
* A "secure" server will do the
* challenging before it sends
* back a response packet.
*/
IF non-secure THEN
BEGIN
/*
* build response packet
*/
...
/*
* let end node do the challenge
*/
send END-NODE CHALLENGE NAME REGISTRATION
RESPONSE;
return;
END
ELSE
/*
* secure server - do the name
* challenge operation
*/
REPEAT
send NAME QUERY REQUEST;
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL response has been received or
retransmit count has been exceeded
IF no response was received THEN
BEGIN
/* node down */
update data base - remove entry;
update data base - add new entry;
send POSITIVE NAME REGISTRATION RESPONSE;
return;
END
ELSE
BEGIN /* challenged node replied */
/*
* challenged node replied with
* a response packet
*/
CASE packet type
POSITIVE NAME QUERY RESPONSE:
/*
* name still owned by the
* challenged node
*
* build packet and send response
*/
...
/*
* Note: The NBNS will need to
* keep track (based on transaction id) of
* the IP address and port number
* of the original requestor.
*/
send NEGATIVE NAME REGISTRATION RESPONSE;
return;
NEGATIVE NAME QUERY RESPONSE:
update data base - remove entry;
update data base - add new entry;
/*
* build response packet and send
* response
*/
send POSITIVE NAME REGISTRATION RESPONSE;
return;
END /* case */
END /* challenged node replied */
END /* unique name exists in data base */
ELSE
IF group name exists in data base THEN
BEGIN /* group names exists */
/*
* Members of a group name are NOT
* challenged.
* Make the assumption that
* at least some of the group members
* are still alive.
* Refresh mechanism will
* allow the NBNS to detect when all
* members of a group no longer use that
* name
*/
send NEGATIVE NAME REGISTRATION RESPONSE;
END /* group name exists */
ELSE
BEGIN /* name does not exist */
/*
* Name does not exist in data base
*
* This code applies to both non-secure
* and secure server.
*/
update data base - add new entry;
send POSITIVE NAME REGISTRATION RESPONSE;
return;
END
NAME QUERY REQUEST:
IF name exists in data base THEN
BEGIN
/*
* build response packet and send to
* requestor
*/
...
send POSITIVE NAME QUERY RESPONSE;
return;
ELSE
BEGIN
/*
* build response packet and send to
* requestor
*/
...
send NEGATIVE NAME QUERY RESPONSE;
return;
END
NAME REGISTRATION REQUEST (GROUP):
IF name exists in data base THEN
BEGIN
IF local entry is a unique name THEN
BEGIN /* local is unique */
IF non-secure THEN
BEGIN
send END-NODE CHALLENGE NAME
REGISTRATION RESPONSE;
return;
END
REPEAT
send NAME QUERY REQUEST;
pause(UCAST_REQ_RETRY_TIMEOUT);
UNTIL response received or
retransmit count exceeded
IF no response received or
NEGATIVE NAME QUERY RESPONSE
received THEN
BEGIN
update data base - remove entry;
update data base - add new entry;
send POSITIVE NAME REGISTRATION RESPONSE;
return;
END
ELSE
BEGIN
/*
* name still being held
* by challenged node
*/
send NEGATIVE NAME REGISTRATION RESPONSE;
END
END /* local is unique */
ELSE
BEGIN /* local is group */
/*
* existing entry is a group name
*/
update data base - remove entry;
update data base - add new entry;
send POSITIVE NAME REGISTRATION RESPONSE;
return;
END /* local is group */
END /* names exists */
ELSE
BEGIN /* does not exist */
/* name does not exist in data base */
update data base - add new entry;
send POSITIVE NAME REGISTRATION RESPONSE;
return;
END /* does not exist */
NAME RELEASE REQUEST:
/*
* secure server may choose to disallow
* a node from deleting a name
*/
update data base - remove entry;
send POSITIVE NAME RELEASE RESPONSE;
return;
NAME UPDATE REQUEST:
/*
* End-node completed a successful challenge,
* no update database
*/
IF secure server THEN
send NEGATIVE NAME REGISTRATION RESPONSE;
ELSE
BEGIN /* new entry */
IF entry already exists THEN
update data base - remove entry;
update data base - add new entry;
send POSITIVE NAME REGISTRATION RESPONSE;
start_timer(TTL);
END
NAME REFRESH REQUEST:
check for consistency;
IF node not allowed to have name THEN
BEGIN
/*
* tell end node that it can't have name
*/
send NEGATIVE NAME REGISTRATION RESPONSE;
END
ELSE
BEGIN
/*
* send confirmation response to the
* end node.
*/
send POSITIVE NAME REGISTRATION;
start_timer(TTL);
END
return;
END /* case */
END /* procedure */
5.1.4.2. NBNS TIMER INITIATED PROCESSING
A NS node uses timers to flush out entries from the data base.
Each entry in the data base is removed when its timer expires.
This time value is a multiple of the refresh TTL established when
the name was registered.
PROCEDURE timer_expired()
/*
* processing initiated by expiration of TTL for a given name
*/
BEGIN
/*
* NBNS can (optionally) ensure
* that the node is actually down
* by sending a NODE STATUS REQUEST.
* If such a request is sent, and
* no response is received, it can
* be assumed that the node is down.
*/
remove entry from data base;
END
5.2. SESSION SERVICE PROTOCOLS
The following are variables and should be configurable by the
NetBIOS user. The default values of these variables is found in
"Defined Constants and Variables" in the Detailed
Specification.):
- SSN_RETRY_COUNT - The maximum number TCP connection attempts
allowable per a single NetBIOS call request.
- SSN_CLOSE_TIMEOUT is the time period to wait when closing the
NetBIOS session before killing the TCP connection if session
sends are outstanding.
The following are Defined Constants for the NetBIOS Session
Service. (See "Defined Constants and Variables" in the Detailed
Specification for the value of these constants):
- SSN_SRVC_TCP_PORT - is the globally well-known TCP port
allocated for the NetBIOS Session Service. The service accepts
TCP connections on this port to establish NetBIOS Sessions.
The TCP connection established to this port by the caller is
initially used for the exchange of NetBIOS control information.
The actual NetBIOS data connection may also pass through this
port or, through the retargetting facility, through another
port.
5.2.1. SESSION ESTABLISHMENT PROTOCOLS
5.2.1.1. USER REQUEST PROCESSING
PROCEDURE listen(listening name, caller name)
/*
* User initiated processing for B, P and M nodes
*
* This procedure assumes that an incoming session will be
* retargetted here by a session server.
*/
BEGIN
Do TCP listen; /* Returns TCP port used */
Register listen with Session Service, give names and
TCP port;
Wait for TCP connection to open; /* Incoming call */
Read SESSION REQUEST packet from connection
Process session request (see section on
processing initiated by the reception of session
service packets);
Inform Session Service that NetBIOS listen is complete;
IF session established THEN
return success and session information to user;
ELSE
return failure;
END /* procedure */
PROCEDURE call(calling name, called name)
/*
* user initiated processing for B, P and M nodes
*/
/*
* This algorithm assumes that the called name is a unique name.
* If the called name is a group name, the call() procedure
* needs to cycle through the members of the group
* until either (retry_count == SSN_RETRY_COUNT) or
* the list has been exhausted.
*/
BEGIN
retry_count = 0;
retarget = FALSE; /* TRUE: caller is being retargetted */
name_query = TRUE; /* TRUE: caller must begin again with */
/* name query. */
REPEAT
IF name_query THEN
BEGIN
do name discovery, returns IP address;
TCP port = SSN_SRVC_TCP_PORT;
IF name discovery fails THEN
return failure;
ELSE
name_query = FALSE;
END
/*
* now have IP address and TCP port of
* remote party.
*/
establish TCP connection with remote party, use an
ephemeral port as source TCP port;
IF connection refused THEN
BEGIN
IF retarget THEN
BEGIN
/* retry */
retarget = FALSE;
use original IP address and TCP port;
goto LOOP;
END
/* retry for just missed TCP listen */
pause(SESSION_RETRY_TIMER);
establish TCP connection, again use ephemeral
port as source TCP port;
IF connection refused OR
connection timed out THEN
return failure;
END
ELSE
IF connection timed out THEN
BEGIN
IF retarget THEN
BEGIN
/* retry */
retarget = FALSE;
use original IP address and TCP port;
goto LOOP;
END
ELSE
BEGIN
/*
* incorrect name discovery was done,
* try again
*/
inform name discovery process of
possible error;
name_query = TRUE;
goto LOOP;
END
END
/*
* TCP connection has been established
*/
wait for session response packet;
CASE packet type OF
POSITIVE SESSION RESPONSE:
return success and session established
information;
NEGATIVE SESSION RESPONSE:
BEGIN
CASE error OF
NOT LISTENING ON CALLED NAME:
NOT LISTENING FOR CALLING NAME:
BEGIN
kill TCP connection;
return failure;
END
CALLED NAME NOT PRESENT:
BEGIN
/*
* called name does not exist on
* remote node
*/
inform name discovery procedure
of possible error;
IF this is a P or M node THEN
BEGIN
/*
* Inform NetBIOS Name Server
* it has returned incorrect
* information.
*/
send NAME RELEASE REQUEST for called
name and IP address to
NetBIOS Name Server;
END
/* retry from beginning */
retarget = FALSE;
name_query = TRUE;
goto LOOP;
END /* called name not present */
END /* case */
END /* negative response */
RETARGET SESSION RESPONSE:
BEGIN
close TCP connection;
extract IP address and TCP port from
response;
retarget = TRUE;
END /* retarget response */
END /* case */
LOOP: retry_count = retry_count + 1;
UNTIL (retry_count > SSN_RETRY_COUNT);
return failure;
END /* procedure */
5.2.1.2. RECEIVED PACKET PROCESSING
These are packets received on a TCP connection before a session
has been established. The listen routines attached to a NetBIOS
user process need not implement the RETARGET response section.
The user process version, separate from a shared Session Service,
need only accept (POSITIVE SESSION RESPONSE) or reject (NEGATIVE
SESSION RESPONSE) a session request.
PROCEDURE session_packet(packet)
/*
* processing initiated by receipt of a session service
* packet for a session in the session establishment phase.
* Assumes the TCP connection has been accepted.
*/
BEGIN
CASE packet type
SESSION REQUEST:
BEGIN
IF called name does not exist on node THEN
BEGIN
send NEGATIVE SESSION RESPONSE with CALLED
NAME NOT PRESENT error code;
close TCP connection;
END
Search for a listen with CALLING NAME for CALLED
NAME;
IF matching listen is found THEN
BEGIN
IF port of listener process is port TCP
connection is on THEN
BEGIN
send POSITIVE SESSION RESPONSE;
Hand off connection to client process
and/or inform user session is
established;
END
ELSE
BEGIN
send RETARGET SESSION RESPONSE with
listener's IP address and
TCP port;
close TCP connection;
END
END
ELSE
BEGIN
/* no matching listen pending */
send NEGATIVE SESSION RESPONSE with either
NOT LISTENING ON CALLED NAME or NOT
LISTENING FOR CALLING NAME error
code;
close TCP connection;
END
END /* session request */
END /* case */
END /* procedure */
5.2.2. SESSION DATA TRANSFER PROTOCOLS
5.2.2.1. USER REQUEST PROCESSING
PROCEDURE send_message(user_message)
BEGIN
build SESSION MESSAGE header;
send SESSION MESSAGE header;
send user_message;
reset and restart keep-alive timer;
IF send fails THEN
BEGIN
/*
* TCP connection has failed */
*/
close NetBIOS session;
inform user that session is lost;
return failure;
END
ELSE
return success;
END
5.2.2.2. RECEIVED PACKET PROCESSING
These are packets received after a session has been established.
PROCEDURE session_packet(packet)
/*
* processing initiated by receipt of a session service
* packet for a session in the data transfer phase.
*/
BEGIN
CASE packet type OF
SESSION MESSAGE:
BEGIN
process message header;
read in user data;
reset and restart keep-alive timer;
deliver data to user;
END /* session message */
SESSION KEEP ALIVE:
discard packet;
END /* case */
END /* procedure */
5.2.2.3. PROCESSING INITIATED BY TIMER
PROCEDURE session_ka_timer()
/*
* processing initiated when session keep alive timer expires
*/
BEGIN
send SESSION KEEP ALIVE, if configured;
IF send fails THEN
BEGIN
/* remote node, or path to it, is down */
abort TCP connection;
close NetBIOS session;
inform user that session is lost;
return;
END
END /* procedure */
5.2.3. SESSION TERMINATION PROTOCOLS
5.2.3.1. USER REQUEST PROCESSING
PROCEDURE close_session()
/* initiated by a user request to close a session */
BEGIN
close gracefully the TCP connection;
WAIT for the connection to close or SSN_CLOSE_TIMEOUT
to expire;
IF time out expired THEN
abort TCP connection;
END /* procedure */
5.2.3.2. RECEPTION INDICATION PROCESSING
PROCEDURE close_indication()
/*
* initiated by a TCP indication of a close request from
* the remote connection partner.
*/
BEGIN
close gracefully TCP connection;
close NetBIOS session;
inform user session closed by remote partner;
END /* procedure */
5.3. NetBIOS DATAGRAM SERVICE PROTOCOLS
The following are GLOBAL variables and should be NetBIOS user
configurable:
- SCOPE_ID: the non-leaf section of the domain name preceded by a
'.' which represents the domain of the NetBIOS scope for the
NetBIOS name. The following protocol description only supports
single scope operation.
- MAX_DATAGRAM_LENGTH: the maximum length of an IP datagram. The
minimal maximum length defined in for IP is 576 bytes. This
value is used when determining whether to fragment a NetBIOS
datagram. Implementations are expected to be capable of
receiving unfragmented NetBIOS datagrams up to their maximum
size.
- BROADCAST_ADDRESS: the IP address B-nodes use to send datagrams
with group name destinations and broadcast datagrams. The
default is the IP broadcast address for a single IP network.
The following are Defined Constants for the NetBIOS Datagram
Service:
- DGM_SRVC_UDP_PORT: the globally well-known UDP port allocated
where the NetBIOS Datagram Service receives UDP packets. See
section 6, "Defined Constants", for its value.
5.3.1. B NODE TRANSMISSION OF NetBIOS DATAGRAMS
PROCEDURE send_datagram(data, source, destination, broadcast)
/*
* user initiated processing on B node
*/
BEGIN
group = FALSE;
do name discovery on destination name, returns name type and
IP address;
IF name type is group name THEN
BEGIN
group = TRUE;
END
/*
* build datagram service UDP packet;
*/
convert source and destination NetBIOS names into
half-ASCII, biased encoded name;
SOURCE_NAME = cat(source, SCOPE_ID);
SOURCE_IP = this nodes IP address;
SOURCE_PORT = DGM_SRVC_UDP_PORT;
IF NetBIOS broadcast THEN
BEGIN
DESTINATION_NAME = cat("*", SCOPE_ID)
END
ELSE
BEGIN
DESTINATION_NAME = cat(destination, SCOPE_ID)
END
MSG_TYPE = select_one_from_set
{BROADCAST, DIRECT_UNIQUE, DIRECT_GROUP}
DGM_ID = next transaction id for Datagrams;
DGM_LENGTH = length of data + length of second level encoded
source and destination names;
IF (length of the NetBIOS Datagram, including UDP and
IP headers, > MAX_DATAGRAM_LENGTH) THEN
BEGIN
/*
* fragment NetBIOS datagram into 2 UDP packets
*/
Put names into 1st UDP packet and any data that fits
after names;
Set MORE and FIRST bits in 1st UDP packet's FLAGS;
OFFSET in 1st UDP = 0;
Replicate NetBIOS Datagram header from 1st UDP packet
into 2nd UDP packet;
Put rest of data in 2nd UDP packet;
Clear MORE and FIRST bits in 2nd UDP packet's FLAGS;
OFFSET in 2nd UDP = DGM_LENGTH - number of name and
data bytes in 1st UDP;
END
BEGIN
/*
* Only need one UDP packet
*/
USER_DATA = data;
Clear MORE bit and set FIRST bit in FLAGS;
OFFSET = 0;
END
IF (group == TRUE) OR (NetBIOS broadcast) THEN
BEGIN
send UDP packet(s) to BROADCAST_ADDRESS;
END
ELSE
BEGIN
send UDP packet(s) to IP address returned by name
discovery;
END
END /* procedure */
5.3.2. P AND M NODE TRANSMISSION OF NetBIOS DATAGRAMS
PROCEDURE send_datagram(data, source, destination, broadcast)
/*
* User initiated processing on P and M node.
*
* This processing is the same as for B nodes except for
* sending broadcast and multicast NetBIOS datagrams.
*/
BEGIN
group = FALSE;
do name discovery on destination name, returns name type
and IP address;
IF name type is group name THEN
BEGIN
group = TRUE;
END
/*