예제 #1
0
void register_user(
        n::connection_manager& con, 
        sc::encrypted_channels& sec, 
        const n::endpoint& ep, 
        const ms::greet_register& r, 
        user_info_map& m)
{
    auto address = n::make_address_str(ep);
    if(r.id().empty()) return;

    //use user specified ip, otherwise use socket ip
    ms::greet_endpoint local = r.local();
    ms::greet_endpoint ext = {ep.address, ep.port};

    //check to see if user already registers and
    //don't re-register if ip and port of local and external are the same
    bool is_udp = ep.protocol == "udp";
    if(m.count(r.id()))
    {
        auto& i = m[r.id()];
        update_address(i, local, ext, ep, is_udp);
    }
    else
    {
        n::endpoint tcp_ep;
        n::endpoint udp_ep;
        (is_udp ? udp_ep : tcp_ep) = ep;
        user_info i = {r.id(), local, ext, r.response_service_address(), tcp_ep, udp_ep};
        m[i.id] = i;
        LOG << "registered " << u::uuid() << std::endl;
    }

    sec.create_channel(address, r.pub_key());

}
예제 #2
0
파일: template.cpp 프로젝트: BoiBetter/qira
static int idaapi hook(void *user_data, int event_id, va_list va) {
  static ea_t old_addr = 0;
  ea_t addr;
  if (event_id == view_curpos) {
    addr = get_screen_ea();
    if (old_addr != addr) {
      if (isCode(getFlags(addr))) {
        // don't update the address if it's already the qira address
        if (addr != qira_address) {
          set_qira_address(addr);
          update_address("iaddr", addr);
        }
      } else {
        update_address("daddr", addr);
      }
    }
    old_addr = addr;
  }
  return 0;
}
예제 #3
0
//done
void asm_pass_one (char* asm_file_name, char* sym_file_name) {
	char line[MAX_LINE_LENGTH];
	char* token = NULL;	
	//open the souce file
	FILE* fp = open_read_or_error(asm_file_name);
	//while there are still lines to read
	//call fgets to store the fp into line	
	while(fgets(line,MAX_LINE_LENGTH,fp)){	
    printf("%s",line);
		//convert to a list of tokens
		token = tokenize_line (line);
    //while my token is not null
    if(token != NULL){
      //if(util_get_opcode(token) != -1){
      //allocate memory currInfo
      currInfo = malloc(sizeof(struct line_info));
      //idk what this does but i'm doing it
      asm_init_line_info(currInfo);

      //check line syntax
      check_line_syntax(token);
      update_address();
      
      //set up link list
      
        if(infoHead == NULL){
          infoHead = currInfo;
          infoTail = currInfo;
        } else{
          //if the head is not null;
          //temp to inc count
          //get the next of the info tail
          infoTail -> next= currInfo;
          //set it equal to currinfo
          infoTail = currInfo;
          //inc that address
        }
      //} 
    }
  }
  //write the symbol talble file 
  if(numErrors == 0){
    lc3_write_sym_table(fp);
  }
  fclose(fp);
}
예제 #4
0
//void
//update_ia(iatype, ialist, ifp, serverid, authparam)
void
update_ia(
	iatype_t iatype,
	struct dhcp6_list *ialist,
	struct dhcp6_if *ifp,
	struct duid *serverid,
	struct authparam *authparam)
{
	struct ia *ia;
	struct ia_conf *iac;
	struct iapd_conf *iapdc;
	struct iana_conf *ianac;
	struct dhcp6_listval *iav, *siav;
	struct timeval timo;

    /* iav指向的是一个具体的节点,该节点的内容则是在iav->val_ia中给出 */
	for (iav = TAILQ_FIRST(ialist); iav; iav = TAILQ_NEXT(iav, link)) {
		/* if we're not interested in this IA, ignore it. */
        /* 根据配置文件中的配置来判断是否这个iac存在 */
		if ((iac = find_iaconf(&ifp->iaconf_list, iatype,
		    iav->val_ia.iaid)) == NULL) {
			continue;
		}

		/* validate parameters */
		/*
		 * If a client receives an IA_NA with T1 greater than T2, and
		 * both T1 and T2 are greater than 0, the client discards the
		 * IA_NA option and processes the remainder of the message as
		 * though the server had not included the invalid IA_NA option.
		 * [RFC3315 22.4]
		 * We apply the same rule to IA_PD as well.
		 */
		if (iav->val_ia.t2 != 0 && iav->val_ia.t1 > iav->val_ia.t2) {
			dprintf(LOG_INFO, FNAME,
			    "invalid IA: T1(%lu) > T2(%lu)",
			    iav->val_ia.t1, iav->val_ia.t2);
			continue;
		}

		/* locate the local IA or make a new one */
		ia = get_ia(iatype, ifp, iac, iav, serverid);
		if (ia == NULL) {
			dprintf(LOG_WARNING, FNAME, "failed to get an IA "
			    "type: %s, ID: %u", iastr(iac->type), iac->iaid);
			continue;
		}

		/* update authentication parameters */
		if (update_authparam(ia, authparam)) {
			dprintf(LOG_WARNING, FNAME, "failed to update "
			    "authentication param for IA "
			    "type: %s, ID: %u", iastr(iac->type), iac->iaid);
			remove_ia(ia);
			continue;
		}

		/* update IA configuration information */
		for (siav = TAILQ_FIRST(&iav->sublist); siav;
		    siav = TAILQ_NEXT(siav, link)) {
			switch (siav->type) {
			case DHCP6_LISTVAL_PREFIX6:
				/* add or update the prefix */
				iapdc = (struct iapd_conf *)iac;
				if (update_prefix(ia, &siav->val_prefix6,
				    &iapdc->iapd_pif_list, ifp, &ia->ctl,
				    callback)) {
					dprintf(LOG_NOTICE, FNAME,
					    "failed to update a prefix %s/%d",
					    in6addr2str(&siav->val_prefix6.addr, 0),
					    siav->val_prefix6.plen);
				}
				break;
			case DHCP6_LISTVAL_STATEFULADDR6:
				ianac = (struct iana_conf *)iac;
				if (update_address(ia, &siav->val_statefuladdr6,
				    ifp, &ia->ctl, callback)) {
					dprintf(LOG_NOTICE, FNAME,
					    "failed to update an address %s",
					    in6addr2str(&siav->val_statefuladdr6.addr, 0));
				}
				break;
			case DHCP6_LISTVAL_STCODE:
				dprintf(LOG_INFO, FNAME,
				    "status code for %s-%lu: %s",
				    iastr(iatype), iav->val_ia.iaid,
				    dhcp6_stcodestr(siav->val_num16));
				if ((ia->state == IAS_RENEW ||
				    ia->state == IAS_REBIND) &&
				    siav->val_num16 == DH6OPT_STCODE_NOBINDING) {
					/*
					 * For each IA in the original Renew or
					 * Rebind message, the client
					 * sends a Request message if the IA
					 * contained a Status Code option
					 * with the NoBinding status.
					 * [RFC3315 18.1.8]
					 * XXX: what about the PD case?
					 */
					dprintf(LOG_INFO, FNAME,
					    "receive NoBinding against "
					    "renew/rebind for %s-%lu",
					    iastr(ia->conf->type),
					    ia->conf->iaid);
					reestablish_ia(ia);
					goto nextia;
				}
				break;
			default:
				dprintf(LOG_ERR, FNAME, "impossible case");
				goto nextia;
			}
		}

		/* see if this IA is still valid.  if not, remove it. */
		if (ia->ctl == NULL || !(*ia->ctl->isvalid)(ia->ctl)) {
			dprintf(LOG_DEBUG, FNAME, "IA %s-%lu is invalidated",
			    iastr(ia->conf->type), ia->conf->iaid);
			remove_ia(ia);
			continue;
		}

		/* if T1 or T2 is 0, determine appropriate values locally. */
		if (ia->t1 == 0 || ia->t2 == 0) {
			u_int32_t duration;

			if (ia->ctl && ia->ctl->duration)
				duration = (*ia->ctl->duration)(ia->ctl);
			else
				duration = 1800; /* 30min. XXX: no rationale */

			if (ia->t1 == 0) {
				if (duration == DHCP6_DURATION_INFINITE)
					ia->t1 = DHCP6_DURATION_INFINITE;
				else
					ia->t1 = duration / 2;
			}
			if (ia->t2 == 0) {
				if (duration == DHCP6_DURATION_INFINITE)
					ia->t2 = DHCP6_DURATION_INFINITE;
				else
					ia->t2 = duration * 4 / 5;
			}

			/* make sure T1 <= T2 */
			if (ia->t1 > ia->t2)
				ia->t1 = ia->t2 * 5 / 8;

			dprintf(LOG_INFO, FNAME, "T1(%lu) and/or T2(%lu) "
			    "is locally determined",  ia->t1, ia->t2);
		}

		/*
		 * Be proactive for too-small timeout values.  Note that
		 * the adjusted values may make some information expire
		 * without renewal.
		 */
		if (ia->t2 < DHCP6_DURATION_MIN) {
			dprintf(LOG_INFO, FNAME, "T1 (%lu) or T2 (%lu) "
			    "is too small", ia->t1, ia->t2);
			ia->t2 = DHCP6_DURATION_MIN;
			ia->t1 = ia->t2 * 5 / 8;
			dprintf(LOG_INFO, "", "  adjusted to %lu and %lu",
			    ia->t1, ia->t2);
		}

		/* set up a timer for this IA. */
		if (ia->t1 == DHCP6_DURATION_INFINITE) {
			if (ia->timer)
				dhcp6_remove_timer(&ia->timer);
		} else {
			if (ia->timer == NULL)
				ia->timer = dhcp6_add_timer(ia_timo, ia);
			if (ia->timer == NULL) {
				dprintf(LOG_ERR, FNAME,
				    "failed to add IA timer");
				remove_ia(ia); /* XXX */
				continue;
			}
			timo.tv_sec = ia->t1;
			timo.tv_usec = 0;

            loginfo(FUNC, "set renew time: %d second", timo.tv_sec);
            
			dhcp6_set_timer(&timo, ia->timer);
		}

        /* 更新这个ia的状态为ACTIVE,接下来就可以使用renew来更新了 */
		ia->state = IAS_ACTIVE;

	  nextia:
		;
	}
}