This commit is contained in:
zhanglianghy 2019-09-20 17:58:49 +08:00
commit 07d41c8aea
16 changed files with 251 additions and 25 deletions

View File

@ -14,6 +14,7 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.opendaylight.controller.md.sal.binding.api.*;
import org.opendaylight.controller.md.sal.binding.api.MountPointService.MountPointListener;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
@ -65,7 +66,9 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -81,7 +84,7 @@ import static org.opendaylight.controller.md.sal.binding.api.DataObjectModificat
public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInfo>,
AutoCloseable {
AutoCloseable, MountPointListener {
private final ListenerRegistration<HuaweiNetconfSpeaker> configurationReg;
private MountPointService mountService;
@ -102,6 +105,9 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
public HuaweiNetconfSpeaker(DataBroker dataBroker, MountPointService mountService) {
this.dataBroker = dataBroker;
this.mountService = mountService;
if(null != this.mountService) {
this.mountService.registerListener(NETCONF_TOPO_IID, this);
}
InstanceIdentifier<ConnectorInfo> connectPath = InstanceIdentifier.create(ConnectorInfo.class);
final DataTreeIdentifier<ConnectorInfo> dataTreeIdentifier = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, connectPath);
configurationReg = dataBroker.registerDataTreeChangeListener(dataTreeIdentifier, this);
@ -145,13 +151,13 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
@Override
public void onFailure(Throwable throwable) {
LOG.error("Failed to created NetconfNode={}", netconfNode, throwable);
stopTask(connectDevice.getId().getValue());
// stopTask(connectDevice.getId().getValue());
}
@Override
public void onSuccess(Void avoid) {
LOG.info("NetconfNode={} created successfully", netconfNode);
startTask(connectDevice.getId().getValue());
// startTask(connectDevice.getId().getValue());
}
});
}
@ -273,7 +279,7 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
} catch (Exception e) {
LOG.error("捕获一个异常:{}", e);
}
}, 180000, 10000, TimeUnit.MILLISECONDS);
}, 10, 10000, TimeUnit.MILLISECONDS);
if (Objects.nonNull(threads.get(nodeId))) {
LOG.info("remove exist pool in thread map");
if (!threads.get(nodeId).isShutdown()) {
@ -289,14 +295,14 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
if (threads.containsKey(nodeId)) {
ScheduledExecutorService pool = threads.get(nodeId);
if (Objects.nonNull(pool)) {
pool.shutdown();
pool.shutdownNow();
}
threads.remove(nodeId);
}
}
private void readInfoFromDevice(String nodeId) {
LOG.info("开始向华为设备获取cpu信息");
LOG.info("开始向华为设备(id:{})获取cpu信息", nodeId);
final Optional<MountPoint> hwNodeOptional = mountService.getMountPoint(NETCONF_TOPO_IID
.child(Node.class, new NodeKey(new NodeId(nodeId))));
LOG.info("开始向华为设备获取cpu信息2");
@ -593,6 +599,48 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
return addressList;
}
/* (non-Javadoc)
* @see org.opendaylight.controller.md.sal.binding.api.MountPointService.MountPointListener#onMountPointCreated(org.opendaylight.yangtools.yang.binding.InstanceIdentifier)
*/
@Override
public void onMountPointCreated(InstanceIdentifier<?> path) {
LOG.info("onMountPointCreated: path is {}.", path);
String nodeid = getNodeidFromPath(path);
if (null != nodeid) {
startTask(nodeid);
} else {
LOG.error("can't get nodeid from path:{}", path);
}
}
/* (non-Javadoc)
* @see org.opendaylight.controller.md.sal.binding.api.MountPointService.MountPointListener#onMountPointRemoved(org.opendaylight.yangtools.yang.binding.InstanceIdentifier)
*/
@Override
public void onMountPointRemoved(InstanceIdentifier<?> path) {
LOG.info("onMountPointRemoved: path is {}.", path);
String nodeid = getNodeidFromPath(path);
if (null != nodeid) {
stopTask(nodeid);
}
}
private String getNodeidFromPath(InstanceIdentifier<?> path) {
InstanceIdentifier<Node> node = path.firstIdentifierOf(Node.class);
if (null == node) {
return null;
}
NodeId nodeId = node.firstKeyOf(Node.class).getNodeId();
if (null == nodeId) {
return null;
} else {
return nodeId.getValue();
}
}
}
/**

View File

@ -29,6 +29,9 @@ int cmhi_set_conntrack_u16(const struct sk_buff *skb, uint16_t value, cmhi_ext_t
case APP_ID:
ct->cmhi.app_id = value;
break;
case BASE_APP_ID:
ct->cmhi.base_app_id = value;
break;
default: {
printk(KERN_INFO"[CT_API]set-conntrak_u16: value is not u16\n");
return CMHI_EXT_ERR;
@ -159,6 +162,9 @@ int cmhi_get_conntrack_u16(const struct sk_buff *skb, uint16_t *value, cmhi_ext_
case APP_ID:
*value = ct->cmhi.app_id;
break;
case BASE_APP_ID:
*value = ct->cmhi.base_app_id;
break;
default: {
printk(KERN_INFO"[CT_API]get-conntrak_u16: value is not u16\n");
return CMHI_EXT_ERR;
@ -260,6 +266,9 @@ int cmhi_del_conntrack(const struct sk_buff *skb, cmhi_ext_type type)
case APP_ID:
ct->cmhi.app_id = 0;
break;
case BASE_APP_ID:
ct->cmhi.base_app_id = 0;
break;
case POLICY_VERSION:
ct->cmhi.policy_version = 0;
break;
@ -537,8 +546,29 @@ int __set_aid_by_dpi_tuple(struct nf_conn *ct, uint16_t aid)
}
/**********************************************************
* : id aid设置到相应的链接跟踪ct中
* : id aid
* : id base_aid设置到相应的链接跟踪ct中
* : struct nf_conn *id base_aid
* :
* : 0-1
**********************************************************/
int __set_base_aid_by_dpi_tuple(struct nf_conn *ct, uint16_t base_aid)
{
if(!ct){
printk(KERN_ERR"[CT_API]__set-base-appid-by-dpituple:input ct is null.\n");
return CMHI_EXT_ERR;
}
if(!ct){
printk(KERN_ERR"[CT_API]__set-base-appid-by-dpituple: ct is not existed or ct is untracked\n");
return CMHI_EXT_ERR;
}
ct->cmhi.base_app_id = base_aid;
return CMHI_EXT_OK;
}
/**********************************************************
* : id aid与base_aid设置到相应的链接跟踪ct中
* : id aid与base_aid
* Êä³ö: ÎÞ
* ·µ»ØÖµ: 0»ò-1
**********************************************************/
@ -562,6 +592,12 @@ int set_aid_by_dpi_tuple(struct dpi *dpi)
return CMHI_EXT_ERR;
}
printk(KERN_INFO"[CT_API]set-appid-by-dpituple: set aid ok\n");
ret = __set_base_aid_by_dpi_tuple(ct, dpi->base_aid);
if(CMHI_EXT_OK != ret){
printk(KERN_ERR"[CT_API]set-appid-by-dpituple:set base_aid failed.\n");
return CMHI_EXT_ERR;
}
printk(KERN_INFO"[CT_API]set-appid-by-dpituple: set base_aid ok\n");
return CMHI_EXT_OK;
}

View File

@ -17,6 +17,7 @@ typedef enum{
AUTH_MARK,
TC_MARK,
PBR_MARK,
BASE_APP_ID,
}cmhi_ext_type;
@ -42,6 +43,7 @@ struct dpi_tuple{
struct dpi{
struct dpi_tuple tuple; /* dpi???a¡Á¨¦ */
uint16_t aid; /* app id */
uint16_t base_aid; /* base app id */
};
int cmhi_set_conntrack_u16(const struct sk_buff *skb, uint16_t value, cmhi_ext_type type);

View File

@ -32,6 +32,14 @@ static unsigned int test_set_correct_value(void *priv, struct sk_buff *skb, cons
}
printk(KERN_INFO"[test_set_correct_value] set app_id successed\n");
printk(KERN_INFO"[test_set_correct_value] test set base_app_id 21\n");
ret = cmhi_set_conntrack_u16(skb, 21, BASE_APP_ID);
if(ret == CMHI_EXT_ERR){
printk(KERN_INFO"[test_set_correct_value] set base_app_id failed\n");
goto out;
}
printk(KERN_INFO"[test_set_correct_value] set base_app_id successed\n");
printk(KERN_INFO"[test_set_correct_value] test set user_id 30\n");
ret = cmhi_set_conntrack_u32(skb, 30, USER_ID);
if(ret == CMHI_EXT_ERR){
@ -119,6 +127,14 @@ static unsigned int test_set_value_by_wrong_interface(void *priv, struct sk_buff
}
printk(KERN_INFO"[test_set_value_by_wrong_interface] set app_id successed\n");
printk(KERN_INFO"[test_set_value_by_wrong_interface] test set base_app_id 21\n");
ret = cmhi_set_conntrack_u32(skb, 21, BASE_APP_ID);
if(ret == CMHI_EXT_ERR){
printk(KERN_INFO"[test_set_value_by_wrong_interface] set base_app_id failed\n");
goto out;
}
printk(KERN_INFO"[test_set_value_by_wrong_interface] set base_app_id successed\n");
printk(KERN_INFO"[test_set_value_by_wrong_interface] test set user_id 30\n");
ret = cmhi_set_conntrack_u16(skb, 30, USER_ID);
if(ret == CMHI_EXT_ERR){
@ -157,6 +173,7 @@ static unsigned int test_get_value_by_correct_interface(void *priv, struct sk_bu
u_int16_t user_version;
u_int32_t node_index;
u_int16_t app_id;
u_int16_t base_app_id;
u_int32_t policy_version;
u_int32_t action;
@ -194,6 +211,13 @@ static unsigned int test_get_value_by_correct_interface(void *priv, struct sk_bu
}
printk(KERN_INFO"[test_get_value_by_correct_interface]: get app_id: %d successed\n", app_id);
ret = cmhi_get_conntrack_u16(skb, &base_app_id, BASE_APP_ID);
if(ret == CMHI_EXT_ERR){
printk(KERN_INFO"[test_get_value_by_correct_interface]: get base_app_id failed\n");
goto out;
}
printk(KERN_INFO"[test_get_value_by_correct_interface]: get base_app_id: %d successed\n", base_app_id);
ret = cmhi_get_conntrack_u32(skb, &policy_version, POLICY_VERSION);
if(ret == CMHI_EXT_ERR){
printk(KERN_INFO"[test_get_value_by_correct_interface]: get policy_version failed\n");
@ -245,6 +269,7 @@ static unsigned int test_get_value_by_wrong_interface(void *priv, struct sk_buff
u_int32_t user_version;
u_int16_t node_index;
u_int32_t app_id;
u_int32_t base_app_id;
u_int16_t policy_version;
u_int16_t action;
@ -278,6 +303,13 @@ static unsigned int test_get_value_by_wrong_interface(void *priv, struct sk_buff
}
printk(KERN_INFO"[test_get_value_by_wrong_interface]: get app_id: %d successed\n", app_id);
ret = cmhi_get_conntrack_u32(skb, &base_app_id, BASE_APP_ID);
if(ret == CMHI_EXT_ERR){
printk(KERN_INFO"[test_get_value_by_wrong_interface]: get base_app_id failed\n");
goto out;
}
printk(KERN_INFO"[test_get_value_by_wrong_interface]: get base_app_id: %d successed\n", base_app_id);
ret = cmhi_get_conntrack_u16(skb, &policy_version, POLICY_VERSION);
if(ret == CMHI_EXT_ERR){
printk(KERN_INFO"[test_get_value_by_wrong_interface]: get policy_version failed\n");
@ -332,6 +364,13 @@ static unsigned int test_get_null_value(void *priv, struct sk_buff *skb, const s
}
printk(KERN_INFO"[test_get_null_value]: get app_id successed\n");
ret = cmhi_get_conntrack_u16(skb, NULL, BASE_APP_ID);
if(ret == CMHI_EXT_ERR){
printk(KERN_INFO"[test_get_null_value]: get base_app_id failed\n");
goto out;
}
printk(KERN_INFO"[test_get_null_value]: get base_app_id successed\n");
ret = cmhi_get_conntrack_u32(skb, NULL, POLICY_VERSION);
if(ret == CMHI_EXT_ERR){
printk(KERN_INFO"[test_get_null_value]: get policy_version failed\n");
@ -380,6 +419,13 @@ static unsigned int test_del_value(void *priv, struct sk_buff *skb, const struct
}
printk(KERN_INFO"[test_del_value]: del APP_ID successed\n");
ret = cmhi_del_conntrack(skb, BASE_APP_ID);
if(ret == CMHI_EXT_ERR){
printk(KERN_INFO"[test_del_value]: del BASE_APP_ID failed\n");
goto out;
}
printk(KERN_INFO"[test_del_value]: del BASE_APP_ID successed\n");
ret = cmhi_del_conntrack(skb, NODE_INDEX);
if(ret == CMHI_EXT_ERR){

View File

@ -43,7 +43,7 @@ enum test_proto_type{
};
/**********************************************************
* :aid,netfilter的hook上
* :aid与base_aid,netfilter的hook上
* :void *, struct sk_buff *, const struct nf_hook_state *
* :
* :
@ -52,6 +52,7 @@ static unsigned int get_aid_test(void *priv, struct sk_buff *skb, const struct n
{
int ret;
uint16_t aid;
uint16_t base_aid;
printk(KERN_INFO"[test]: test get app_id\n");
ret = cmhi_get_conntrack_u16(skb, &aid, APP_ID);
if(ret == CMHI_EXT_ERR){
@ -59,6 +60,14 @@ static unsigned int get_aid_test(void *priv, struct sk_buff *skb, const struct n
goto out;
}
printk(KERN_INFO"[test]: get app_id: %d successed\n", aid);
printk(KERN_INFO"[test]: test get base_app_id\n");
ret = cmhi_get_conntrack_u16(skb, &base_aid, BASE_APP_ID);
if(ret == CMHI_EXT_ERR){
printk(KERN_INFO"[test]: get base_app_id failed\n");
goto out;
}
printk(KERN_INFO"[test]: get base_app_id: %d successed\n", base_aid);
goto out;
out:
@ -138,7 +147,7 @@ out:
}
/**********************************************************
* :TCP的DPI五元组设置链接跟踪ct里的aid
* :TCP的DPI五元组设置链接跟踪ct里的aid与base_aid
* :
* :
* : 0-1
@ -154,8 +163,9 @@ int dpi_set_aid_test_tcp(void)
dpi.tuple.sport = htons(179);
dpi.tuple.dport = htons(10020);
dpi.aid = 3;
printk(KERN_INFO"[Test]dpi_tuple sip=%x, dip=%x, proto=%d, sport=%du, dport=%du,aid=%d\n",
dpi.tuple.sip, dpi.tuple.dip, dpi.tuple.protonum, dpi.tuple.sport, dpi.tuple.dport, dpi.aid);
dpi.base_aid = 3;
printk(KERN_INFO"[Test]dpi_tuple sip=%x, dip=%x, proto=%d, sport=%du, dport=%du,aid=%u, base_aid=%u\n",
dpi.tuple.sip, dpi.tuple.dip, dpi.tuple.protonum, dpi.tuple.sport, dpi.tuple.dport, dpi.aid, dpi.base_aid);
ret = set_aid_by_dpi_tuple(&dpi);
if(CMHI_EXT_OK != ret){
printk(KERN_ERR"[Test]set_aid_by_dpi_tuple failed.\n");
@ -165,7 +175,7 @@ int dpi_set_aid_test_tcp(void)
}
/**********************************************************
* :UDP的DPI五元组设置链接跟踪ct里的aid
* :UDP的DPI五元组设置链接跟踪ct里的aid与base_aid
* :
* :
* : 0-1
@ -181,8 +191,9 @@ int dpi_set_aid_test_udp(void)
dpi.tuple.sport = htons(7);
dpi.tuple.dport = htons(520);
dpi.aid = 5;
printk(KERN_INFO"[Test]dpi_set_aid_test_udp: dpi_tuple sip=%x, dip=%x, proto=%d, sport=%d, dport=%d,aid=%d\n",
dpi.tuple.sip, dpi.tuple.dip, dpi.tuple.protonum, dpi.tuple.sport, dpi.tuple.dport, dpi.aid);
dpi.base_aid = 5;
printk(KERN_INFO"[Test]dpi_set_aid_test_udp: dpi_tuple sip=%x, dip=%x, proto=%d, sport=%d, dport=%d,aid=%u, dpi.base_aid=%u\n",
dpi.tuple.sip, dpi.tuple.dip, dpi.tuple.protonum, dpi.tuple.sport, dpi.tuple.dport, dpi.aid, dpi.base_aid);
ret = set_aid_by_dpi_tuple(&dpi);
if(CMHI_EXT_OK != ret){
printk(KERN_ERR"[Test]dpi_set_aid_test_udp: set_aid_by_dpi_tuple failed.\n");

View File

@ -59,6 +59,10 @@ static int trace_rcv_policy(struct sk_buff *skb, struct nlmsghdr *nlh, struct ne
dpi.aid = policy->app_type;
printk(KERN_DEBUG " app_type:%u", policy->app_type);
dpi.base_aid = policy->base_type;
printk(KERN_DEBUG " base_type:%u", policy->base_type);
printk(KERN_DEBUG " src family:%u", policy->src.family);
if (policy->src.family == TRACE_FAMILY_IP4) {
dpi.tuple.sip = policy->src.addr.ip4.s_addr;

View File

@ -132,7 +132,7 @@ ret_code dhcp_client_get(uint source,
char *fname="/var/lib/dhcp/dhclient.leases";
FILE *fp;
char *lease_interface, *ip, *router;
cJSON *json = NULL;
//cJSON *json = NULL;
char *out = NULL;
char line[1000] = {0};
if ((fp=fopen(fname,"r"))==NULL){

View File

@ -264,7 +264,7 @@ ret_code dhcp_host_config_get(uint source,
char *fname="/etc/dhcp/dhcpd.conf";
FILE *fp;
char *name=NULL, *mac=NULL, *ip=NULL;
cJSON *json = NULL;
//cJSON *json = NULL;
char *out = NULL;
char line[1000] = {0};
int len;

View File

@ -80,6 +80,8 @@ char *getfileall(char *fname)
}
fclose(fp);
if(!strcmp(str, "")){
free(str);
str = NULL;
return NULL;
}
return str;
@ -121,6 +123,8 @@ char *getfilefirstline(char *fname)
}
fclose(fp);
if(!strcmp(str, "")){
free(str);
str = NULL;
return NULL;
}
return str;
@ -166,6 +170,8 @@ char *getfileall_with_linefeed(char *fname)
fclose(fp);
//printf("%s\n", str);
if(!strcmp(str, "")){
free(str);
str = NULL;
return NULL;
}
return str;
@ -519,6 +525,8 @@ char *wan_if_str(){
}
//free(ifname);
if(!strcmp(wanif, "")){
free(wanif);
wanif = NULL;
return NULL;
}
return wanif;

View File

@ -343,7 +343,7 @@ ret_code dhcp_subnet_config_get(uint source,
char *fname="/etc/dhcp/dhcpd.conf";
FILE *fp = NULL;
char *subnet=NULL, *netmask=NULL, *range=NULL, *dns=NULL, *submask=NULL, *routers=NULL, *lease=NULL;
cJSON *json = NULL;
//cJSON *json = NULL;
char *out = NULL;
char line[1000] = {0};
if ((fp=fopen(fname,"r"))==NULL){
@ -591,6 +591,9 @@ ret_code dhcp_subnet_config_get_all(uint source, pointer output, int *output_len
if(netmask != NULL){
free(netmask);
}
if(name != NULL){
free(name);
}
fclose(fp);
out = cJSON_PrintUnformatted(root);
*output_len = strlen(out) + 1;

View File

@ -30,6 +30,11 @@ extern int conf_file_write(char *conf_path, char *sum_buf);
ret_code routing_to_json(int count, routing_t *buff_total, pointer output, int *output_len)
{
if (NULL == buff_total)
{
return RET_EMPTY_STRING;
}
ret_code ret = RET_OK;
char *json_routing;
@ -658,7 +663,7 @@ ret_code routing_add(routing_t *conf_buff)
char string[STRING_LENGTH] = {0};
uint version_t = conf_buff->version;
uint netmask_t = conf_buff->netmask;
char route_type[10] = {0};
//char route_type[10] = {0};
ret_code ret = RET_OK;
char *destip_t = conf_buff->destip;
char *gw_t = conf_buff->gateway;
@ -678,6 +683,7 @@ ret_code routing_add(routing_t *conf_buff)
if(version_t == IPV4_VERSION)
{
char route_type[10] = {0};
if (netmask_t > IPV4_MIN_NETMASK && netmask_t < IPV4_MAX_NETMASK)
{
strcpy(route_type,"-net");
@ -746,7 +752,7 @@ ret_code routing_del(routing_t *conf_buff)
char string_del[STRING_LENGTH] = {0};
uint version_t = conf_buff->version;
uint netmask_t = conf_buff->netmask;
char route_type[10] = {0};
//char route_type[10] = {0};
ret_code ret = RET_OK;
char *destip_t = conf_buff->destip;
char *gw_t = conf_buff->gateway;
@ -758,6 +764,7 @@ ret_code routing_del(routing_t *conf_buff)
if(version_t == IPV4_VERSION)
{
char route_type[10] = {0};
if (netmask_t > IPV4_MIN_NETMASK && netmask_t < IPV4_MAX_NETMASK)
{
strcpy(route_type,"-net");
@ -1204,7 +1211,7 @@ ret_code routing_config_proc(uint source, uint config_type,
uint conf_type = config_type;
routing_t conf_buff = {0};
routing_t *routing_conf = &conf_buff;
int flag = 0;
//int flag = 0;
if(NULL == input)
{

View File

@ -503,10 +503,8 @@ ret_code authpara_config_get_proc(uint source, uint config_type,
}
memcpy(output, ret_char, ret_int);
free(ret_char);
cJSON_Delete(res);
cJSON_Delete(data);
return RET_OK;
}

View File

@ -753,9 +753,11 @@ ret_code freeauth_config_mov_proc(uint source, uint config_type,
freeauth_mov_json_parse(input, &conf_type, rule_mod);
printf("%s %d\n", rule_mod->name, rule_mod->after);
#if 0
if(input_len < sizeof(rule_mod_t)) {
return RET_INPUTERR;
}
#endif
/*判断一些目前全局变量存的数量 移动的数需要约束*/
for(i = 0; i < RULE_MAX_NUM; i++) {

View File

@ -5,6 +5,7 @@
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <arpa/inet.h>
#include "log.h"
#include "trace_api.h"
@ -23,6 +24,7 @@ int main(int argc, char **argv)
trace_client_init();
printf("argc num:%d\n", argc);
#if 0
int count = 1;
if (argc >= 2) {
count = atoi(argv[1]);
@ -43,6 +45,8 @@ int main(int argc, char **argv)
trace1.src.family = TRACE_FAMILY_IP4;
trace1.dst.family = TRACE_FAMILY_IP4;
trace1.protocol = 30;
trace1.app_type = 3;
trace1.base_type = 4;
if (async == 1) {
printf("async exec\n");
@ -57,6 +61,62 @@ int main(int argc, char **argv)
}
printf("send success\n");
}
#else
printf("usage: %s src_ip src_port dst_ip dst_port protocol is_async\n", argv[0]);
struct in_addr src_addr={0};
struct in_addr dst_addr={0};
u16 src_port = 0;
u16 dst_port = 0;
u16 prot = 6;
int async = 1;
if (argc >= 2) {
inet_aton(argv[1], &src_addr);
}
if (argc >= 3) {
src_port = atoi(argv[2]);
}
if (argc >= 4) {
inet_aton(argv[3], &dst_addr);
}
if (argc >= 5) {
dst_port = atoi(argv[4]);
}
if (argc >= 6) {
prot = atoi(argv[5]);
}
if (argc >= 7) {
async = atoi(argv[6]);
}
trace_policy_t trace1 = {0};
trace1.src.addr.ip4.s_addr = src_addr.s_addr;
trace1.dst.addr.ip4.s_addr = dst_addr.s_addr;
trace1.src.family = TRACE_FAMILY_IP4;
trace1.dst.family = TRACE_FAMILY_IP4;
trace1.sport = htons(src_port);
trace1.dport = htons(dst_port);
trace1.protocol = prot;
trace1.app_type = 3;
trace1.base_type = 4;
if (async == 1) {
printf("async exec\n");
trace_async_exec(&trace1, cb, NULL);
} else if (async == 2) {
printf("exec no reply\n");
trace_exec_no_reply(&trace1);
} else {
printf("sync exec\n");
trace_sync_exec(&trace1);
printf("sync final\n");
}
printf("send success\n");
#endif
//policy_client_exit();
if (async != 3) {

View File

@ -190,7 +190,7 @@ static trace_ret_t cfg_channel_send(const uint32_t seq, const trace_policy_t *p
req.policy.src.family, req.policy.src.addr.ip4.s_addr, req.policy.sport);
SYSLOG_DEBUG(" dst family:%u, dst ip:%02x, dport:%u",
req.policy.dst.family, req.policy.dst.addr.ip4.s_addr, req.policy.dport);
SYSLOG_DEBUG(" protocol:%u, app_type:%u", req.policy.protocol, req.policy.app_type);
SYSLOG_DEBUG(" protocol:%u, app_type:%u, base_type:%u", req.policy.protocol, req.policy.app_type, req.policy.base_type);
/*发送组装好的netlink消息*/
//if (commcfg_send(hdr) < 0) {

View File

@ -57,6 +57,7 @@ struct cmhi_ext_info {
uint32_t auth_mark;
uint32_t tc_mark;
uint32_t pbr_mark;
uint16_t base_app_id;
};
struct nf_conn {
/* Usage count in here is 1 for hash table, 1 per skb,