Exemplo n.º 1
0
void Update_Network_Full_Flag( int action_flag, int value ) {
	char	qbuf[200];

	if (my_nets == NULL) return;

	if (action_flag == FULLFLAG_seton) {
		snprintf( qbuf, 200, "update config_nets set full_flag = 'YES' " \
			"where nettype = '%s' and cmts_ip = '%s' " \
			"and cmts_vlan = %d and network = '%s' ",
			my_nets[value].s_nettype, my_nets[value].s_cmts_ip,
			my_nets[value].cmts_vlan, my_nets[value].s_network );
	}

	if (action_flag == FULLFLAG_setoff) {
		snprintf( qbuf, 200, "update config_nets set full_flag = 'NO' " \
			"where nettype = '%s' and cmts_ip = '%s' " \
			"and cmts_vlan = %d and network = '%s' ",
			my_nets[value].s_nettype, my_nets[value].s_cmts_ip,
			my_nets[value].cmts_vlan, my_nets[value].s_network );
	}

	if (action_flag == FULLFLAG_clearall) {
		snprintf( qbuf, 200, "update config_nets set full_flag = 'NO' where cmts_vlan = %d",
			value );
	}
	SQL_QUERY_RET( qbuf );
}
Exemplo n.º 2
0
void  my_WriteNewCMLease( dhcp_message *message ) {
	char	qbuf[500];

	snprintf( qbuf, 500, "replace into docsis_update ( ipaddr, modem_macaddr, thetime ) "
		"values ( '%s', '%s', now() ) ", message->s_ipaddr, message->s_macaddr );
	SQL_QUERY_RET( qbuf );
}
Exemplo n.º 3
0
void  my_UpdateTime( dhcp_message *message ) {
    char	qbuf[500];

    snprintf( qbuf, 500, "update dhcp_leases set update_time = now() " \
              "where ipaddr = '%s' ", message->s_ipaddr );
    SQL_QUERY_RET( qbuf );
}
Exemplo n.º 4
0
void  my_DeleteLease( dhcp_message *message ) {
    char    qbuf[500];

    snprintf( qbuf, 500, "insert into dhcp_oldleases "
              "select *, now() from dhcp_leases where ipaddr = '%s' and lockip_flag = 'NO'",
              message->s_ipaddr );
    SQL_QUERY_RET( qbuf );

    snprintf( qbuf, 500, "delete from dhcp_leases where ipaddr = '%s' and lockip_flag = 'NO'",
              message->s_ipaddr );
    SQL_QUERY_RET( qbuf );

    strcpy( message->s_ipaddr, "" );
    message->b_ipaddr = 0;
    message->ipaddr = 0;
    message->vlan = 0;
}
Exemplo n.º 5
0
void  my_UpdateLease( dhcp_message *message ) {
    char	qbuf[500];

    snprintf( qbuf, 100, "delete from dhcp_leases "
              "where macaddr = '%s-x' and lockip_flag = 'NO' ",
              message->s_macaddr );
    SQL_QUERY_RET( qbuf );

    if (message->in_opts.agent_mac_len > 0) {
        snprintf( qbuf, 100, "update dhcp_leases "
                  "set modem_macaddr = '%s' where ipaddr = '%s' ",
                  message->s_modem_macaddr, message->s_ipaddr );
        SQL_QUERY_RET( qbuf );
    }

    if (message->in_opts.host_name_len > 0) {
        snprintf( qbuf, 500, "update dhcp_leases "
                  "set pc_name = '%s' where ipaddr = '%s' ",
                  message->in_opts.host_name, message->s_ipaddr );
        SQL_QUERY_RET( qbuf );
    }

    if (message->subnum > 0) {
        snprintf( qbuf, 100, "update dhcp_leases "
                  "set subnum = '%llu' where ipaddr = '%s' ",
                  message->subnum, message->s_ipaddr );
        SQL_QUERY_RET( qbuf );
    }

    snprintf( qbuf, 150, "update dhcp_leases set start_time = now(), "
              "end_time = date_add(now(),interval %ld second), "
              "cmts_vlan = %d where ipaddr = '%s' ",
              message->lease_time, message->vlan, message->s_ipaddr );
    SQL_QUERY_RET( qbuf );
    my_Update_PowerDNS( message );
}
Exemplo n.º 6
0
void  my_WriteNewCPELease( dhcp_message *message ) {
    char	*s_dynam;
    char	qbuf[220];

    s_dynam = "NO";
    if (message->cpe_type == CPE_DYNAMIC) {
        s_dynam = "YES";
    }

    snprintf( qbuf, 220, "replace into dhcp_leases "
              "( ipaddr, macaddr, start_time, end_time, update_time, "
              "cmts_vlan, dynamic_flag, subnum ) "
              " values ( '%s', '%s', now(), now(), now(), %d, '%s', %llu ) ",
              message->s_ipaddr, message->s_macaddr, message->vlan,
              s_dynam, message->subnum );
    SQL_QUERY_RET( qbuf );
    my_Update_PowerDNS( message );
}
Exemplo n.º 7
0
void  my_UpdateAgent( dhcp_message *message ) {
	char	qbuf[1000];
	char	*mce_concat, *mce_ver, *mce_frag, *mce_phs, *mce_igmp;
	char	*mce_bpi, *mce_filt_dot1p, *mce_filt_dot1q, *mce_dcc;
	char	version[11], mce_ds_said[sizeof(int) + 1], mce_us_sid[sizeof(int) + 1], mce_tetps[sizeof(int) + 1], mce_ntet[sizeof(int) + 1];

	if (message->in_opts.agent_mac_len == 0) return;

	mce_concat = "NULL";
	if (message->in_opts.mce_concat == 0) mce_concat = "'NO'";
	if (message->in_opts.mce_concat == 1) mce_concat = "'YES'";
	mce_ver = "NULL";
	if (message->in_opts.mce_ver == 0) mce_ver = "'v1.0'";
	if (message->in_opts.mce_ver == 1) mce_ver = "'v1.1'";
	if (message->in_opts.mce_ver == 2) mce_ver = "'v2.0'";
	mce_frag = "NULL";
	if (message->in_opts.mce_frag == 0) mce_frag = "'NO'";
	if (message->in_opts.mce_frag == 1) mce_frag = "'YES'";
	mce_phs = "NULL";
	if (message->in_opts.mce_phs == 0) mce_phs = "'NO'";
	if (message->in_opts.mce_phs == 1) mce_phs = "'YES'";
	mce_igmp = "NULL";
	if (message->in_opts.mce_igmp == 0) mce_igmp = "'NO'";
	if (message->in_opts.mce_igmp == 1) mce_igmp = "'YES'";
	mce_bpi = "NULL";
	if (message->in_opts.mce_bpi == 0) mce_bpi = "'BPI'";
	if (message->in_opts.mce_bpi == 1) mce_bpi = "'BPI+'";
	mce_filt_dot1p = "NULL";
	if (message->in_opts.mce_filt_dot1p == 0) mce_filt_dot1p = "'NO'";
	if (message->in_opts.mce_filt_dot1p == 1) mce_filt_dot1p = "'YES'";
	mce_filt_dot1q = "NULL";
	if (message->in_opts.mce_filt_dot1q == 0) mce_filt_dot1q = "'NO'";
	if (message->in_opts.mce_filt_dot1q == 1) mce_filt_dot1q = "'YES'";
	mce_dcc = "NULL";
	if (message->in_opts.mce_dcc == 0) mce_dcc = "'NO'";
	if (message->in_opts.mce_dcc == 1) mce_dcc = "'YES'";

	strcpy( version, "" );
	if (*message->in_opts.version != 0)
		snprintf( version, 10, "%s", message->in_opts.version );
	strcpy( mce_ds_said, "NULL" );
	if (message->in_opts.mce_ds_said >= 0)
		snprintf( mce_ds_said, sizeof(int), "'%d'", message->in_opts.mce_ds_said );
	strcpy( mce_us_sid, "NULL" );
	if (message->in_opts.mce_us_sid >= 0)
		snprintf( mce_us_sid, sizeof(int), "'%d'", message->in_opts.mce_us_sid );
	strcpy( mce_tetps, "NULL" );
	if (message->in_opts.mce_tetps >= 0)
		snprintf( mce_tetps, sizeof(int), "'%d'", message->in_opts.mce_tetps );
	strcpy( mce_ntet, "NULL" );
	if (message->in_opts.mce_ntet >= 0)
		snprintf( mce_ntet, sizeof(int), "'%d'", message->in_opts.mce_ntet );

	snprintf( qbuf, 1000, "replace into docsis_update ( modem_macaddr, ipaddr, cmts_ip, "
		"agentid, version, mce_concat, mce_ver, mce_frag, mce_phs, mce_igmp, mce_bpi, "
		"mce_ds_said, mce_us_sid, mce_filt_dot1p, mce_filt_dot1q, mce_tetps, mce_ntet, "
		"mce_dcc, thetime ) values "
		"( '%s','%s','%s','%s','%s', %s,%s,%s,%s,%s,  %s,%s,%s,%s,%s,  %s,%s,%s, now() )",
		message->s_macaddr, message->s_ipaddr, message->in_giaddr,
		message->in_opts.s_agentid, version,
		mce_concat, mce_ver, mce_frag, mce_phs, mce_igmp, mce_bpi, mce_ds_said, mce_us_sid,
		mce_filt_dot1p, mce_filt_dot1q, mce_tetps, mce_ntet, mce_dcc );
	SQL_QUERY_RET( qbuf );
}
Exemplo n.º 8
0
void  my_Load_Nets( void ) {
	MYSQL_RES	*res;
	MYSQL_ROW	myrow;
	char		*qbuf, network[21], *mask;
	int		nmask, i = 0, n = 0;
	u_int32_t	nmask2;
	ConfigNets	tmp;
	struct in_addr	inp;
	static time_t	old_time = 0;
	time_t		new_time = 0;

	new_time = time( NULL );
	if ( new_time - old_time < 3600 && my_nets != NULL) return;	// reload every hour
	old_time = new_time;

	my_Clear_Nets();

	qbuf = "select nettype, cmts_ip, cmts_vlan, network, gateway, grant_flag, dynamic_flag, "
		"full_flag, range_min, range_max, lease_time, config_opt1, config_opt2, "
		"config_opt3 from config_nets order by nettype, cmts_ip, cmts_vlan, inet_aton(range_min)";
	SQL_QUERY_RET( qbuf );
	res = mysql_store_result( my_sock );
	if (res == NULL) return;
	num_nets = mysql_num_rows( res );
	if (num_nets == 0) return;
	my_nets = (ConfigNets *) calloc(num_nets +1, sizeof(ConfigNets) );

	while ( myrow = mysql_fetch_row( res ) ) {
		memset( &my_nets[i], 0, sizeof(ConfigNets) );
		strncpy( my_nets[i].s_nettype, (myrow)[0], 7 );
		if (my_nets[i].s_nettype[1] == 'M') my_nets[i].nettype = NET_TYPE_CM;
		if (my_nets[i].s_nettype[1] == 'P') my_nets[i].nettype = NET_TYPE_CPE;
		if (my_nets[i].s_nettype[1] == 'T') my_nets[i].nettype = NET_TYPE_MTA;

		if (cpe_net == 0 && my_nets[i].nettype == NET_TYPE_CPE) cpe_net = i;

		strncpy( my_nets[i].s_cmts_ip, (myrow)[1], 20 );
		inet_aton( (myrow)[1], &inp ); my_nets[i].cmts_ip = inp.s_addr;

		my_nets[i].cmts_vlan = strtoul( (myrow)[2], NULL, 10 );

		strncpy( my_nets[i].s_network, (myrow)[3], 20 );
		strncpy( network, (myrow)[3], 20 );
		nmask = 0;
		mask = network;
		while(*mask != 0) {
			if (*mask == '/') {
				*mask = 0;
				mask++;
				nmask = strtoul( mask, NULL, 10 );
				mask--;
			}
			mask++;
		}
		if (nmask <= 0 || nmask > 30) { nmask = 24; }
		nmask2 = 0xFFFFFFFF << (32 - nmask);

		inet_aton( network, &inp );    my_nets[i].network = inp.s_addr;

		my_nets[i].mask = htonl( nmask2 );

		inet_aton( (myrow)[4], &inp ); my_nets[i].gateway = inp.s_addr;

		if (((myrow)[5][0] & 0x5F) == 'Y') my_nets[i].grant_flag = 1;
		// fprintf(stderr, "grant_flag  %d  %d  %d \n", (myrow)[5][0], ((myrow)[5][0] & 0x5F), 'Y' );

		if (((myrow)[6][0] & 0x5F) == 'Y') my_nets[i].dynamic_flag = CPE_DYNAMIC;

		if (((myrow)[7][0] & 0x5F) == 'Y') my_nets[i].full_flag = 1;

		inet_aton( (myrow)[8], &inp ); my_nets[i].range_min = inp.s_addr;

		inet_aton( (myrow)[9], &inp ); my_nets[i].range_max = inp.s_addr;

		my_nets[i].lease_time = strtoull( (myrow)[10], NULL, 10 );
		my_nets[i].opt1 = strtoul( (myrow)[11], NULL, 10 );
		my_nets[i].opt2 = strtoul( (myrow)[12], NULL, 10 );
		my_nets[i].opt3 = strtoul( (myrow)[13], NULL, 10 );

		/* Check Ranges */
		tmp.network = ntohl( my_nets[i].network );
		tmp.mask = nmask2;
		tmp.gateway = ntohl( my_nets[i].gateway );
		tmp.range_min = ntohl( my_nets[i].range_min );
		tmp.range_max = ntohl( my_nets[i].range_max );

		/* Check Network Address */
		if ( (tmp.network & tmp.mask) != tmp.network) {
			my_syslog( MLOG_ERROR, "dhcp: Load_Nets: " \
				"network address does not match subnet mask (%s %s)",
				(myrow)[1], (myrow)[3] );
			continue;
		}

		/* Calculate Broadcast Address */
		tmp.broadcast = 0xFFFFFFFF;
		tmp.broadcast -= tmp.mask;
		tmp.broadcast += tmp.network;
		my_nets[i].broadcast = htonl( tmp.broadcast );

		/* Check Gateway is in the network */
		if (!((tmp.gateway > tmp.network) && (tmp.broadcast > tmp.gateway))) {
			my_syslog( MLOG_ERROR, "dhcp: Load_Nets: " \
				"gateway address is not in the network specified (%s %s %s)",
				(myrow)[1], (myrow)[3], (myrow)[4] );
			continue;
		}
		/* Check Range_MIN is in the network */
		if (!((tmp.range_min > tmp.network) && (tmp.broadcast > tmp.range_min))) {
			my_syslog( MLOG_ERROR, "dhcp: Load_Nets: " \
				"range_min address is not in the network specified (%s %s %s)",
				(myrow)[1], (myrow)[3], (myrow)[8] );
			continue;
		}
		/* Check Range_MAX is in the network */
		if (!((tmp.range_max > tmp.network) && (tmp.broadcast > tmp.range_max))) {
			my_syslog( MLOG_ERROR, "dhcp: Load_Nets: " \
				"range_max address is not in the network specified (%s %s %s)",
				(myrow)[1], (myrow)[3], (myrow)[9] );
			continue;
		}
		/* Check that the Gateway in not between range min and max */
		if ((tmp.range_min < tmp.gateway) && (tmp.range_max > tmp.gateway)) {
			my_syslog( MLOG_ERROR, "dhcp: Load_Nets: " \
				"gateway address is between range min and max (%s %s %s (%s %s))",
				(myrow)[1], (myrow)[3], (myrow)[4], (myrow)[8], (myrow)[9] );
			continue;
		}
		/* Check that the range max is greater than the range min */
		if (tmp.range_min > tmp.range_max) {
			my_syslog( MLOG_ERROR, "dhcp: Load_Nets: " \
				"range min is greater than range max (%s %s %s %s)",
				(myrow)[1], (myrow)[3], (myrow)[8], (myrow)[9] );
			continue;
		}

		if (my_nets[i].nettype == NET_TYPE_CM) {
			for (n=tmp.range_min; n < tmp.range_max; n++) {
				u_int32_t n_ord = htonl( n );
				if (my_CheckCM_IP( n_ord )) {
					my_nets[i].last_used_ip = n;
					n = tmp.range_max;
				}
			}
		}
		if (my_nets[i].nettype == NET_TYPE_CPE) {
			for (n=tmp.range_min; n < tmp.range_max; n++) {
				u_int32_t n_ord = htonl( n );
				if (my_CheckCPE_IP( n_ord )) {
					my_nets[i].last_used_ip = n;
					n = tmp.range_max;
				}
			}
		}
		i++;
	}
	mysql_free_result(res);
}