Every routing protocol instance communicates with one or more neighbor for exchange of routing information. Gated provides an interface for protocol implementations to send/receive routing messages, and some abstract data types for physical entities involved in such communication (e.g. the neighbor itself, the physical interface over which the Gated instance talks to the router).
Most protocol implementations directly access the operating system interface to send and receive routing messages to and from neighbors. Thus, BGP directly reads the socket associated with its TCP connections to its peers.
However, some older protocol implementations appear to use the functions task_receive_packet() and task_send_packet() respectively. While ideal for protocols that use unreliable datagrams for sending routing protocol messages, these functions do not suffice for protocol that use stream-based transports.
Gated provides an abstract data type to encapsulate all useful information pertaining to a routing protocol neighbor.
The basic data structure here is the gw_entry, one per protocol and (possibly) one per peer, which stores the neighbor's address, some state information, the list of routes heard from the neighbor and the import and export policies pertinent to the neighbor.
The parser calls gw_locate() when reading from the configuration file, to allocate a gw_entry to the configured neighbor.