📄 pooladdr.c
字号:
memcpy (packet->RP_CHUNKS, chunks, sizeof (ADDRESS_CHUNK) * count); total_length = SIZEOF_RADIPA_ALLOCATE (count); } else { total_length = SIZEOF_RADIPA; } bytes_sent = send (sockfd, (char *) send_buffer, total_length, 0); if (bytes_sent < 0) { if (timeout) { logit (LOG_DAEMON, LOG_ERR, "%s: timeout on connect to %s", func, ip_hostname (router_address)); } else { logit (LOG_DAEMON, LOG_ERR, "%s: Can't send release ipaddr request to %s: %s", func, ip_hostname (router_address), get_errmsg ()); } return (-1); } return bytes_sent;} /* end of ip_address_send () *//************************************************************************* * * Function: ip_address_recv * * Purpose: Reads RADIPAD replies from server. * * Returns: 0, if successful, * -1, otherwise. * *************************************************************************/static intip_address_recv (ipaddr, authreq)UINT4 ipaddr;AUTH_REQ *authreq;{ int total_length; UINT4 ip_address; RADIPA_PACKET *packet; static char *func = "ip_address_recv"; dprintf(2, (LOG_AUTH, LOG_DEBUG, "%s: entered", func)); if ((total_length = recv (sockfd, (char *) recv_buffer, sizeof (recv_buffer), 0)) < 0) { if (timeout) { logit (LOG_DAEMON, LOG_ERR, "%s: timeout on connect to %s", func, ip_hostname (ipaddr)); } else { logit (LOG_DAEMON, LOG_ERR, "%s: %s s=%s", func, get_errmsg (), ip_hostname (ipaddr)); } return (-1); } if (total_length == 0) { logit (LOG_DAEMON, LOG_ERR, "%s: EOF on radipad socket", func, strerror (errno)); return (-1); } if (authreq->code == PW_ASCEND_RADIPA_ALLOCATE) { packet = reorder_integers ((char *) recv_buffer); ip_address = packet->rp_ip_address; avpair_add (&authreq->cur_request, PW_FRAMED_IP_ADDRESS, &ip_address, 0); } return 0;} /* end of ip_address_recv () *//************************************************************************* * * Function: parse_global * * Purpose: Parse ASCEND_ASSIGN_IP_GLOBAL_POOL reply-item. * * Returns: 0, if pool name not found, * number of ADDRESS_CHUNKs found otherwise. * *************************************************************************/static intparse_global (pool_name, chunk_0)char *pool_name;ADDRESS_CHUNK *chunk_0;{ long count; char *base_addr_string; char *count_string; ADDRESS_CHUNK *chunk; VALUE_PAIR *reply_pairs; VALUE_PAIR *vp; ipaddr_t base_address; static char *func = "parse_global"; dprintf(2, (LOG_DAEMON, LOG_DEBUG, "%s: entered", func)); chunk = chunk_0; if (user_find (NULL, pool_name, 0, (VALUE_PAIR **) NULL, (VALUE_PAIR **) NULL, &reply_pairs, 0)) { logit (LOG_DAEMON, LOG_ERR, "%s: Pseudo-user '%s' not found", func, pool_name); return 0; } for (vp = reply_pairs; vp; vp = vp->next) { if (vp->attribute == ASCEND_IP_POOL_DEFINITION) { /* vp->strvalue[vp->lvalue] = '\0'; */ base_addr_string = strtok (vp->strvalue, white_space); if (!strchr (base_addr_string, '.')) { base_addr_string = strtok (NULL, white_space); } count_string = strtok (NULL, white_space); base_address = inet_addr (base_addr_string); count = strtol (count_string, (char **) NULL, 0); if (base_address == INADDR_NONE) { logit (LOG_DAEMON, LOG_ERR, "%s: Bogus pool definition address: %s", func, base_addr_string); } else if (count == 0) { logit (LOG_DAEMON, LOG_ERR, "%s: Bogus pool definition count: %s", func, count_string); } else { chunk->base_address = base_address; chunk->count = htonl(count); chunk++; } } } avpair_free (reply_pairs); return (chunk - chunk_0);} /* end of parse_global () *//************************************************************************* * * Function: parse_hosts * * Purpose: Extract the "radipa-hosts" pseudo-user from the users * file and parse the IP addresses. The server (if found) * is added to the clients list. Any other NAS clients * are also added to the clients list, if not already there. * * Returns: address of the RADIPAD server, or * INADDR_ANY, if RADIPA_HOSTS is not found. * *************************************************************************/static UINT4parse_hosts (){ UINT4 ipaddr; VALUE_PAIR *reply_pairs = 0; VALUE_PAIR *vp; static char *func = "parse_hosts"; dprintf(2, (LOG_DAEMON, LOG_DEBUG, "%s: entered", func)); if (user_find (NULL, RADIPA_HOSTS, 0, (VALUE_PAIR **) NULL, (VALUE_PAIR **) NULL, &reply_pairs, 0)) { logit (LOG_DAEMON, LOG_ERR, "%s: Pseudo-user '%s' not found", func, RADIPA_HOSTS); return INADDR_ANY; } for (vp = reply_pairs; vp; vp = vp->next) { if (vp->attribute == ASCEND_ASSIGN_IP_SERVER) { ipaddr = vp->lvalue; } } avpair_free (reply_pairs); return ipaddr;} /* end of parse_hosts () *//************************************************************************* * * Function: parse_pool * * Purpose: Given a user name, look for reply-items of pool names to * parse. Allocate memory for the "chunks" of IP addresses. * * Returns: 0, if user name not found, * number of ADDRESS_CHUNKs found otherwise. * *************************************************************************/static intparse_pool (user_name, chunks_ptr)char *user_name;ADDRESS_CHUNK **chunks_ptr;{ int chunks_malloced = 0; int count; ADDRESS_CHUNK *chunks; VALUE_PAIR *reply_pairs; VALUE_PAIR *vp; char pool_name[AUTH_STRING1_LEN + 1]; static char *func = "parse_pool"; dprintf(2, (LOG_DAEMON, LOG_DEBUG, "%s: entered", func)); if (user_find (NULL, user_name, 0, (VALUE_PAIR **) NULL, (VALUE_PAIR **) NULL, &reply_pairs, 0)) { logit (LOG_DAEMON, LOG_ERR, "%s: User '%s' not found", func, user_name); return 0; } if (*chunks_ptr == 0) { *chunks_ptr = MALLOC(ADDRESS_CHUNK, MAX_ADDRESS_CHUNKS); chunks_malloced = 1; } chunks = *chunks_ptr; for (vp = reply_pairs; vp; vp = vp->next) { if (vp->attribute == ASCEND_ASSIGN_IP_GLOBAL_POOL) { strncpy (pool_name, vp->strvalue, vp->lvalue); pool_name[vp->lvalue] = '\0'; chunks += parse_global (pool_name, chunks); } } avpair_free (reply_pairs); count = chunks - *chunks_ptr; if (chunks_malloced) { *chunks_ptr = REALLOC(*chunks_ptr, ADDRESS_CHUNK, count); } return count;} /* end of parse_pool () *//************************************************************************* * * Function: pool_time_out * * Purpose: Alarm signal handler to just set flag on alarm. * *************************************************************************/static voidpool_time_out (signal)int signal;{ /* Set flag. EINTR will cause blocking routines to look */ timeout = 1; } /* end of pool_time_out *//************************************************************************* * * Function: reorder_integers * * Purpose: Convert a request block from network to host byte ordering. * *************************************************************************/RADIPA_PACKET *reorder_integers (buf)char *buf;{ RADIPA_PACKET *request; static char *func = "reorder_integers"; dprintf(2, (LOG_DAEMON, LOG_DEBUG, "%s: entered", func)); request = (RADIPA_PACKET *) buf; request->rp_count = ntohs(request->rp_count); request->rp_ip_address = ntohl(request->rp_ip_address); request->rp_router_address = ntohl(request->rp_router_address); if (request->rp_code == RADIPA_ALLOCATE) { ADDRESS_CHUNK *chunk = request->RP_CHUNKS; ADDRESS_CHUNK *end = &chunk[request->rp_count]; for ( ; chunk < end ; chunk++) { chunk->base_address = ntohl(chunk->base_address); chunk->count = ntohl(chunk->count); } } return request;} /* end of reorder_integers () *//************************************************************************* * * Function: try_connect * * Purpose: Attempt to connect to the TCP socket. * * Returns: 1 if the TCP socket is in use, * 0 if the session is connected successfully, * -1 if there was an error or a timeout occurred. * *************************************************************************/static inttry_connect (addr)UINT4 addr;{ u_short svc_port; int loop_count; struct sockaddr_in sin; static char *func = "try_connect"; dprintf(2, (LOG_DAEMON, LOG_DEBUG, "%s: entered", func)); logit (LOG_DAEMON, LOG_INFO, "%s: Establishing connection to RADIPAD", func); svc_port = RADIPA_SERVICE_PORT; /* Use default configured value */ memset ((char *) &sin, '\0', sizeof (sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(addr); sin.sin_port = htons(svc_port); if (connect (sockfd, (struct sockaddr *) &sin, sizeof (sin)) < 0) { if (errno == EADDRINUSE) /* For possible other child. */ { sleep (2); return 1; } if (timeout) { logit (LOG_DAEMON, LOG_ERR, "%s: timeout on connect to %s", func, ip_hostname (addr)); } else { logit (LOG_DAEMON, LOG_ERR, "%s: %s dest=%s", func, get_errmsg (), ip_hostname (addr)); } return (-1); } return 0;} /* end of try_connect */#endif /* IP_ADDR_POOL */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -