Contents of the NBDETAIL.TXT file

Network Working GroupRequest for Comments: 1002 March, 1987

PROTOCOL STANDARD FOR A NetBIOS SERVICE ON A TCP/UDP TRANSPORT: DETAILED SPECIFICATIONS

ABSTRACT

This RFC defines a proposed standard protocol to support NetBIOSservices in a TCP/IP environment. Both local network and internetoperation are supported. Various node types are defined to accommodatelocal and internet topologies and to allow operation with or without theuse of IP broadcast.

This RFC gives the detailed specifications of the NetBIOS-over-TCPpackets, protocols, and defined constants and variables. A more generaloverview is found in a companion RFC, "Protocol Standard For a NetBIOSService on a TCP/UDP Transport: Concepts and Methods".

The system proposed by this RFC does not reflect any existing Netbios-over-TCP implementation. However, the design incorporates considerable knowledge obtained from prior implementations. Special thanks goes to the following organizations which have provided this invaluable information:

CMC/Syros Excelan Sytek Ungermann-Bass

NetBIOS Working Group [Page 4]

RFC 1002 March 1987

3. INTRODUCTION

This RFC contains the detailed packet formats and protocol specifications for NetBIOS-over-TCP. This RFC is a companion to RFC 1001, "Protocol Standard For a NetBIOS Service on a TCP/UDP Transport: Concepts and Methods" [1].

4. PACKET DESCRIPTIONS

Bit and byte ordering are defined by the most recent version of "Assigned Numbers" [2].

4.1. NAME FORMAT

The NetBIOS name representation in all NetBIOS packets (for NAME, SESSION, and DATAGRAM services) is defined in the Domain Name Service RFC 883[3] as "compressed" name messages. This format is called "second-level encoding" in the section entitled "Representation of NetBIOS Names" in the Concepts and Methods document.

For ease of description, the first two paragraphs from page 31, the section titled "Domain name representation and compression", of RFC 883 are replicated here:

Domain names messages are expressed in terms of a sequence of labels. Each label is represented as a one octet length field followed by that number of octets. Since every domain name ends with the null label of the root, a compressed domain name is terminated by a length byte of zero. The high order two bits of the length field must be zero, and the remaining six bits of the length field limit the label to 63 octets or less.

To simplify implementations, the total length of label octets and label length octets that make up a domain name is restricted to 255 octets or less.

The following is the uncompressed representation of the NetBIOS name "FRED ", which is the 4 ASCII characters, F, R, E, D, followed by 12 space characters (0x20). This name has the SCOPE_ID: "NETBIOS.COM"

EGFCEFEECACACACACACACACACACACACA.NETBIOS.COM

This uncompressed representation of names is called "first-level encoding" in the section entitled "Representation of NetBIOS Names" in the Concepts and Methods document.

The following is a pictographic representation of the compressed representation of the previous uncompressed Domain Name representation.

Each section of a domain name is called a label [7 (page 31)]. A label can be a maximum of 63 bytes. The first byte of a label in compressed representation is the number of bytes in the label. For the above example, the first 0x20 is the number of bytes in the left-most label, EGFCEFEECACACACACACACACACACACACA, of the domain name. The bytes following the label length count are the characters of the label. The following labels are in sequence after the first label, which is the encoded NetBIOS name, until a zero (0x00) length count. The zero length count represents the root label, which is always null.

A label length count is actually a 6-bit field in the label length field. The most significant 2 bits of the field, bits 7 and 6, are flags allowing an escape from the above compressed representation. If bits 7 and 6 are both set (11), the following 14 bits are an offset pointer into the full message to the actual label string from another domain name that belongs in this name. This label pointer allows for a further compression of a domain name in a packet.

NetBIOS implementations can only use label string pointers in Name Service packets. They cannot be used in Session or Datagram Service packets.

NetBIOS Working Group [Page 6]

RFC 1002 March 1987

The other two possible values for bits 7 and 6 (01 and 10) of a label length field are reserved for future use by RFC 883[2 (page 32)].

Note that the first octet of a compressed name must contain one of the following bit patterns. (An "x" indicates a bit whose value may be either 0 or 1.):

The NetBIOS Name Service packets follow the packet structure defined in the Domain Name Service (DNS) RFC 883 [7 (pg 26-31)]. The structures are compatible with the existing DNS packet formats, however, additional types and codes have been added to work with NetBIOS.

If Name Service packets are sent over a TCP connection they are preceded by a 16 bit unsigned integer representing the length of the Name Service packet.

Since the RR_NAME is the same name as the QUESTION_NAME, the RR_NAME representation must use pointers to the QUESTION_NAME name's labels to guarantee the length of the datagram is less than the maximum 576 bytes. See section above on name formats and also page 31 and 32 of RFC 883, Domain Names - Implementation and Specification, for a complete description of compressed name label pointers.

