2017-07-06 01:01:16 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* net/devif/devif_forward.c
|
|
|
|
*
|
2021-02-19 19:45:37 +08:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-07-06 01:01:16 +08:00
|
|
|
*
|
2021-02-19 19:45:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-07-06 01:01:16 +08:00
|
|
|
*
|
2021-02-19 19:45:37 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-07-06 01:01:16 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2017-07-08 11:32:10 +08:00
|
|
|
#include <nuttx/mm/iob.h>
|
2017-07-06 01:01:16 +08:00
|
|
|
#include <nuttx/net/netdev.h>
|
|
|
|
|
2017-07-08 08:45:58 +08:00
|
|
|
#include "ipforward/ipforward.h"
|
2017-07-06 01:01:16 +08:00
|
|
|
#include "devif/devif.h"
|
|
|
|
|
2017-08-09 04:24:12 +08:00
|
|
|
#ifdef CONFIG_NET_IPFORWARD
|
2017-07-06 01:01:16 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: devif_forward
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Called from protocol-specific IP forwarding logic to re-send a packet.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* fwd - An initialized instance of the common forwarding structure that
|
|
|
|
* includes everything needed to perform the forwarding operation.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void devif_forward(FAR struct forward_s *fwd)
|
|
|
|
{
|
|
|
|
unsigned int offset;
|
|
|
|
int ret;
|
|
|
|
|
2017-07-07 06:19:10 +08:00
|
|
|
DEBUGASSERT(fwd != NULL && fwd->f_iob != NULL && fwd->f_dev != NULL);
|
2017-07-06 01:01:16 +08:00
|
|
|
offset = NET_LL_HDRLEN(fwd->f_dev);
|
|
|
|
|
2017-07-07 06:19:10 +08:00
|
|
|
/* Copy the IOB chain that contains the L3L3 headers and any data payload */
|
2017-07-06 01:01:16 +08:00
|
|
|
|
2018-07-05 04:10:40 +08:00
|
|
|
DEBUGASSERT(offset + fwd->f_iob->io_pktlen <= NETDEV_PKTSIZE(fwd->f_dev));
|
2017-07-07 06:19:10 +08:00
|
|
|
ret = iob_copyout(&fwd->f_dev->d_buf[offset], fwd->f_iob,
|
|
|
|
fwd->f_iob->io_pktlen, 0);
|
2017-07-06 01:01:16 +08:00
|
|
|
|
2017-07-07 06:19:10 +08:00
|
|
|
DEBUGASSERT(ret == fwd->f_iob->io_pktlen);
|
2017-07-06 01:01:16 +08:00
|
|
|
|
2017-07-08 10:19:26 +08:00
|
|
|
fwd->f_dev->d_sndlen = 0;
|
2017-11-29 08:54:17 +08:00
|
|
|
fwd->f_dev->d_len = fwd->f_iob->io_pktlen;
|
2017-08-13 00:27:55 +08:00
|
|
|
|
|
|
|
UNUSED(ret);
|
2017-07-06 01:01:16 +08:00
|
|
|
}
|
|
|
|
|
2017-08-09 04:24:12 +08:00
|
|
|
#endif /* CONFIG_NET_IPFORWARD */
|