📄 natmgmt.c
字号:
pNatTblEntry->natTcpSyncSessionMaxIdleTime = pNatClass->tcp_connecting_timer; /* Fill up the log mask value using the various debug values */ if (pNatClass->printing_enabled) pNatTblEntry->natLogMask |= NAT_PRINT_ENABLED; if (pNatClass->initialization_printing_enabled) pNatTblEntry->natLogMask |= NAT_INIT_PRINT_ENABLED; if (pNatClass->trace_printing_enabled) pNatTblEntry->natLogMask |= NAT_TRACE_PRINT_ENABLED; if (pNatClass->data_printing_enabled) pNatTblEntry->natLogMask |= NAT_DATA_PRINT_ENABLED; if (pNatClass->error_printing_enabled) pNatTblEntry->natLogMask |= NAT_ERROR_PRINT_ENABLED; if (pNatClass->enabled) pNatTblEntry->natEnable = TRUE; else /* Do the boolean formatting for FALSE as per the MIB expectations */ pNatTblEntry->natEnable = 2; if (pNatClass->static_entries_enabled) pNatTblEntry->natStaticBindEnable = TRUE; else /* Do the boolean formatting for FALSE as per the MIB expectations */ pNatTblEntry->natStaticBindEnable = 2; pNatTblEntry->natDefXEnable = TRUE; pNatTblEntry->natGlobalAddrFilter = TRUE; return OK; }/************************************************************************** * * m2NatTblEntrySet - The SET routine for the NAT table objects * * This routine selects the NAT device described by the index field in * <pNatTblEntry> and attempts to modify the values of all the objects * mentioned using the bit masked <varsToSet> value. * * RETURNS: OK if a successful modification was done * ERROR otherwise */STATUS m2NatTblEntrySet ( NAT_TBL_ENTRY * pNatTblEntry, /* Pointer to the new values */ int varsToSet /* Mask of objects to set */ ) { NAT_CLASS * pNatClass = &nat; if (!pNatTblEntry) return ERROR; /* * If, at later time, the NAT implementation is upgraded to allow * the existance of more than one NAT device, uncomment the for * loop below and enclose all the code following it within this * for loop. Also, change the pNatClass initialization above to * NULL instead of the nat global's address. */ /* * for (index = 1; index <= NAT_NUM_DEVICES; index++) * { * if (nat[index] == pNatTblEntry->natIndex) * { * pNatClass = &nat[index]; * break; * } * } */ /* * If you uncomment the code above, change pNatTblEntry->index * to index. */ if (pNatTblEntry->natIndex > NUM_NAT_DEVICES) { errnoSet(S_m2Lib_ENTRY_NOT_FOUND); return ERROR; } if (varsToSet & NAT_SESS_MAX_IDLETIME) { pNatClass->ip_translation_entry_timer = pNatTblEntry->natSessionMaxIdleTime; } if (varsToSet & NAT_UDP_SESS_MAX_IDLETIME) { pNatClass->udp_translation_entry_timer = pNatTblEntry->natUdpSessionMaxIdleTime; } if (varsToSet & NAT_ICMP_SESS_MAX_IDLETIME) { pNatClass->icmp_translation_entry_timer = pNatTblEntry->natIcmpSessionMaxIdleTime; } if (varsToSet & NAT_TCPUP_SESS_MAX_IDLETIME) { pNatClass->tcp_connected_timer = pNatTblEntry->natTcpUpSessionMaxIdleTime; } if (varsToSet & NAT_TCPDISC_SESS_MAX_IDLETIME) { pNatClass->tcp_disconnected_timer = pNatTblEntry->natTcpDiscSessionMaxIdleTime; } if (varsToSet & NAT_TCPCLOS_SESS_MAX_IDLETIME) { pNatClass->tcp_closing_timer = pNatTblEntry->natTcpClosingSessionMaxIdleTime; } if (varsToSet & NAT_TCPSYNC_SESS_MAX_IDLETIME) { pNatClass->tcp_connecting_timer = pNatTblEntry->natTcpSyncSessionMaxIdleTime; } if (varsToSet & NAT_LOG_MASK) { if (pNatTblEntry->natLogMask & NAT_PRINT_ENABLED) { if (pNatClass->printing_enabled == 0) natBoolValModify (pNatClass->printing_enabled, (int *) &pNatClass->printing_enabled); } else { if (pNatClass->printing_enabled == 1) natBoolValModify (pNatClass->printing_enabled, (int *) &pNatClass->printing_enabled); } if (pNatTblEntry->natLogMask & NAT_INIT_PRINT_ENABLED) { if (pNatClass->initialization_printing_enabled == 0) natBoolValModify (pNatClass->initialization_printing_enabled, (int *) &pNatClass->initialization_printing_enabled); } else { if (pNatClass->initialization_printing_enabled == 1) natBoolValModify (pNatClass->initialization_printing_enabled, (int *) &pNatClass->initialization_printing_enabled); } if (pNatTblEntry->natLogMask & NAT_DATA_PRINT_ENABLED) { if (pNatClass->data_printing_enabled == 0) natBoolValModify (pNatClass->data_printing_enabled, (int *) &pNatClass->data_printing_enabled); } else { if (pNatClass->data_printing_enabled == 1) natBoolValModify (pNatClass->data_printing_enabled, (int *) &pNatClass->data_printing_enabled); } if (pNatTblEntry->natLogMask & NAT_TRACE_PRINT_ENABLED) { if (pNatClass->trace_printing_enabled == 0) natBoolValModify (pNatClass->trace_printing_enabled, (int *) &pNatClass->trace_printing_enabled); } else { if (pNatClass->trace_printing_enabled == 1) natBoolValModify (pNatClass->trace_printing_enabled, (int *) &pNatClass->trace_printing_enabled); } if (pNatTblEntry->natLogMask & NAT_ERROR_PRINT_ENABLED) { if (pNatClass->error_printing_enabled == 0) natBoolValModify (pNatClass->error_printing_enabled, (int *) &pNatClass->error_printing_enabled); } else { if (pNatClass->error_printing_enabled == 1) natBoolValModify (pNatClass->error_printing_enabled, (int *) &pNatClass->error_printing_enabled); } } if (varsToSet & NAT_ENABLE) { natBoolValModify (pNatClass->enabled, (int *)&pNatClass->enabled); } if (varsToSet & NAT_STATIC_BIND_ENABLE) { natBoolValModify (pNatClass->static_entries_enabled, (int *)&pNatClass->static_entries_enabled); } return OK; }/************************************************************************** * * m2NatBindTblEntrySet - The SET routine for the NAT bind table objects * * This routine provides an interface to create/modify/delete a bind * relationship in the bind table. If the address tuples, identifying * a bind entry, do not match an entry in the translation lists, a * new entry is created. Otherwise, we try to either modify an existing * entry in the translation table or delete it. * * Currently, the only actions that are supported are CREATE a new row * or DELETE an entire row. * * RETURNS: OK if successful * ERROR otherwise */STATUS m2NatBindTblEntrySet ( NAT_BINDTBL_ENTRY * pNatBindEntry, /* Pointer to buffer */ int varsToSet /* Bit mask of variables to set */ ) { int found = 0; int matchType = 0; void * pBestEntry = NULL; TCP_TRANSLATION_ENTRY * pTcpEntry = NULL; UDP_TRANSLATION_ENTRY * pUdpEntry = NULL; char addr[INET_ADDR_LEN]; struct in_addr iaddr; if (!pNatBindEntry) return ERROR; /* * We do not have an appropriate API in NAT to create bindings for Basic * mode. So, we bail out for Basic NAT */ if (nat.single_global_address_enabled == FALSE) return ERROR; /* * We first walk through the list and see if the address tuple * pair provided to us matches an exisiting entry. */ switch (pNatBindEntry->natBindProto) { case TCP_TRANS_LIST: pTcpEntry = (TCP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) &nat.nats.tcp_translation_list); while (pTcpEntry) { if (transListWalk ( &pTcpEntry->local_address, &pTcpEntry->local_port, &pTcpEntry->remote_address, &pTcpEntry->remote_port, &pNatBindEntry->natBindLocalAddress, &pNatBindEntry->natBindLocalPort, &pNatBindEntry->natBindRemAddress, &pNatBindEntry->natBindRemPort, 0, 0, 0, 0, NAT_NAPT, GET_VALUE ) != ERROR) { pBestEntry = pTcpEntry; matchType = TCP_TRANS_LIST; found = 1; break; } pTcpEntry = (TCP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) pTcpEntry); } break; case UDP_TRANS_LIST: pUdpEntry = (UDP_TRANSLATION_ENTRY *) DLL_FIRST((DL_LIST *) &nat.nats.udp_translation_list); while (pUdpEntry) { if (transListWalk ( &pUdpEntry->local_address, &pUdpEntry->local_port, &pUdpEntry->remote_address, &pUdpEntry->remote_port, &pNatBindEntry->natBindLocalAddress, &pNatBindEntry->natBindLocalPort, &pNatBindEntry->natBindRemAddress, &pNatBindEntry->natBindRemPort, 0, 0, 0, 0, NAT_NAPT, GET_VALUE ) != ERROR) { pBestEntry = pUdpEntry; matchType = UDP_TRANS_LIST; found = 1; break; } pUdpEntry = (UDP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) pUdpEntry); } break; default: errnoSet(S_m2Lib_ENTRY_NOT_FOUND); return ERROR; } iaddr.s_addr = ntohl(pNatBindEntry->natBindLocalAddress); inet_ntoa_b(iaddr, addr); if ( (!found) && (pNatBindEntry->natBindAction == NAT_BIND_CREATE) ) { /* Create a new entry, since we did not find one */ if (pNatBindEntry->natBindProto == TCP_TRANS_LIST) { if (natTcpStaticAdd ( addr, pNatBindEntry->natBindLocalPort, pNatBindEntry->natBindRemPort ) != OK) { return ERROR; } } else { /* Create a UDP entry */ if (natUdpStaticAdd (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -