-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ttl: track ttl value to decrase it or drop pkt if value exceeded
Signed-off-by: hanen mizouni <[email protected]>
- Loading branch information
1 parent
db56b17
commit ca1a131
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* Copyright 2015 Outscale SAS | ||
* | ||
* This file is part of Packetgraph. | ||
* | ||
* Packetgraph is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as published | ||
* by the Free Software Foundation. | ||
* | ||
* Packetgraph is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Packetgraph. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef _PG_TTL_H | ||
#define _PG_TTL_H | ||
|
||
#include <packetgraph/common.h> | ||
#include <packetgraph/errors.h> | ||
//#include <rte_mbuf.h> | ||
|
||
/** | ||
* Create a new ttl brick | ||
* | ||
* @param name brick's name | ||
* @param errp is set in case of an error | ||
* @return a pointer to a brick structure on success, NULL on error | ||
*/ | ||
PG_WARN_UNUSED | ||
|
||
void pg_ttl_handle(const char *name, struct rte_mbuf *pkt, | ||
uint16_t ttl, struct pg_error **errp); | ||
|
||
#endif /* _PG_TTL_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* Copyright 2015 Outscale SAS | ||
* | ||
* This file is part of Packetgraph. | ||
* | ||
* Packetgraph is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as published | ||
* by the Free Software Foundation. | ||
* | ||
* Packetgraph is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Packetgraph. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <packetgraph/packetgraph.h> | ||
#include "brick-int.h" | ||
#include "utlis/network.h" | ||
#include <errno.h> | ||
#include <rte_mbuf.h> | ||
|
||
void pg_ttl_handle(const char *name, struct rte_mbuf *pkt, | ||
uint16_t ttl, struct pg_error **errp) | ||
{ | ||
struct ether_hdr *hdr; | ||
|
||
hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *); | ||
switch (rte_cpu_to_be_16(hdr->ethernet.ether_type)) { | ||
case ETHER_TYPE_IPv4 : | ||
ttl = hdr->ipv4.time_to_live; | ||
break; | ||
case ETHER_TYPE_IPv6 : | ||
ttl = hdr->ipv6.hop_limits; | ||
break; | ||
default : | ||
*errp = pg_error_new("error occured in ethernet.ether_type"); | ||
return ; | ||
} | ||
if (ttl == 0) { | ||
//drop pkt and ICMP msg | ||
rte_pktmbuf_free(pkt); | ||
} else { | ||
ttl--; | ||
} | ||
} | ||
|