FMT_ERR 0x1 Format Error. Request was invalidly formatted. SRV_ERR 0x2 Server failure. Problem with NBNS, cannot process name. IMP_ERR 0x4 Unsupported request error. Allowable only for challenging NBNS when gets an Update type registration request. RFS_ERR 0x5 Refused error. For policy reasons server will not register this name from this host. ACT_ERR 0x6 Active error. Name is owned by another node. CFT_ERR 0x7 Name in conflict error. A UNIQUE name is owned by more than one node.

Since the RR_NAME is the same name as the QUESTION_NAME, the RR_NAME representation must use label string pointers to the QUESTION_NAME labels to guarantee the length of the datagram is less than the maximum 576 bytes. This is the same condition as with the NAME REGISTRATION REQUEST.

RFS_ERR 0x5 Refused error. For policy reasons server will not release this name from this host.

ACT_ERR 0x6 Active error. Name is owned by another node. Only that node may release it. A NetBIOS Name Server can optionally allow a node to release a name it does not own. This would facilitate detection of inactive names for nodes that went down silently.

The ADDR_ENTRY ARRAY a sequence of zero or more ADDR_ENTRY records. Each ADDR_ENTRY record represents an owner of a name. For group names there may be multiple entries. However, the list may be incomplete due to packet size limitations. Bit 22, "T", will be set to indicate truncated data.

An end node responding to a NAME QUERY REQUEST always responds with the AA and RA bits set for both the NEGATIVE and POSITIVE NAME QUERY RESPONSE packets. An end node never sends a REDIRECT NAME QUERY RESPONSE packet.

NetBIOS Working Group [Page 24]

RFC 1002 March 1987

When the requestor receives the REDIRECT NAME QUERY RESPONSE it must reiterate the NAME QUERY REQUEST to the NBNS specified by the NSD_IP_ADDR field of the A type RESOURCE RECORD in the ADDITIONAL section of the response packet. This is an optional packet for the NBNS.

The NSD_NAME and the RR_NAME in the ADDITIONAL section of the response packet are the same name. Space can be optimized if label string pointers are used in the RR_NAME which point to the labels in the NSD_NAME.

The RR_NAME in the AUTHORITY section is the name of the domain the NBNS called by NSD_NAME has authority over.

The NAME_TRN_ID of the WACK RESPONSE packet is the same NAME_TRN_ID of the request that the NBNS is telling the requestor to wait longer to complete. The RR_NAME is the name from the request, if any. If no name is available from the request then it is a null name, single byte of zero.

The TTL field of the ResourceRecord is the new time to wait, in seconds, for the request to complete. The RDATA field contains the OPCODE and NM_FLAGS of the request.

A TTL value of 0 means that the NBNS can not estimate the time it may take to complete a response.

The NODE_NAME ARRAY is an array of zero or more NUM_NAMES entries of NODE_NAME records. Each NODE_NAME entry represents an active name in the same NetBIOS scope as the requesting name in the local name table of the responder. RR_NAME is the requesting name.

RESERVED 7-15 Reserved for future use. Must be zero (0). PRM 6 Permanent Name Flag. If one (1) then entry is for the permanent node name. Flag is zero (0) for all other names. ACT 5 Active Name Flag. All entries have this flag set to one (1). CNF 4 Conflict Flag. If one (1) then name on this node is in conflict. DRG 3 Deregister Flag. If one (1) then this name is in the process of being deleted. ONT 1,2 Owner Node Type: 00 = B node 01 = P node 10 = M node 11 = Reserved for future use G 0 Group Name Flag. If one (1) then the name is a GROUP NetBIOS name. If zero (0) then it is a UNIQUE NetBIOS name.

The TYPE, FLAGS, and LENGTH fields are present in every session packet.

NetBIOS Working Group [Page 29]

RFC 1002 March 1987

The LENGTH field is the number of bytes following the LENGTH field. In other words, LENGTH is the combined size of the TRAILER field(s). For example, the POSITIVE SESSION RESPONSE packet always has a LENGTH field value of zero (0000) while the RETARGET SESSION RESPONSE always has a LENGTH field value of six (0006).

One of the bits of the FLAGS field acts as an additional, high- order bit for the LENGTH field. Thus the cumulative size of the trailer field(s) may range from 0 to 128K bytes.

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.

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;

NetBIOS Working Group [Page 37]

RFC 1002 March 1987

/* * 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. * */

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;

NetBIOS Working Group [Page 39]

RFC 1002 March 1987

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.

NetBIOS Working Group [Page 40]

RFC 1002 March 1987

*/

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

NetBIOS Working Group [Page 41]

RFC 1002 March 1987

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. */

/* * 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);

NetBIOS Working Group [Page 43]

RFC 1002 March 1987

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 */

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

NetBIOS Working Group [Page 47]

RFC 1002 March 1987

/* * 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 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 /*

NetBIOS Working Group [Page 48]

RFC 1002 March 1987

* 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);

NetBIOS Working Group [Page 49]

RFC 1002 March 1987

ELSE pause(UCAST_REQ_RETRY_TIMEOUT); UNTIL response packet is received or retransmit count has been exceeded

/* * 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

NetBIOS Working Group [Page 52]

RFC 1002 March 1987

*/

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 */

IF request NOT broadcast THEN /* * Don't send negative responses to * queries sent by B nodes */

NetBIOS Working Group [Page 58]

RFC 1002 March 1987

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 */

NetBIOS Working Group [Page 59]

RFC 1002 March 1987

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

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.

NetBIOS Working Group [Page 60]

RFC 1002 March 1987

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. */

/* * 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. */

NAME QUERY REQUEST: IF name exists in data base THEN BEGIN /* * build response packet and send to * requestor */ ...

send POSITIVE NAME QUERY RESPONSE; return;

NetBIOS Working Group [Page 63]

RFC 1002 March 1987

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 */

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

NetBIOS Working Group [Page 66]

RFC 1002 March 1987

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.

/* * 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. */

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 */

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 */

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;

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 */

PROCEDURE close_indication() /* * initiated by a TCP indication of a close request from * the remote connection partner.

NetBIOS Working Group [Page 73]

RFC 1002 March 1987

*/ 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.

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 */

NetBIOS Working Group [Page 75]

RFC 1002 March 1987

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

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 /* * Sending of following query is optional. * Node may send datagram to NBDD immediately * but NBDD may discard the datagram. */ send DATAGRAM QUERY REQUEST to NBDD; IF response is POSITIVE QUERY RESPONSE THEN send UDP packet(s) to NBDD Server IP address; ELSE BEGIN get list of destination nodes from NBNS;

NetBIOS Working Group [Page 77]

RFC 1002 March 1987

FOR EACH node in list BEGIN send UDP packet(s) to this node's IP address; END END END ELSE BEGIN send UDP packet(s) to IP address returned by name discovery; END /* procedure */

5.3.3. RECEPTION OF NetBIOS DATAGRAMS BY ALL NODES

The following algorithm discards out of order NetBIOS Datagram fragments. An implementation which reassembles out of order NetBIOS Datagram fragments conforms to this specification. The fragment discard timer is initialized to the value FRAGMENT_TO. This value should be user configurable. The default value is given in Section 6, "Defined Constants and Variables".

IF DESTINATION_NAME is not present in the local name table THEN BEGIN /* destination not present */ build DATAGRAM ERROR packet, clear FIRST and MORE bit, put in this nodes IP and PORT, set ERROR_CODE; send DATAGRAM ERROR packet to source IP address and port of UDP; discard UDP packet(s); return; END ELSE BEGIN /* good */ /*

NetBIOS Working Group [Page 79]

RFC 1002 March 1987

* Replicate received NetBIOS datagram for * each recipient */ FOR EACH pending NetBIOS user's receive datagram operation BEGIN IF source name of operation matches destination name of packet THEN BEGIN deliver USER_DATA from UDP packet(s); END END /* for each */ return; END /* good */ END /* non-broadcast */ END /* datagram service */

IF this is a P or M node THEN BEGIN /* * tell NetBIOS Name Server that it may * have given incorrect information */

send NAME RELEASE REQUEST with name and incorrect IP address to NetBIOS Name Server; END END /* datagram error */

END /* case */ END

5.3.4. PROTOCOLS FOR THE NBDD

The key to NetBIOS Datagram forwarding service is the packet delivered to the destination end node must have the same NetBIOS header as if the source end node sent the packet directly to the destination end node. Consequently, the NBDD does not reassemble NetBIOS Datagrams. It forwards the UDP packet as is.

NetBIOS Working Group [Page 80]

RFC 1002 March 1987

PROCEDURE datagram_packet(packet)

/* * processing initiated by a incoming datagram service * packet on a NBDD node. */

BEGIN CASE packet type OF

DATAGRAM SERVICE: BEGIN IF packet was sent as a directed NetBIOS datagram THEN BEGIN /* * provide group forwarding service * * Forward datagram to each member of the * group. Can forward via: * 1) get list of group members and send * the DATAGRAM SERVICE packet unicast * to each * 2) use Group Multicast, if available * 3) combination of 1) and 2) */

...

END

ELSE BEGIN /* * provide broadcast forwarding service * * Forward datagram to every node in the * NetBIOS scope. Can forward via: * 1) get list of group members and send * the DATAGRAM SERVICE packet unicast * to each * 2) use Group Multicast, if available * 3) combination of 1) and 2) */

...

END END /* datagram service */

DATAGRAM ERROR:

NetBIOS Working Group [Page 81]

RFC 1002 March 1987

BEGIN /* * Should never receive these because Datagrams * forwarded have source end node IP address and * port in NetBIOS header. */

send DELETE NAME REQUEST with incorrect name and IP address to NetBIOS Name Server;

END /* datagram error */

DATAGRAM QUERY REQUEST: BEGIN IF can send packet to DESTINATION_NAME THEN BEGIN /* * NBDD is able to relay Datagrams for * this name */

send POSITIVE DATAGRAM QUERY RESPONSE to REQUEST source IP address and UDP port with request's DGM_ID; END ELSE BEGIN /* * NBDD is NOT able to relay Datagrams for * this name */