net/netlink/: Misc bugfixes from initial testing using NSH 'arp -t' command.
This commit is contained in:
parent
3439720739
commit
7bd045130c
|
@ -439,6 +439,8 @@ void arp_hdr_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr);
|
|||
#ifdef CONFIG_NETLINK_ROUTE
|
||||
unsigned int arp_snapshot(FAR struct arp_entry_s *snapshot,
|
||||
unsigned int nentries);
|
||||
#else
|
||||
# define arp_snapshot(s,n) (0)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -476,6 +478,7 @@ void arp_dump(FAR struct arp_hdr_s *arp);
|
|||
# define arp_delete(i)
|
||||
# define arp_update(i,m);
|
||||
# define arp_hdr_update(i,m);
|
||||
# define arp_snapshot(s,n) (0)
|
||||
# define arp_dump(arp)
|
||||
|
||||
#endif /* CONFIG_NET_ARP */
|
||||
|
|
|
@ -86,7 +86,6 @@ struct nlroute_sendto_request_s
|
|||
|
||||
struct nlroute_recvfrom_response_s
|
||||
{
|
||||
FAR struct netlink_reqdata_s *flink;
|
||||
struct nlmsghdr hdr;
|
||||
struct ndmsg msg;
|
||||
struct rtattr attr;
|
||||
|
@ -96,6 +95,15 @@ struct nlroute_recvfrom_response_s
|
|||
#define SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(n) \
|
||||
(sizeof(struct nlroute_recvfrom_response_s) + (n) - 1)
|
||||
|
||||
struct nlroute_recvfrom_rsplist_s
|
||||
{
|
||||
FAR struct netlink_reqdata_s *flink;
|
||||
struct nlroute_recvfrom_response_s payload;
|
||||
};
|
||||
|
||||
#define SIZEOF_NLROUTE_RECVFROM_RSPLIST_S(n) \
|
||||
(sizeof(struct nlroute_recvfrom_rsplist_s) + (n) - 1)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
@ -131,11 +139,11 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
|
|||
|
||||
if (req->hdr.nlmsg_type == RTM_GETNEIGH && req->msg.ndm_family == AF_INET)
|
||||
{
|
||||
FAR struct nlroute_recvfrom_response_s *entry;
|
||||
FAR struct nlroute_recvfrom_rsplist_s *entry;
|
||||
unsigned int ncopied;
|
||||
size_t tabsize;
|
||||
size_t paysize;
|
||||
size_t entsize;
|
||||
size_t rspsize;
|
||||
size_t allocsize;
|
||||
|
||||
/* Preallocate memory to hold the maximum sized ARP table
|
||||
* REVISIT: This is probably excessively large and could cause false
|
||||
|
@ -143,11 +151,11 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
|
|||
* the number of valid entries in the ARP table.
|
||||
*/
|
||||
|
||||
tabsize = CONFIG_NET_ARPTAB_SIZE * sizeof( struct arp_entry_s);
|
||||
paysize = SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(tabsize);
|
||||
entsize = SIZEOF_NETLINK_RESPONSE_S(paysize);
|
||||
tabsize = CONFIG_NET_ARPTAB_SIZE * sizeof( struct arp_entry_s);
|
||||
rspsize = SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(tabsize);
|
||||
allocsize = SIZEOF_NLROUTE_RECVFROM_RSPLIST_S(tabsize);
|
||||
|
||||
entry = (FAR struct nlroute_recvfrom_response_s *)kmm_malloc(entsize);
|
||||
entry = (FAR struct nlroute_recvfrom_rsplist_s *)kmm_malloc(allocsize);
|
||||
if (entry == NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
|
@ -155,18 +163,18 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
|
|||
|
||||
/* Populate the entry */
|
||||
|
||||
memcpy(&entry->hdr, &req->hdr, sizeof(struct nlmsghdr));
|
||||
entry->hdr.nlmsg_len = paysize;
|
||||
memcpy(&entry->msg, &req->msg, sizeof(struct ndmsg));
|
||||
entry->attr.rta_len = tabsize;
|
||||
entry->attr.rta_type = 0;
|
||||
memcpy(&entry->payload.hdr, &req->hdr, sizeof(struct nlmsghdr));
|
||||
entry->payload.hdr.nlmsg_len = rspsize;
|
||||
memcpy(&entry->payload.msg, &req->msg, sizeof(struct ndmsg));
|
||||
entry->payload.attr.rta_len = tabsize;
|
||||
entry->payload.attr.rta_type = 0;
|
||||
|
||||
/* Lock the network so that the ARP table will be stable, then copy
|
||||
* the ARP table into the allocated memory.
|
||||
*/
|
||||
|
||||
net_lock();
|
||||
ncopied = arp_snapshot((FAR struct arp_entry_s *)entry->data,
|
||||
ncopied = arp_snapshot((FAR struct arp_entry_s *)entry->payload.data,
|
||||
CONFIG_NET_ARPTAB_SIZE);
|
||||
net_unlock();
|
||||
|
||||
|
@ -176,28 +184,28 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
|
|||
|
||||
if (ncopied < CONFIG_NET_ARPTAB_SIZE)
|
||||
{
|
||||
FAR struct nlroute_recvfrom_response_s *newentry;
|
||||
FAR struct nlroute_recvfrom_rsplist_s *newentry;
|
||||
|
||||
tabsize = ncopied * sizeof( struct arp_entry_s);
|
||||
paysize = SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(tabsize);
|
||||
entsize = SIZEOF_NETLINK_RESPONSE_S(paysize);
|
||||
rspsize = SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(tabsize);
|
||||
allocsize = SIZEOF_NLROUTE_RECVFROM_RSPLIST_S(tabsize);
|
||||
|
||||
newentry = (FAR struct nlroute_recvfrom_response_s *)
|
||||
kmm_realloc(entry, entsize);
|
||||
newentry = (FAR struct nlroute_recvfrom_rsplist_s *)
|
||||
kmm_realloc(entry, allocsize);
|
||||
|
||||
if (newentry != NULL)
|
||||
{
|
||||
entry = newentry;
|
||||
}
|
||||
|
||||
entry->hdr.nlmsg_len = paysize;
|
||||
entry->attr.rta_len = tabsize;
|
||||
entry->payload.hdr.nlmsg_len = rspsize;
|
||||
entry->payload.attr.rta_len = tabsize;
|
||||
}
|
||||
|
||||
/* Finally, add the data to the list of pending responses */
|
||||
|
||||
netlink_add_response(psock, (FAR struct netlink_response_s *)entry);
|
||||
return OK;
|
||||
return len;
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -222,41 +230,46 @@ ssize_t netlink_route_recvfrom(FAR struct socket *psock,
|
|||
size_t len, int flags,
|
||||
FAR struct sockaddr_nl *from)
|
||||
{
|
||||
FAR struct nlroute_recvfrom_response_s *resp;
|
||||
FAR struct nlroute_recvfrom_rsplist_s *entry;
|
||||
ssize_t ret;
|
||||
|
||||
DEBUGASSERT(psock != NULL && nlmsg != NULL &&
|
||||
nlmsg->nlmsg_len >= sizeof(struct nlmsghdr) &&
|
||||
len >= sizeof(struct nlmsghdr) &&
|
||||
from != NULL);
|
||||
len >= sizeof(struct nlmsghdr));
|
||||
|
||||
/* Find the response to this message */
|
||||
|
||||
net_lock();
|
||||
resp = (FAR struct nlroute_recvfrom_response_s *)
|
||||
entry = (FAR struct nlroute_recvfrom_rsplist_s *)
|
||||
netlink_get_response(psock, nlmsg);
|
||||
net_unlock();
|
||||
|
||||
if (resp == NULL)
|
||||
if (entry == NULL)
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (len < resp->hdr.nlmsg_len)
|
||||
if (len < entry->payload.hdr.nlmsg_len)
|
||||
{
|
||||
kmm_free(resp);
|
||||
kmm_free(entry);
|
||||
return -EMSGSIZE;
|
||||
}
|
||||
|
||||
memcpy(nlmsg, resp, resp->hdr.nlmsg_len);
|
||||
memcpy(nlmsg, &entry->payload, entry->payload.hdr.nlmsg_len);
|
||||
|
||||
/* Return address. REVISIT... this is just a guess. */
|
||||
|
||||
from->nl_family = resp->msg.ndm_family;
|
||||
from->nl_pad = 0;
|
||||
from->nl_pid = resp->hdr.nlmsg_pid;
|
||||
from->nl_groups = resp->hdr.nlmsg_type;
|
||||
if (from != NULL)
|
||||
{
|
||||
from->nl_family = entry->payload.msg.ndm_family;
|
||||
from->nl_pad = 0;
|
||||
from->nl_pid = entry->payload.hdr.nlmsg_pid;
|
||||
from->nl_groups = entry->payload.hdr.nlmsg_type;
|
||||
}
|
||||
|
||||
return resp->hdr.nlmsg_len;
|
||||
ret = entry->payload.hdr.nlmsg_len;
|
||||
kmm_free(entry);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NETLINK_ROUTE */
|
||||
|
|
|
@ -593,15 +593,14 @@ static ssize_t netlink_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
int ret;
|
||||
|
||||
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL &&
|
||||
to != NULL && tolen >= sizeof(struct nlmsghdr));
|
||||
to != NULL && tolen >= sizeof(struct sockaddr_nl));
|
||||
|
||||
conn = (FAR struct netlink_conn_s *)psock->s_conn;
|
||||
|
||||
/* Get a reference to the netlink message */
|
||||
|
||||
nlmsg = (FAR struct nlmsghdr *)buf;
|
||||
DEBUGASSERT(nlmsg->nlmsg_len >= sizeof(struct nlmsghdr) &&
|
||||
tolen >= nlmsg->nlmsg_len);
|
||||
DEBUGASSERT(nlmsg->nlmsg_len >= sizeof(struct nlmsghdr));
|
||||
|
||||
switch (conn->protocol)
|
||||
{
|
||||
|
@ -652,8 +651,9 @@ static ssize_t netlink_recvfrom(FAR struct socket *psock, FAR void *buf,
|
|||
FAR struct nlmsghdr *nlmsg;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL &&
|
||||
from != NULL && *fromlen >= sizeof(struct nlmsghdr));
|
||||
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL);
|
||||
DEBUGASSERT(from == NULL ||
|
||||
(fromlen != NULL && *fromlen >= sizeof(struct sockaddr_nl)));
|
||||
|
||||
conn = (FAR struct netlink_conn_s *)psock->s_conn;
|
||||
|
||||
|
@ -667,7 +667,11 @@ static ssize_t netlink_recvfrom(FAR struct socket *psock, FAR void *buf,
|
|||
case NETLINK_ROUTE:
|
||||
ret = netlink_route_recvfrom(psock, nlmsg, len, flags,
|
||||
(FAR struct sockaddr_nl *)from);
|
||||
*fromlen = sizeof(struct sockaddr_nl);
|
||||
if (ret >= 0 && fromlen != NULL)
|
||||
{
|
||||
*fromlen = sizeof(struct sockaddr_nl);
|
||||
}
|
||||
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue